Example #1
0
 def __call__(self):
     context = aq_inner(self.context)
     storage = IStorage(self.context)
     catalog = getToolByName(self.context, 'portal_catalog')
     try:
         brains = catalog(UID=IUUID(self.context))
     except TypeError:  # pragma: no cover
         brains = []
     item = None
     if len(brains) > 0:
         obj = brains[0]
         base_path = '/'.join(context.getPhysicalPath())
         item = {}
         for attr in self.attributes:
             key = attr
             if key == 'path':
                 attr = 'getPath'
             val = getattr(obj, attr, None)
             if callable(val):
                 val = val()
             if key == 'path':
                 val = val[len(base_path):]
             item[key] = val
     return json.dumps({
         'addButtons': [],
         'defaultPage': self.context.getDefaultPage(),
         'object': item,
         'branches': storage.branches(),
         'tags': storage.tags(),
         'defaultRev': storage.rev,  # no checkout should have been done
     })
Example #2
0
 def __call__(self):
     context = aq_inner(self.context)
     storage = IStorage(self.context)
     catalog = getToolByName(self.context, 'portal_catalog')
     try:
         brains = catalog(UID=IUUID(self.context))
     except TypeError:  # pragma: no cover
         brains = []
     item = None
     if len(brains) > 0:
         obj = brains[0]
         base_path = '/'.join(context.getPhysicalPath())
         item = {}
         for attr in self.attributes:
             key = attr
             if key == 'path':
                 attr = 'getPath'
             val = getattr(obj, attr, None)
             if callable(val):
                 val = val()
             if key == 'path':
                 val = val[len(base_path):]
             item[key] = val
     return json.dumps({
         'addButtons': [],
         'defaultPage': self.context.getDefaultPage(),
         'object': item,
         'branches': storage.branches(),
         'tags': storage.tags(),
         'defaultRev': storage.rev,  # no checkout should have been done
     })
Example #3
0
    def get_items(self):
        storage = IStorage(self.context)
        storage.datefmt = 'rfc3339.local'
        if self.commit:
            storage.checkout(self.commit)
        # use the normalized revision identifier.
        self.commit = storage.rev

        def pathinfo(p):
            return p, storage.pathinfo(p)

        fileinfo = sorted(
            (
                pathinfo('/'.join(self.subpath + [fn]))
                for fn in storage.listdir('/'.join(self.subpath))
            ),
            key=lambda x: (x[1]['type'] == 'file', x[1]['basename']))

        results = []

        for filepath, info in fileinfo:
            # for the styling.
            if info['type'] == 'file':
                info['type'] = 'document'

            url = self.get_url(filepath)
            fb = FileBrain(
                info['basename'],
                url,
                url,
                info['date'],
                info['size'],
                info['type'] == 'folder',
                info['type'],
                filepath,  # a simple unique id.
                filepath,  # a simple unique id.
                '/' + storage.rev + '/' + filepath,
            )
            results.append(fb._asdict())

        return results
Example #4
0
    def test_standard_fs_workflow(self):
        # Register a backend that requires filesystem
        self.portal.getSiteManager().registerUtility(self.backend,
                                                     provided=IStorageBackend,
                                                     name=u'dummy_fs_backend')
        utilities = getUtility(IUtilityRegistry, 'repodono.storage.backends')
        utilities.enable('dummy_fs_backend')

        installer = getUtility(IStorageInstaller)
        installer(self.folder, 'dummy_fs_backend')

        self.assertIn('repodono.storage.base.StorageInfo',
                      IAnnotations(self.folder).keys())

        storage = IStorage(self.folder)
        self.assertEqual(storage.path,
                         join(self.tempdir, 'plone', TEST_FOLDER_ID))
        self.assertTrue(exists(storage.path))
Example #5
0
    def test_storage_lifecycle(self):
        # have to mark the object manually with IStorageEnabled.
        # Normally dexterity behavior will provide this.
        alsoProvides(self.portal, IStorageEnabled)

        installer = getUtility(IStorageInstaller)
        installer(self.portal, 'dummy_backend')

        self.assertEqual(DummyStorageData._data.keys(), ['plone'])

        sf = IStorageFactory(self.portal)
        self.assertEqual(sf.backend, u'dummy_backend')

        storage_backend = getUtility(IStorageBackend, name=u'dummy_backend')
        storage = storage_backend.acquire(self.portal)
        self.assertTrue(isinstance(storage, DummyStorage))

        storage = IStorage(self.portal)
        self.assertTrue(isinstance(storage, DummyStorage))
Example #6
0
    def get_items(self):
        storage = IStorage(self.context)
        storage.datefmt = 'rfc3339.local'
        if self.commit:
            storage.checkout(self.commit)
        # use the normalized revision identifier.
        self.commit = storage.rev

        def pathinfo(p):
            return p, storage.pathinfo(p)

        fileinfo = sorted((pathinfo('/'.join(self.subpath + [fn]))
                           for fn in storage.listdir('/'.join(self.subpath))),
                          key=lambda x:
                          (x[1]['type'] == 'file', x[1]['basename']))

        results = []

        for filepath, info in fileinfo:
            # for the styling.
            if info['type'] == 'file':
                info['type'] = 'document'

            url = self.get_url(filepath)
            fb = FileBrain(
                info['basename'],
                url,
                url,
                info['date'],
                info['size'],
                info['type'] == 'folder',
                info['type'],
                filepath,  # a simple unique id.
                filepath,  # a simple unique id.
                '/' + storage.rev + '/' + filepath,
            )
            results.append(fb._asdict())

        return results