예제 #1
0
파일: workspace.py 프로젝트: PMR2/pmr2.app
    def generateStructure(self):
        data, errors = self.extractData()
        if errors:
            return

        wks_path = None
        if IWorkspace.providedBy(self.context):
            wks_path = u'/'.join(self.context.getPhysicalPath())
        elif IExposure.providedBy(self.context):
            wks_path = self.context.workspace

        struct = {
            'docview_generator': data['docview_generator'],
            'docview_gensource': data['docview_gensource'],
            'Subject': (),  # XXX to be assigned by filetype?
        }

        if wks_path:
            struct.update({
                'commit_id': self.current_commit_id(),
                'curation': {},  # XXX no interface yet, and deprecated.
                'title': u'',  # XXX copy context?
                'workspace': wks_path,
            })

        structure = (self.filename, struct)

        return structure
예제 #2
0
파일: adapter.py 프로젝트: PMR2/pmr2.app
    def __call__(self):
        if not self.enabled:
            # This isn't a protocol request according to isprotocol.  While
            # it is still possible to directly call the protocol but that's
            # unchecked.
            raise NotProtocolRequestError()

        raw_result = self.storage_util.protocol(self.context, self.request)
        if isinstance(raw_result, ProtocolResult):
            event = raw_result.event
            result = raw_result.result
        else:
            # legacy implementation that only returns raw client results
            # and not the event to fire.
            event = None
            result = raw_result
            if self.request.method in ['POST']:
                # Assume all POST requests are pushes.
                if IWorkspace.providedBy(self.context):
                    event = Push(self.context)
            
        if event:
            zope.event.notify(event)

        return result
예제 #3
0
파일: vocab.py 프로젝트: PMR2/pmr2.app
    def acquireWorkspace(self):
        if not IWorkspace.providedBy(self.context):
            wks = None
            obj = aq_inner(self.context)
            while obj and not wks and not IWorkspace.providedBy(obj):
                wks = zope.component.queryAdapter(obj, IWorkspace)
                if not wks:
                    # The object that can adapted to the workspace can
                    # be nested, i.e. a form adapter object.
                    obj = aq_parent(obj)
                    if IWorkspace.providedBy(obj):
                        # We actually have one.
                        wks = obj
            if not wks:
                return None
        else:
            wks = self.context

        return wks
예제 #4
0
    def acquireWorkspace(self):
        if not IWorkspace.providedBy(self.context):
            wks = None
            obj = aq_inner(self.context)
            while obj and not wks and not IWorkspace.providedBy(obj):
                wks = zope.component.queryAdapter(obj, IWorkspace)
                if not wks:
                    # The object that can adapted to the workspace can
                    # be nested, i.e. a form adapter object.
                    obj = aq_parent(obj)
                    if IWorkspace.providedBy(obj):
                        # We actually have one.
                        wks = obj
            if not wks:
                raise Exception("Unable to adapt to a workspace; will not be "
                                "able to acquire file listing.")
        else:
            wks = self.context

        return wks
예제 #5
0
파일: adapter.py 프로젝트: PMR2/pmr2.app
def WorkspaceStorageAdapter(workspace):
    """\
    Adapts a given `Workspace` into a `Storage`.
    """

    assert IWorkspace.providedBy(workspace)
    storage_util = zope.component.queryUtility(
        IStorageUtility, name=workspace.storage)
    if storage_util is None:
        raise UnknownStorageTypeError('cannot acquire storage backend',
            workspace.storage)
    return storage_util(workspace)
예제 #6
0
파일: adapter.py 프로젝트: PMR2/pmr2.app
    def __call__(self):

        settings = zope.component.getUtility(IPMR2GlobalSettings)
        reporoot = settings.dirCreatedFor(self.context)
        if reporoot is None:
            raise WorkspaceDirNotExistsError()

        try:
            # XXX placeholder method of getting a listing of directories,
            # currently assuming any directory is valid repo
            paths = os.listdir(reporoot)
            repodirs = [i for i in paths 
                if os.path.isdir(os.path.join(reporoot, i))]
        except OSError:
            raise WorkspaceDirNotExistsError()

        # code below is slightly naive, performance-wise.  if done in
        # same loop, popping both list as a stack, compare the values
        # that are popped might be faster.

        # objects need to be processed
        # True = correct type (Workspace), False = incorrect type
        items = self.context.items()
        repoobjs = [(i[0], IWorkspace.providedBy(i[1]),) for i in items]
        repoobjs_d = dict(repoobjs)

        # check to see if a repo dir has object of same name
        # None = missing, True/False (from above if exists)
        check = [(i, repoobjs_d.get(i, None)) for i in repodirs]

        # failure due to non-existing objects (remaining repoobjs that
        # were not checked
        # False = repo missing/invalid Workspace object
        fail = [(i[0], False) for i in repoobjs if i[0] not in repodirs]

        # build the result and sort
        result = fail + check
        result.sort()

        return result
예제 #7
0
 def sync(self, context, source):
     if IWorkspace.providedBy(source):
         return self.syncWorkspace(context, source)
     return self.syncIdentifier(context, source)
예제 #8
0
 def available(self):
     return (
         IWorkspace.providedBy(self.context)
         and IPMR2ExposureLayer.providedBy(self.request)
         and IWorkspacePage.providedBy(self.view)
     )