Back to index

plone3  3.1.7
Classes | Functions | Variables
CMFCore.DirectoryView Namespace Reference

Classes

class  _walker
class  DirectoryInformation
class  DirectoryRegistry
class  DirectoryView
class  DirectoryViewSurrogate

Functions

def _filtered_listdir
def _generateKey
def _findProductForPath
def listFolderHierarchy
def createDirectoryView
def addDirectoryViews
def manage_addDirectoryView
def manage_listAvailableDirectories

Variables

tuple logger = logging.getLogger('CMFCore.DirectoryView')
int __reload_module__ = 0
tuple base_ignore = ('.', '..')
tuple ignore = ('CVS', '.svn')
tuple ignore_re = re.compile(r'\.|(.*~$)|#')
tuple _dirreg = DirectoryRegistry()
 registerDirectory = _dirreg.registerDirectory
 registerFileExtension = _dirreg.registerFileExtension
 registerMetaType = _dirreg.registerMetaType
tuple manage_addDirectoryViewForm = HTMLFile('dtml/addFSDirView', globals())

Function Documentation

def CMFCore.DirectoryView._filtered_listdir (   path,
  ignore 
) [private]

Definition at line 59 of file DirectoryView.py.

00059 
00060 def _filtered_listdir(path, ignore):
00061     return [ name
00062              for name
00063              in listdir(path)
00064              if name not in ignore and not ignore_re.match(name) ]

Here is the caller graph for this function:

def CMFCore.DirectoryView._findProductForPath (   path,
  subdir = None 
) [private]

Definition at line 90 of file DirectoryView.py.

00090 
00091 def _findProductForPath(path, subdir=None):
00092     # like minimalpath, but raises an error if path is not inside a product
00093     p = abspath(path)
00094     for ppath in ProductsPath:
00095         if p.startswith(ppath):
00096             dirpath = p[len(ppath)+1:]
00097             parts = dirpath.replace('\\', '/').split('/', 1)
00098             parts.append('')
00099             if subdir:
00100                 subdir = '/'.join((parts[1], subdir))
00101                 if subdir.startswith('/'):
00102                     subdir=subdir[1:]
00103             else:
00104                 subdir = parts[1]
00105             return ('Products.' + parts[0], subdir)
00106 
00107     raise ValueError('Path is not inside a product')
00108 

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCore.DirectoryView._generateKey (   package,
  subdir 
) [private]
Generate a key for a path inside a package.

The key has the quality that keys for subdirectories can be derived by
simply appending to the key.

Definition at line 82 of file DirectoryView.py.

00082 
00083 def _generateKey(package, subdir):
00084     """Generate a key for a path inside a package.
00085 
00086     The key has the quality that keys for subdirectories can be derived by
00087     simply appending to the key.
00088     """
00089     return ':'.join((package, subdir.replace('\\', '/')))

Here is the caller graph for this function:

def CMFCore.DirectoryView.addDirectoryViews (   ob,
  name,
  _prefix 
)
Add a directory view for every subdirectory of the given directory.

Meant to be called by filesystem-based code. Note that registerDirectory()
still needs to be called by product initialization code to satisfy
persistence demands.

Definition at line 612 of file DirectoryView.py.

00612 
00613 def addDirectoryViews(ob, name, _prefix):
00614     """ Add a directory view for every subdirectory of the given directory.
00615 
00616     Meant to be called by filesystem-based code. Note that registerDirectory()
00617     still needs to be called by product initialization code to satisfy
00618     persistence demands.
00619     """
00620     if not isinstance(_prefix, basestring):
00621         package = getPackageName(_prefix)
00622     else:
00623         warn('addDirectoryViews() called with deprecated _prefix type. '
00624              'Support for paths will be removed in CMF 2.3. Please use '
00625              'globals instead.', DeprecationWarning, stacklevel=2)
00626         (package, name) = _findProductForPath(_prefix, name)
00627     reg_key = _generateKey(package, name)
00628     info = _dirreg.getDirectoryInfo(reg_key)
00629     if info is None:
00630         raise ValueError('Not a registered directory: %s' % reg_key)
00631     for entry in info.getSubdirs():
00632         entry_reg_key = '/'.join((reg_key, entry))
00633         createDirectoryView(ob, entry_reg_key, entry)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCore.DirectoryView.createDirectoryView (   parent,
  reg_key,
  id = None 
)
Add either a DirectoryView or a derivative object.

Definition at line 594 of file DirectoryView.py.

00594 
00595 def createDirectoryView(parent, reg_key, id=None):
00596     """ Add either a DirectoryView or a derivative object.
00597     """
00598     info = _dirreg.getDirectoryInfo(reg_key)
00599     if info is None:
00600         reg_key = _dirreg.getCurrentKeyFormat(reg_key)
00601         info = _dirreg.getDirectoryInfo(reg_key)
00602         warn('createDirectoryView() called with deprecated reg_key format. '
00603              'Support for old key formats will be removed in CMF 2.3. Please '
00604              'use the new key format <product>:<subdir> instead.',
00605              DeprecationWarning, stacklevel=2)
00606     if not id:
00607         id = reg_key.split('/')[-1]
00608     else:
00609         id = str(id)
00610     ob = DirectoryView(id, reg_key)
00611     parent._setObject(id, ob)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCore.DirectoryView.listFolderHierarchy (   ob,
  path,
  rval,
  adding_meta_type = None 
)

Definition at line 429 of file DirectoryView.py.

00429 
00430 def listFolderHierarchy(ob, path, rval, adding_meta_type=None):
00431     if not hasattr(ob, 'objectValues'):
00432         return
00433     values = ob.objectValues()
00434     for subob in ob.objectValues():
00435         base = getattr(subob, 'aq_base', subob)
00436         if getattr(base, 'isPrincipiaFolderish', 0):
00437 
00438             if adding_meta_type is not None and hasattr(
00439                 base, 'filtered_meta_types'):
00440                 # Include only if the user is allowed to
00441                 # add the given meta type in this location.
00442                 meta_types = subob.filtered_meta_types()
00443                 found = 0
00444                 for mt in meta_types:
00445                     if mt['name'] == adding_meta_type:
00446                         found = 1
00447                         break
00448                 if not found:
00449                     continue
00450 
00451             if path:
00452                 subpath = path + '/' + subob.getId()
00453             else:
00454                 subpath = subob.getId()
00455             title = getattr(subob, 'title', None)
00456             if title:
00457                 name = '%s (%s)' % (subpath, title)
00458             else:
00459                 name = subpath
00460             rval.append((subpath, name))
00461             listFolderHierarchy(subob, subpath, rval, adding_meta_type)
00462 

Here is the caller graph for this function:

def CMFCore.DirectoryView.manage_addDirectoryView (   self,
  reg_key,
  id = None,
  REQUEST = None 
)
Add either a DirectoryView or a derivative object.

Definition at line 634 of file DirectoryView.py.

00634 
00635 def manage_addDirectoryView(self, reg_key, id=None, REQUEST=None):
00636     """ Add either a DirectoryView or a derivative object.
00637     """
00638     createDirectoryView(self, reg_key, id)
00639     if REQUEST is not None:
00640         return self.manage_main(self, REQUEST)

Here is the call graph for this function:

List registered directories.

Definition at line 641 of file DirectoryView.py.

00641 
00642 def manage_listAvailableDirectories(*args):
00643     """ List registered directories.
00644     """
00645     return list(_dirreg.listDirectories())

Here is the caller graph for this function:


Variable Documentation

Definition at line 49 of file DirectoryView.py.

Definition at line 423 of file DirectoryView.py.

tuple CMFCore.DirectoryView.base_ignore = ('.', '..')

Definition at line 52 of file DirectoryView.py.

tuple CMFCore.DirectoryView.ignore = ('CVS', '.svn')

Definition at line 54 of file DirectoryView.py.

tuple CMFCore.DirectoryView.ignore_re = re.compile(r'\.|(.*~$)|#')

Definition at line 56 of file DirectoryView.py.

tuple CMFCore.DirectoryView.logger = logging.getLogger('CMFCore.DirectoryView')

Definition at line 47 of file DirectoryView.py.

tuple CMFCore.DirectoryView.manage_addDirectoryViewForm = HTMLFile('dtml/addFSDirView', globals())

Definition at line 592 of file DirectoryView.py.

CMFCore.DirectoryView.registerDirectory = _dirreg.registerDirectory

Definition at line 424 of file DirectoryView.py.

CMFCore.DirectoryView.registerFileExtension = _dirreg.registerFileExtension

Definition at line 425 of file DirectoryView.py.

CMFCore.DirectoryView.registerMetaType = _dirreg.registerMetaType

Definition at line 426 of file DirectoryView.py.