def _extractUtilities(self): fragment = self._doc.createDocumentFragment() # We get back a generator but in order to have a consistent order # which is needed for the tests we convert to a sorted list registrations = [reg for reg in self.context.registeredUtilities()] registrations.sort() for registration in registrations: child = self._doc.createElement('utility') provided = _getDottedName(registration.provided) child.setAttribute('interface', provided) name = _getDottedName(registration.name) if name: child.setAttribute('name', name) comp = registration.component # check if the component is acquisition wrapped. If it is, export # an object reference instead of a factory reference if getattr(comp, 'aq_base', None) is not None: child.setAttribute('object', comp.getId()) else: factory = _getDottedName(type(comp)) child.setAttribute('factory', factory) fragment.appendChild(child) return fragment
def _extractUtilities(self): fragment = self._doc.createDocumentFragment() registrations = [ {'component': reg.component, 'provided': _getDottedName(reg.provided), 'name': reg.name} for reg in self.context.registeredUtilities() ] registrations.sort(key=itemgetter('name')) registrations.sort(key=itemgetter('provided')) site = aq_base(self._getSite()) for reg_info in registrations: child = self._doc.createElement('utility') child.setAttribute('interface', reg_info['provided']) if reg_info['name']: child.setAttribute('name', reg_info['name']) comp = reg_info['component'] # check if the component is acquisition wrapped. If it is, export # an object reference instead of a factory reference if getattr(comp, 'aq_base', None) is not None: if aq_base(comp) is site: child.setAttribute('object', '') else: child.setAttribute('object', comp.getId()) else: factory = _getDottedName(type(comp)) child.setAttribute('factory', factory) fragment.appendChild(child) return fragment
def _extractAdapters(self): fragment = self._doc.createDocumentFragment() # We get back a generator but in order to have a consistent order # which is needed for the tests we convert to a sorted list registrations = [reg for reg in self.context.registeredAdapters()] registrations.sort() for registration in registrations: child = self._doc.createElement('adapter') factory = _getDottedName(registration.factory) provided = _getDottedName(registration.provided) name = _getDottedName(registration.name) for_ = u'' for interface in registration.required: for_ = for_ + _getDottedName(interface) + u'\n ' child.setAttribute('factory', factory) child.setAttribute('provides', provided) child.setAttribute('for_', for_.strip()) if name: child.setAttribute('name', name) fragment.appendChild(child) return fragment
def _extractAdapters(self): fragment = self._doc.createDocumentFragment() registrations = [ {'factory': _getDottedName(reg.factory), 'provided': _getDottedName(reg.provided), 'required': reg.required, 'name': reg.name} for reg in self.context.registeredAdapters() ] registrations.sort(key=itemgetter('name')) registrations.sort(key=itemgetter('provided')) for reg_info in registrations: child = self._doc.createElement('adapter') for_ = u'' for interface in reg_info['required']: for_ = for_ + _getDottedName(interface) + u'\n ' child.setAttribute('factory', reg_info['factory']) child.setAttribute('provides', reg_info['provided']) child.setAttribute('for_', for_.strip()) if reg_info['name']: child.setAttribute('name', reg_info['name']) fragment.appendChild(child) return fragment
def _extractUtilities(self): fragment = self._doc.createDocumentFragment() registrations = [{ 'component': reg.component, 'provided': _getDottedName(reg.provided), 'name': reg.name } for reg in self.context.registeredUtilities()] registrations.sort(key=itemgetter('name')) registrations.sort(key=itemgetter('provided')) site = aq_base(self._getSite()) for reg_info in registrations: child = self._doc.createElement('utility') child.setAttribute('interface', reg_info['provided']) if reg_info['name']: child.setAttribute('name', reg_info['name']) comp = reg_info['component'] # check if the component is acquisition wrapped. If it is, export # an object reference instead of a factory reference if getattr(comp, 'aq_base', None) is not None: if aq_base(comp) is site: child.setAttribute('object', '') else: child.setAttribute('object', comp.getId()) else: factory = _getDottedName(type(comp)) child.setAttribute('factory', factory) fragment.appendChild(child) return fragment
def registerStep( self, id, handler, title=None, description=None ): """ Register an export step. o 'id' is the unique identifier for this step o 'step' should implement IExportPlugin. o 'title' is a one-line UI description for this step. If None, the first line of the documentation string of the step is used, or the id if no docstring can be found. o 'description' is a one-line UI description for this step. If None, the remaining line of the documentation string of the step is used, or default to ''. """ if title is None or description is None: t, d = _extractDocstring( handler, id, '' ) title = title or t description = description or d info = { 'id' : id , 'handler' : _getDottedName( handler ) , 'title' : title , 'description' : description } self._registered[ id ] = info
def registerStep(self, id, handler, title=None, description=None): """ Register an export step. o 'id' is the unique identifier for this step o 'handler' is the dottoed name of a handler which should implement IImportPlugin. o 'title' is a one-line UI description for this step. If None, the first line of the documentation string of the step is used, or the id if no docstring can be found. o 'description' is a one-line UI description for this step. If None, the remaining line of the documentation string of the step is used, or default to ''. """ if not isinstance(handler, str): handler = _getDottedName(handler) if title is None or description is None: method = _resolveDottedName(handler) if method is None: t, d = id, "" else: t, d = _extractDocstring(method, id, "") title = title or t description = description or d info = {"id": id, "handler": handler, "title": title, "description": description} self._registered[id] = info
def registerStep(self, id, version, handler, dependencies=(), title=None, description=None): """ Register a setup step. o 'id' is a unique name for this step, o 'version' is a string for comparing versions, it is preferred to be a yyyy/mm/dd-ii formatted string (date plus two-digit ordinal). when comparing two version strings, the version with the lower sort order is considered the older version. - Newer versions of a step supplant older ones. - Attempting to register an older one after a newer one results in a KeyError. o 'handler' is the dottoed name of a handler which should implement IImportPlugin. o 'dependencies' is a tuple of step ids which have to run before this step in order to be able to run at all. Registration of steps that have unmet dependencies are deferred until the dependencies have been registered. o 'title' is a one-line UI description for this step. If None, the first line of the documentation string of the handler is used, or the id if no docstring can be found. o 'description' is a one-line UI description for this step. If None, the remaining line of the documentation string of the handler is used, or default to ''. """ already = self.getStepMetadata(id) if already and already["version"] > version: raise KeyError("Existing registration for step %s, version %s" % (id, already["version"])) if not isinstance(handler, str): handler = _getDottedName(handler) if title is None or description is None: method = _resolveDottedName(handler) if method is None: t, d = id, "" else: t, d = _extractDocstring(method, id, "") title = title or t description = description or d info = { "id": id, "version": version, "handler": handler, "dependencies": dependencies, "title": title, "description": description, } self._registered[id] = info
def registerStep( self , id , version , handler , dependencies=() , title=None , description=None ): """ Register a setup step. o 'id' is a unique name for this step, o 'version' is a string for comparing versions, it is preferred to be a yyyy/mm/dd-ii formatted string (date plus two-digit ordinal). when comparing two version strings, the version with the lower sort order is considered the older version. - Newer versions of a step supplant older ones. - Attempting to register an older one after a newer one results in a KeyError. o 'handler' should implement IImportPlugin. o 'dependencies' is a tuple of step ids which have to run before this step in order to be able to run at all. Registration of steps that have unmet dependencies are deferred until the dependencies have been registered. o 'title' is a one-line UI description for this step. If None, the first line of the documentation string of the handler is used, or the id if no docstring can be found. o 'description' is a one-line UI description for this step. If None, the remaining line of the documentation string of the handler is used, or default to ''. """ already = self.getStepMetadata( id ) if already and already[ 'version' ] > version: raise KeyError( 'Existing registration for step %s, version %s' % ( id, already[ 'version' ] ) ) if title is None or description is None: t, d = _extractDocstring( handler, id, '' ) title = title or t description = description or d info = { 'id' : id , 'version' : version , 'handler' : _getDottedName( handler ) , 'dependencies' : dependencies , 'title' : title , 'description' : description } self._registered[ id ] = info
def __init__(self, id): self.id = str(id) self._import_registry = ImportStepRegistry() self._export_registry = ExportStepRegistry() self._export_registry.registerStep('step_registries', _getDottedName(exportStepRegistries), 'Export import / export steps.', ) self._toolset_registry = ToolsetRegistry()
def __init__(self, id): self.id = str(id) self._import_registry = ImportStepRegistry() self._export_registry = ExportStepRegistry() self._export_registry.registerStep( 'step_registries', _getDottedName(exportStepRegistries), 'Export import / export steps.', ) self._toolset_registry = ToolsetRegistry()
def _extractUtilities(self): fragment = self._doc.createDocumentFragment() # We get back a generator but in order to have a consistent order # which is needed for the tests we convert to a sorted list registrations = [reg for reg in self.context.registeredUtilities()] registrations.sort() for registration in registrations: child = self._doc.createElement('utility') provided = _getDottedName(registration.provided) child.setAttribute('interface', provided) name = _getDottedName(registration.name) if name: child.setAttribute('name', name) comp = registration.component # check if the component is acquisition wrapped. If it is export # an object reference instead of a factory reference if hasattr(comp, 'aq_base'): # if the site is acquistion wrapped as well, get the relative # path to the site path = '/'.join(comp.getPhysicalPath()) site = aq_parent(self.context) if hasattr(site, 'aq_base'): site_path = '/'.join(site.getPhysicalPath()) rel_path = path[len(site_path):] if not rel_path: rel_path = '/' child.setAttribute('object', rel_path) else: factory = _getDottedName(type(comp)) child.setAttribute('factory', factory) fragment.appendChild(child) return fragment
def _extractUtilities(self): fragment = self._doc.createDocumentFragment() # We get back a generator but in order to have a consistent order # which is needed for the tests we convert to a sorted list registrations = [reg for reg in self.context.registeredUtilities()] registrations.sort() for registration in registrations: child = self._doc.createElement('utility') provided = _getDottedName(registration.provided) child.setAttribute('interface', provided) name = _getDottedName(registration.name) if name: child.setAttribute('name', name) comp = registration.component # check if the component is acquisition wrapped. If it is export # an object reference instead of a factory reference if hasattr(comp, 'aq_base'): # if the site is acquistion wrapped as well, get the relative # path to the site path = '/'.join(comp.getPhysicalPath()) site = self.environ.getSite() if hasattr(site, 'aq_base'): site_path = '/'.join(site.getPhysicalPath()) rel_path = path[len(site_path):] child.setAttribute('object', rel_path) else: factory = _getDottedName(type(comp)) child.setAttribute('factory', factory) fragment.appendChild(child) return fragment
def export(self, export_context, subdir, root=False): """ See IFilesystemExporter. """ context = self.context if not root: subdir = '%s/%s' % (subdir, context.getId()) exportable = self.listExportableItems() stream = StringIO() csv_writer = writer(stream) for object_id, object, adapter in exportable: factory_namer = IContentFactoryName(object, None) if factory_namer is None: factory_name = _getDottedName(object.__class__) else: factory_name = factory_namer() csv_writer.writerow((object_id, factory_name)) export_context.writeDataFile( '.objects', text=stream.getvalue(), content_type='text/comma-separated-values', subdir=subdir, ) prop_adapter = IINIAware(context, None) if prop_adapter is not None: export_context.writeDataFile( '.properties', text=prop_adapter.as_ini(), content_type='text/plain', subdir=subdir, ) for object_id, object, adapter in exportable: if adapter is not None: adapter.export(export_context, subdir)
def export(self, export_context, subdir, root=False): """ See IFilesystemExporter. """ context = self.context if not root: subdir = '%s/%s' % (subdir, context.getId()) exportable = self.listExportableItems() stream = StringIO() csv_writer = writer(stream) for object_id, object, adapter in exportable: factory_namer = queryAdapter(object, IContentFactoryName, None) if factory_namer is None: factory_name = _getDottedName(object.__class__) else: factory_name = factory_namer() csv_writer.writerow((object_id, factory_name)) export_context.writeDataFile('.objects', text=stream.getvalue(), content_type='text/comma-separated-values', subdir=subdir, ) prop_adapter = queryAdapter(context, IINIAware, None) if prop_adapter is not None: export_context.writeDataFile('.properties', text=prop_adapter.as_ini(), content_type='text/plain', subdir=subdir, ) for object_id, object, adapter in exportable: if adapter is not None: adapter.export(export_context, subdir)
def registerStep(self, id, handler, title=None, description=None): """ Register an export step. o 'id' is the unique identifier for this step o 'handler' is the dottoed name of a handler which should implement IImportPlugin. o 'title' is a one-line UI description for this step. If None, the first line of the documentation string of the step is used, or the id if no docstring can be found. o 'description' is a one-line UI description for this step. If None, the remaining line of the documentation string of the step is used, or default to ''. """ if not isinstance(handler, str): handler = _getDottedName(handler) if title is None or description is None: method = _resolveDottedName(handler) if method is None: t, d = id, '' else: t, d = _extractDocstring(method, id, '') title = title or t description = description or d info = { 'id': id, 'handler': handler, 'title': title, 'description': description } self._registered[id] = info