Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions | Private Attributes
CMFCore.FSMetadata.FSMetadata Class Reference

List of all members.

Public Member Functions

def __init__
def read
def getProxyRoles
def getSecurity
def getProperties

Private Member Functions

def _readMetadata
def _nullParser
def _securityParser
def _getSectionDict
def _old_readProperties
def _old_readSecurity

Private Attributes

 _filename
 _properties
 _security

Detailed Description

Definition at line 48 of file FSMetadata.py.


Constructor & Destructor Documentation

def CMFCore.FSMetadata.FSMetadata.__init__ (   self,
  filename 
)

Definition at line 50 of file FSMetadata.py.

00050 
00051     def __init__(self, filename):
00052         self._filename = filename


Member Function Documentation

def CMFCore.FSMetadata.FSMetadata._getSectionDict (   self,
  cfg,
  section,
  parser = None 
) [private]
Get a section and put it into a dict, mostly a convenience
function around the ConfigParser

Note: the parser is a function to parse each value, so you can
have custom values for the key value pairs

Definition at line 128 of file FSMetadata.py.

00128 
00129     def _getSectionDict(self, cfg, section, parser=None):
00130         """
00131         Get a section and put it into a dict, mostly a convenience
00132         function around the ConfigParser
00133 
00134         Note: the parser is a function to parse each value, so you can
00135         have custom values for the key value pairs
00136         """
00137         if parser is None:
00138             parser = self._nullParser
00139 
00140         props = {}
00141         if cfg.has_section(section):
00142             for opt in cfg.options(section):
00143                 props[opt] = parser(cfg.get(section, opt))
00144             return props
00145 
00146         # we need to return None if we have none to be compatible
00147         # with existing API
00148         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCore.FSMetadata.FSMetadata._nullParser (   self,
  data 
) [private]
This is the standard rather boring null parser that does very little

Definition at line 103 of file FSMetadata.py.

00103 
00104     def _nullParser(self, data):
00105         """
00106         This is the standard rather boring null parser that does very little
00107         """
00108         return data

Here is the caller graph for this function:

Reads the properties file next to an object.

Moved from DirectoryView.py to here with only minor
modifications. Old and deprecated in favour of .metadata now

Definition at line 149 of file FSMetadata.py.

00149 
00150     def _old_readProperties(self):
00151         """
00152         Reads the properties file next to an object.
00153 
00154         Moved from DirectoryView.py to here with only minor
00155         modifications. Old and deprecated in favour of .metadata now
00156         """
00157         fp = self._filename + '.properties'
00158         try:
00159             f = open(fp, 'rt')
00160         except IOError:
00161             return None
00162         else:
00163             warn('.properties objects will disappear in CMF 2.0 - Use '
00164                  '.metadata objects instead.', DeprecationWarning)
00165             lines = f.readlines()
00166             f.close()
00167             props = {}
00168             for line in lines:
00169                 kv = line.split('=', 1)
00170                 if len(kv) == 2:
00171                     props[kv[0].strip()] = kv[1].strip()
00172                 else:
00173                     logger.exception("Error parsing .properties file")
00174 
00175             return props

Here is the call graph for this function:

Reads the security file next to an object.

Moved from DirectoryView.py to here with only minor
modifications. Old and deprecated in favour of .metadata now

Definition at line 176 of file FSMetadata.py.

00176 
00177     def _old_readSecurity(self):
00178         """
00179         Reads the security file next to an object.
00180 
00181         Moved from DirectoryView.py to here with only minor
00182         modifications. Old and deprecated in favour of .metadata now
00183         """
00184         fp = self._filename + '.security'
00185         try:
00186             f = open(fp, 'rt')
00187         except IOError:
00188             return None
00189         else:
00190             warn('.security objects will disappear in CMF 2.0 - Use '
00191                  '.metadata objects instead.', DeprecationWarning)
00192             lines = f.readlines()
00193             f.close()
00194             prm = {}
00195             for line in lines:
00196                 try:
00197                     c1 = line.index(':')+1
00198                     c2 = line.index(':',c1)
00199                     permission = line[:c1-1]
00200                     acquire = bool(line[c1:c2])
00201                     proles = line[c2+1:].split(',')
00202                     roles=[]
00203                     for role in proles:
00204                         role = role.strip()
00205                         if role:
00206                             roles.append(role)
00207                 except:
00208                     logger.exception("Error reading permission "
00209                                      "from .security file")
00210                 prm[permission]=(acquire,roles)
00211             return prm

Here is the call graph for this function:

Read the new file format using ConfigParser 

Definition at line 82 of file FSMetadata.py.

00082 
00083     def _readMetadata(self):
00084         """ Read the new file format using ConfigParser """
00085         self._properties = {}
00086         self._security = {}
00087 
00088         try:
00089             cfg = CMFConfigParser()
00090             cfg.read(self._filename + '.metadata')
00091 
00092             # the two sections we care about
00093             self._properties = self._getSectionDict(cfg, 'default')
00094             self._security = self._getSectionDict(cfg, 'security',
00095                                                   self._securityParser)
00096         except:
00097             logger.exception("Error parsing .metadata file")
00098 
00099         # to add in a new value such as proxy roles,
00100         # just add in the section, call it using getSectionDict
00101         # if you need a special parser for some whacky
00102         # config, then just pass through a special parser

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCore.FSMetadata.FSMetadata._securityParser (   self,
  data 
) [private]
A specific parser for security lines

Security lines must be of the format

Permission = (0|1):Role[,Role...]

Where 0|1 is the acquire permission setting
and Role is the roles for this permission
eg: 1:Manager or 0:Manager,Anonymous

Definition at line 109 of file FSMetadata.py.

00109 
00110     def _securityParser(self, data):
00111         """ A specific parser for security lines
00112 
00113         Security lines must be of the format
00114 
00115         Permission = (0|1):Role[,Role...]
00116 
00117         Where 0|1 is the acquire permission setting
00118         and Role is the roles for this permission
00119         eg: 1:Manager or 0:Manager,Anonymous
00120         """
00121         if data.find(':') < 1:
00122             raise ValueError, "The security declaration of file " + \
00123                   "%r is in the wrong format" % self._filename
00124 
00125         acquire, roles = data.split(':')
00126         roles = [r.strip() for r in roles.split(',') if r.strip()]
00127         return (int(acquire), roles)

Here is the caller graph for this function:

Gets the properties settings 

Definition at line 77 of file FSMetadata.py.

00077 
00078     def getProperties(self):
00079         """ Gets the properties settings """
00080         return self._properties

Here is the caller graph for this function:

Returns the proxy roles 

Definition at line 65 of file FSMetadata.py.

00065 
00066     def getProxyRoles(self):
00067         """ Returns the proxy roles """
00068         if self.getProperties():
00069             pxy = self.getProperties().get('proxy')
00070             if pxy:
00071                 return [r.strip() for r in pxy.split(',') if r.strip()]
00072         return []

Here is the call graph for this function:

Gets the security settings 

Definition at line 73 of file FSMetadata.py.

00073 
00074     def getSecurity(self):
00075         """ Gets the security settings """
00076         return self._security

Find the files to read, either the old security and
properties type or the new metadata type 

Definition at line 53 of file FSMetadata.py.

00053 
00054     def read(self):
00055         """ Find the files to read, either the old security and
00056         properties type or the new metadata type """
00057         filename = self._filename + '.metadata'
00058         if exists(filename):
00059             # found the new type, lets use that
00060             self._readMetadata()
00061         else:
00062             # not found so try the old ones
00063             self._properties = self._old_readProperties()
00064             self._security = self._old_readSecurity()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 51 of file FSMetadata.py.

Definition at line 62 of file FSMetadata.py.

Definition at line 63 of file FSMetadata.py.


The documentation for this class was generated from the following file: