def exportSiteStructure(context):

    transmogrifier = ITransmogrifier(context.getSite())
    # we don't use transmogrifer's __call__ method, because we need to do
    # some modification in pipeline sections

    config_name = registerPersistentConfig(context.getSite(), "export")
    if config_name is None:
        transmogrifier._raw = _load_config(EXPORT_CONFIG)
    else:
        transmogrifier._raw = _load_config(config_name)
        global CONFIGFILE
        CONFIGFILE = None
    transmogrifier._data = {}

    options = transmogrifier._raw["transmogrifier"]
    sections = options["pipeline"].splitlines()
    pipeline = constructPipeline(transmogrifier, sections)

    last_section = pipeline.gi_frame.f_locals["self"]

    # if 'quintagroup.transmogrifier.writer' section's export context is
    # tarball replace it with given function argument
    while hasattr(last_section, "previous"):
        if isinstance(last_section, WriterSection) and isinstance(last_section.export_context, TarballExportContext):
            last_section.export_context = context
        last_section = last_section.previous
        # end cycle if we get empty starter section
        if type(last_section) == type(iter(())):
            break
        last_section = last_section.gi_frame.f_locals["self"]

    # Pipeline execution
    for item in pipeline:
        pass  # discard once processed
def importSiteStructure(context):

    # Only run step if a flag file is present
    if context.readDataFile('quintagroup.transmogrifier-import.txt') is None:
        if getattr(context, '_archive', None) is None:
            return

    transmogrifier = ITransmogrifier(context.getSite())

    # we don't use transmogrifer's __call__ method, because we need to do
    # some modification in pipeline sections

    config_name = registerPersistentConfig(context.getSite(), 'import')
    if config_name is None:
        transmogrifier._raw = _load_config(IMPORT_CONFIG)
    else:
        transmogrifier._raw = _load_config(config_name)
        global CONFIGFILE
        CONFIGFILE = None
    transmogrifier._data = {}

    # this function is also called when adding Plone site, so call standard handler
    path = ''
    prefix = 'structure'
    if 'reader' in transmogrifier._raw:
        path = transmogrifier._raw['reader'].get('path', '')
        prefix = transmogrifier._raw['reader'].get('prefix', 'structure')
    if not context.readDataFile('.objects.xml', subdir=os.path.join(path, prefix)):
        try:
            from Products.GenericSetup.interfaces import IFilesystemImporter
            IFilesystemImporter(context.getSite()).import_(context, 'structure', True)
        except ImportError:
            pass
        return

    options = transmogrifier._raw['transmogrifier']
    sections = options['pipeline'].splitlines()
    pipeline = constructPipeline(transmogrifier, sections)

    last_section = pipeline.gi_frame.f_locals['self']

    # if 'quintagroup.transmogrifier.writer' section's export context is
    # tarball replace it with given function argument
    while hasattr(last_section, 'previous'):
        if isinstance(last_section, ReaderSection) and \
            isinstance(last_section.import_context, TarballImportContext):
            last_section.import_context = context
        last_section = last_section.previous
        # end cycle if we get empty starter section
        if type(last_section) == type(iter(())):
            break
        last_section = last_section.gi_frame.f_locals['self']

    # Pipeline execution
    for item in pipeline:
        pass # discard once processed
def importSiteStructure(context):

    # Only run step if a flag file is present
    if context.readDataFile('quintagroup.transmogrifier-import.txt') is None:
        if getattr(context, '_archive', None) is None:
            return

    transmogrifier = ITransmogrifier(context.getSite())

    # we don't use transmogrifer's __call__ method, because we need to do
    # some modification in pipeline sections

    config_name = registerPersistentConfig(context.getSite(), 'import')
    if config_name is None:
        transmogrifier._raw = _load_config(IMPORT_CONFIG)
    else:
        transmogrifier.configuration_id = config_name
        transmogrifier._raw = _load_config(config_name)
        global CONFIGFILE
        CONFIGFILE = None
    transmogrifier._data = {}

    # this function is also called when adding Plone site, so call standard handler
    path = ''
    prefix = 'structure'
    if 'reader' in transmogrifier._raw:
        path = transmogrifier._raw['reader'].get('path', '')
        prefix = transmogrifier._raw['reader'].get('prefix', 'structure')
    if not context.readDataFile('.objects.xml',
                                subdir=os.path.join(path, prefix)):
        try:
            from Products.GenericSetup.interfaces import IFilesystemImporter
            IFilesystemImporter(context.getSite()).import_(
                context, 'structure', True)
        except ImportError:
            pass
        return

    IAnnotations(transmogrifier)[IMPORT_CONTEXT] = context
    options = transmogrifier._raw['transmogrifier']
    sections = options['pipeline'].splitlines()
    pipeline = constructPipeline(transmogrifier, sections)

    last_section = pipeline.gi_frame.f_locals['self']

    # Pipeline execution
    for item in pipeline:
        pass  # discard once processed
Exemple #4
0
    def updateWidgets(self):
        self.label = self.request.get('form.widgets.config')
        config = _load_config(self.request.get('form.widgets.config'))
        section = None
        for section_id in config.keys():
            tmp = config[section_id]
            if tmp.get('blueprint', '') in SOURCE_SECTIONS:
                section = tmp
                break
        if not section:
            raise Exception("Source section not found.")

        # Omit some fields depending on the selected source
        if section['blueprint'] == 'collective.jsonmigrator.catalogsource':
            self.fields = self.fields.omit('remote_path', 'remote_crawl_depth',
                                           'remote_skip_path')
        elif section['blueprint'] == 'collective.jsonmigrator.remotesource':
            self.fields = self.fields.omit('catalog_path', 'catalog_query')

        # Fill in default values from the transmogrifier config file
        for option, value in section.items():
            field = self.fields.get(option.replace('-', '_'))
            if field:
                field = field.field
                value = value.decode('utf8')
                if IFromUnicode.providedBy(field):
                    field.default = field.fromUnicode(value)
                elif IList.providedBy(field):
                    field.default = [
                        field.value_type.fromUnicode(v) for v in value.split()
                    ]

        super(JSONMigratorRun, self).updateWidgets()
        self.widgets['config'].mode = interfaces.HIDDEN_MODE
    def updateWidgets(self):
        config = _load_config(self.request.get("form.widgets.config"))
        section = None
        for section_id in config.keys():
            tmp = config[section_id]
            if tmp.get("blueprint", "") in SOURCE_SECTIONS:
                section = tmp
                break
        if not section:
            raise Exception("Source section not found.")

        # Omit some fields depending on the selected source
        if section["blueprint"] == "collective.jsonmigrator.catalogsource":
            self.fields = self.fields.omit("remote_path", "remote_crawl_depth", "remote_skip_path")
        elif section["blueprint"] == "collective.jsonmigrator.remotesource":
            self.fields = self.fields.omit("catalog_path", "catalog_query")

        # Fill in default values from the transmogrifier config file
        for option, value in section.items():
            field = self.fields.get(option.replace("-", "_"))
            if field:
                field = field.field
                value = value.decode("utf8")
                if IFromUnicode.providedBy(field):
                    field.default = field.fromUnicode(value)
                elif IList.providedBy(field):
                    field.default = [field.value_type.fromUnicode(v) for v in value.split()]

        super(JSONMigratorRun, self).updateWidgets()
        self.widgets["config"].mode = interfaces.HIDDEN_MODE
def importSiteStructure(context):

    # Only run step if a flag file is present
    if context.readDataFile("quintagroup.transmogrifier-import.txt") is None:
        if getattr(context, "_archive", None) is None:
            return

    transmogrifier = ITransmogrifier(context.getSite())
    # we don't use transmogrifer's __call__ method, because we need to do
    # some modification in pipeline sections

    config_name = registerPersistentConfig(context.getSite(), "import")
    if config_name is None:
        transmogrifier._raw = _load_config(IMPORT_CONFIG)
    else:
        transmogrifier.configuration_id = config_name
        transmogrifier._raw = _load_config(config_name)
        global CONFIGFILE
        CONFIGFILE = None
    transmogrifier._data = {}

    # this function is also called when adding Plone site, so call standard handler
    path = ""
    prefix = "structure"
    if "reader" in transmogrifier._raw:
        path = transmogrifier._raw["reader"].get("path", "")
        prefix = transmogrifier._raw["reader"].get("prefix", "structure")
    if not context.readDataFile(".objects.xml", subdir=os.path.join(path, prefix)):
        try:
            from Products.GenericSetup.interfaces import IFilesystemImporter

            IFilesystemImporter(context.getSite()).import_(context, "structure", True)
        except ImportError:
            pass
        return

    IAnnotations(transmogrifier)[IMPORT_CONTEXT] = context
    options = transmogrifier._raw["transmogrifier"]
    sections = options["pipeline"].splitlines()
    pipeline = constructPipeline(transmogrifier, sections)

    last_section = pipeline.gi_frame.f_locals["self"]

    # Pipeline execution
    for item in pipeline:
        pass  # discard once processed
Exemple #7
0
 def _loadConfig(self, config):
     from collective.transmogrifier.transmogrifier import _load_config
     config = (
         '[transmogrifier]\n'
         'include=collective.transmogrifier.tests.included\n\n') + config
     self._registerConfig(u'collective.transmogrifier.tests.includer',
                          config)
     return _load_config(u'collective.transmogrifier.tests.includer')
Exemple #8
0
 def _loadConfig(self, config):
     from collective.transmogrifier.transmogrifier import _load_config
     config = (
         '[transmogrifier]\n'
         'include=collective.transmogrifier.tests.included\n\n'
         ) + config
     self._registerConfig(
         u'collective.transmogrifier.tests.includer', config)
     return _load_config(u'collective.transmogrifier.tests.includer')
 def __call__(self, context):
     terms = []
     for conf_id in configuration_registry.listConfigurationIds():
         conf_file = _load_config(conf_id)
         for section_id in conf_file.keys():
             section = conf_file[section_id]
             if section.get("blueprint", "") in SOURCE_SECTIONS:
                 conf = configuration_registry.getConfiguration(conf_id)
                 terms.append(SimpleVocabulary.createTerm(conf_id, conf_id, conf["title"]))
                 break
     return SimpleVocabulary(terms)
Exemple #10
0
def importSiteStructure(context):
    # this function is also called when adding Plone site, so call standard handler
    if not context.readDataFile('.objects.xml', subdir='structure'):
        IFilesystemImporter(context.getSite()).import_(context, 'structure', True)
        return

    transmogrifier = ITransmogrifier(context.getSite())

    # we don't use transmogrifer's __call__ method, because we need to do
    # some modification in pipeline sections

    config_name = registerPersistentConfig(context.getSite(), 'import')
    if config_name is None:
        transmogrifier._raw = _load_config(IMPORT_CONFIG)
    else:
        transmogrifier._raw = _load_config(config_name)
        global CONFIGFILE
        CONFIGFILE = None
    transmogrifier._data = {}

    options = transmogrifier._raw['transmogrifier']
    sections = options['pipeline'].splitlines()
    pipeline = constructPipeline(transmogrifier, sections)

    last_section = pipeline.gi_frame.f_locals['self']

    # if 'quintagroup.transmogrifier.writer' section's export context is
    # tarball replace it with given function argument
    while hasattr(last_section, 'previous'):
        if isinstance(last_section, ReaderSection) and \
            isinstance(last_section.import_context, TarballImportContext):
            last_section.import_context = context
        last_section = last_section.previous
        # end cycle if we get empty starter section
        if type(last_section) == type(iter(())):
            break
        last_section = last_section.gi_frame.f_locals['self']

    # Pipeline execution
    for item in pipeline:
        pass # discard once processed
Exemple #11
0
 def __call__(self, context):
     terms = []
     for conf_id in configuration_registry.listConfigurationIds():
         conf_file = _load_config(conf_id)
         for section_id in conf_file.keys():
             section = conf_file[section_id]
             if section.get('blueprint', '') in SOURCE_SECTIONS:
                 conf = configuration_registry.getConfiguration(conf_id)
                 terms.append(SimpleVocabulary.createTerm(
                     conf_id, conf_id, conf['title']))
                 break
     return SimpleVocabulary(terms)
Exemple #12
0
 def __call__(self, context):
     terms = []
     for conf_id in configuration_registry.listConfigurationIds():
         print conf_id
         conf_file = _load_config(conf_id)
         for section_id in conf_file.keys():
             section = conf_file[section_id]
             if section.get('blueprint', '') == 'plone.app.transmogrifier.atschemaupdater':
                 conf = configuration_registry.getConfiguration(conf_id)
                 terms.append(SimpleVocabulary.createTerm(
                         conf_id, conf_id, conf['title']))
                 break
     return SimpleVocabulary(terms)
def exportSiteStructure(context):

    transmogrifier = ITransmogrifier(context.getSite())

    # we don't use transmogrifer's __call__ method, because we need to do
    # some modification in pipeline sections

    config_name = registerPersistentConfig(context.getSite(), 'export')
    if config_name is None:
        transmogrifier._raw = _load_config(EXPORT_CONFIG)
    else:
        transmogrifier._raw = _load_config(config_name)
        global CONFIGFILE
        CONFIGFILE = None
    transmogrifier._data = {}

    options = transmogrifier._raw['transmogrifier']
    sections = options['pipeline'].splitlines()
    pipeline = constructPipeline(transmogrifier, sections)

    last_section = pipeline.gi_frame.f_locals['self']

    # if 'quintagroup.transmogrifier.writer' section's export context is
    # tarball replace it with given function argument
    while hasattr(last_section, 'previous'):
        if isinstance(last_section, WriterSection) and \
            isinstance(last_section.export_context, TarballExportContext):
            last_section.export_context = context
        last_section = last_section.previous
        # end cycle if we get empty starter section
        if type(last_section) == type(iter(())):
            break
        last_section = last_section.gi_frame.f_locals['self']

    # Pipeline execution
    for item in pipeline:
        pass # discard once processed
Exemple #14
0
def formfactory(configname):
    if configname in groupforms:
        return groupforms[configname]
    groups = []
    config = _load_config(configname)
    sections = config['transmogrifier']['pipeline'].splitlines()
    print sections
    for section_id in sections:
        if not section_id:
            continue
        if section_id == 'transmogrifier':
            continue
        cparser = config[section_id]
        g = type(section_id, (group.Group,),dict(label=section_id.capitalize()))
        fields = []
        doc = cparser.get('@doc','')
        for key,value in cparser.items():
            if key in ['@doc','blueprint']:
                continue 
            if key.startswith('@'):
                key = key[1:]
                metavar,_,help = value.partition(':')
                default = unicode(cparser.get(key,''))
                help = value
            else:
                if '@'+key in cparser:
                    # let the @option line be used instead
                    continue
                else:
                    metavar = 'LINE'
                    default = unicode(value)
                    help = ''
            title = key.capitalize().replace('-',' ').replace('_',' ')
#                name = "%s:%s"%(section_id,key[1:])
            if metavar == 'HIDDEN':
                continue
            elif metavar == 'PASSWORD':
                ftype = Password()
            elif metavar == 'INT':
                ftype = Int()
                if default:
                    default = int(default)
                else:
                    default = 0
            #elif metavar == 'URL':
            #    ftype = URI()
            elif metavar == 'LIST' or '\n' in default:
                ftype = List(
                    value_type=TextLine(),)
                #ftype = Text()
                #if type(default) == type(""):
                default = default.splitlines()
                ftype.widgetFactory = multi.multiFieldWidgetFactory
            elif metavar.upper() != metavar:
                ftype = Bool()
                default = len(default)
            else:
                ftype = TextLine()
            ftype.__name__ = "%s-%s"%(section_id,key.replace('-', '_'))
            ftype.title=unicode(title)
            ftype.description=unicode(help)
            ftype.required=False
            ftype.default = default
            print (key,value,ftype,default)
            fields.append(ftype)
        if fields:
            g.fields = field.Fields(*fields)
            groups.append(g)
    groupforms[configname]=groups
    return groups
Exemple #15
0
def formfactory(configname):
    if configname in groupforms:
        return groupforms[configname]
    groups = []
    config = _load_config(configname)
    sections = config['transmogrifier']['pipeline'].splitlines()
    print sections
    for section_id in sections:
        if not section_id:
            continue
        if section_id == 'transmogrifier':
            continue
        cparser = config[section_id]
        g = type(section_id, (group.Group, ),
                 dict(label=section_id.capitalize()))
        fields = []
        for key, value in cparser.items():
            if key in ['@doc', 'blueprint']:
                continue
            if key.startswith('@'):
                key = key[1:]
                metavar, _, help = value.partition(':')
                default = unicode(cparser.get(key, ''))
                help = value
            else:
                if '@' + key in cparser:
                    # let the @option line be used instead
                    continue
                else:
                    metavar = 'LINE'
                    default = unicode(value)
                    help = ''
            title = key.capitalize().replace('-', ' ').replace('_', ' ')
            # name = "%s:%s"%(section_id,key[1:])
            if metavar == 'HIDDEN':
                continue
            elif metavar == 'PASSWORD':
                ftype = Password()
            elif metavar == 'INT':
                ftype = Int()
                if default:
                    default = int(default)
                else:
                    default = 0
            # elif metavar == 'URL':
            #    ftype = URI()
            elif metavar == 'LIST' or '\n' in default:
                ftype = List(value_type=TextLine(), )
                # ftype = Text()
                # if type(default) == type(""):
                default = default.splitlines()
                ftype.widgetFactory = multi.multiFieldWidgetFactory
            elif metavar.upper() != metavar:
                ftype = Bool()
                default = len(default)
            else:
                ftype = TextLine()
            ftype.__name__ = "%s-%s" % (section_id, key.replace('-', '_'))
            ftype.title = unicode(title)
            ftype.description = unicode(help)
            ftype.required = False
            ftype.default = default
            print(key, value, ftype, default)
            fields.append(ftype)
        if fields:
            g.fields = field.Fields(*fields)
            groups.append(g)
    groupforms[configname] = groups
    return groups