Back to index

plone3  3.1.7
Classes | Functions | Variables
Marshall.tests.test_export Namespace Reference

Classes

class  ExportTest

Functions

def normalize_xml
def import_file
def fromFS
def test_suite

Variables

 tool_id = Registry.id
tuple IGNORE_NAMES = ('CVS', '.svn')

Function Documentation

def Marshall.tests.test_export.fromFS (   base,
  target,
  metadata = 'atxml',
  data = 'primary_field' 
)

Definition at line 71 of file test_export.py.

00071 
00072 def fromFS(base, target, metadata='atxml', data='primary_field'):
00073     paths = []
00074     ignore = lambda x: filter(None, [x.endswith(n) for n in IGNORE_NAMES])
00075     def import_metadata(relparts, fname, target, handler=metadata):
00076         return import_file(relparts, fname, target, handler)
00077     def import_data(relparts, fname, target, handler=data):
00078         return import_file(relparts, fname, target, handler)
00079     def import_func(arg, dirname, names):
00080         # Remove ignored filenames
00081         [names.remove(n) for n in names if ignore(n)]
00082         names = map(os.path.normcase, names)
00083         for name in names:
00084             fullname = os.path.join(dirname, name)
00085             if not os.path.isfile(fullname):
00086                 continue
00087             fparts = fullname.split(os.sep)
00088             bparts = base.split(os.sep)
00089             relparts = fparts[len(bparts):]
00090             relpath = '/'.join(relparts)
00091             arg.append(relpath)
00092             if '.metadata' in dirname:
00093                 relparts.remove('.metadata')
00094                 import_metadata(relparts, fullname, target)
00095             else:
00096                 import_data(relparts, fullname, target)
00097     os.path.walk(base, import_func, paths)
00098     return paths

Here is the call graph for this function:

def Marshall.tests.test_export.import_file (   relparts,
  fname,
  target,
  handler 
)

Definition at line 50 of file test_export.py.

00050 
00051 def import_file(relparts, fname, target, handler):
00052     marshaller = getComponent(handler)
00053     f = open(fname, 'rb+')
00054     content = f.read()
00055     f.close()
00056     curr = parent = target
00057     for p in relparts[:-1]:
00058         curr = parent.restrictedTraverse(p, None)
00059         if curr is None:
00060             parent.invokeFactory('Folder', p)
00061             curr = parent.restrictedTraverse(p)
00062         parent = curr
00063     obj_id = relparts[-1]
00064     obj = parent.restrictedTraverse(obj_id, None)
00065     if obj is None:
00066         parent.invokeFactory('Document', obj_id)
00067         obj = parent.restrictedTraverse(obj_id)
00068     marshaller.demarshall(obj, content)
00069     return

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 45 of file test_export.py.

00045 
00046 def normalize_xml(s):
00047     s = re.sub(r"[ \t]+", " ", s)
00048     return s
00049 

Here is the caller graph for this function:

Definition at line 121 of file test_export.py.

00121 
00122 def test_suite():
00123     import unittest
00124     suite = unittest.TestSuite()
00125     dirs = glob.glob(os.path.join(PACKAGE_HOME, 'export', '*'))
00126     comps = [i['name'] for i in getRegisteredComponents()]
00127     for d in dirs:
00128         prefix = os.path.basename(d)
00129         if prefix not in comps:
00130             continue
00131         k_dict = {'base':d,
00132                   'prefix':prefix}
00133         klass = type('%sExportTest' % prefix,
00134                      (ExportTest,),
00135                      k_dict)
00136         suite.addTest(unittest.makeSuite(klass))
00137     return suite

Here is the call graph for this function:


Variable Documentation

tuple Marshall.tests.test_export.IGNORE_NAMES = ('CVS', '.svn')

Definition at line 70 of file test_export.py.

Definition at line 43 of file test_export.py.