Ejemplo n.º 1
0
    def _getImportContext(self, context_id, should_purge=None, archive=None):
        """ Crack ID and generate appropriate import context.
        """
        encoding = self.getEncoding()

        if context_id is not None:
            if context_id.startswith('profile-'):
                context_id = context_id[len('profile-'):]
                info = _profile_registry.getProfileInfo(context_id)

                if info.get('product'):
                    path = os.path.join(_getProductPath(info['product']),
                                        info['path'])
                else:
                    path = info['path']
                if should_purge is None:
                    should_purge = (info.get('type') != EXTENSION)
                return DirectoryImportContext(self, path, should_purge,
                                              encoding)

            elif context_id.startswith('snapshot-'):
                context_id = context_id[len('snapshot-'):]
                if should_purge is None:
                    should_purge = True
                return SnapshotImportContext(self, context_id, should_purge,
                                             encoding)

        if archive is not None:
            return TarballImportContext(tool=self,
                                       archive_bits=archive,
                                       encoding='UTF8',
                                       should_purge=should_purge,
                                      )

        raise KeyError('Unknown context "%s"' % context_id)
Ejemplo n.º 2
0
def importVarious(context):
    """Run the setup handlers for the default profile"""
    if context.readDataFile('collective_lineage-default.txt') is None:
        return

    # run the upgrade steps for this package
    portal = getSite()
    setup_tool = getToolByName(portal, 'portal_setup')
    profile_id = "collective.lineage:default"
    upgrade_steps = setup_tool.listUpgrades(profile_id)
    steps_to_run = []
    for step in upgrade_steps:
        if isinstance(step, list):
            # this is a group of steps
            for new_step in step:
                steps_to_run.append(new_step['step'].id)
        else:
            steps_to_run.append(step['step'].id)

    #################
    # from GS tool...
    #################
    for step_id in steps_to_run:
        step = _upgrade_registry.getUpgradeStep(profile_id, step_id)
        if step is not None:
            step.doStep(setup_tool)

    # XXX should be a bit smarter about deciding when to up the
    #     profile version
    profile_info = _profile_registry.getProfileInfo(profile_id)
    version = profile_info.get('version', None)
    if version is not None:
        setup_tool.setLastVersionForProfile(profile_id, version)
Ejemplo n.º 3
0
    def _getImportContext(self, context_id, should_purge=None, archive=None):
        """ Crack ID and generate appropriate import context.

        Note: it seems context_id (profile id) and archive (tarball)
        are mutually exclusive.  Exactly one of the two should be
        None.  There seems to be no use case for a different
        combination.
        """
        encoding = self.getEncoding()

        if context_id is not None:
            prefix = "snapshot-"
            if context_id.startswith(prefix):
                context_id = context_id[len(prefix) :]
                if should_purge is None:
                    should_purge = True
                return SnapshotImportContext(self, context_id, should_purge, encoding)
            prefix = "profile-"
            if context_id.startswith(prefix):
                context_id = context_id[len(prefix) :]
            info = _profile_registry.getProfileInfo(context_id)
            if info.get("product"):
                path = os.path.join(_getProductPath(info["product"]), info["path"])
            else:
                path = info["path"]
            if should_purge is None:
                should_purge = info.get("type") != EXTENSION
            return DirectoryImportContext(self, path, should_purge, encoding)

        if archive is not None:
            return TarballImportContext(tool=self, archive_bits=archive, encoding="UTF8", should_purge=should_purge)

        raise KeyError('Unknown context "%s"' % context_id)
Ejemplo n.º 4
0
def upgrade_step_directory_action(profile, dottedname, path,
                                  soft_dependencies):
    start_version = find_start_version(profile)
    scanner = Scanner(dottedname, path)

    if profile not in _profile_registry.listProfiles():
        raise UpgradeStepConfigurationError(
            'The profile "{0}" needs to be registered before registering its'
            ' upgrade step directory.'.format(profile))

    profileinfo = _profile_registry.getProfileInfo(profile)
    if profileinfo.get('version', None) is not None:
        raise UpgradeStepConfigurationError(
            'Registering an upgrades directory for "{0}" requires this profile'
            ' to not define a version in its metadata.xml.'
            ' The version is automatically set to the latest upgrade.'.format(
                profile))

    _package, profilename = profile.split(':', 1)
    last_version = ''.join(find_start_version(profile))
    for upgrade_info in scanner.scan():
        upgrade_profile_name = '{0}-upgrade-{1}'.format(
            profilename, upgrade_info['target-version'])

        upgrade_handler = wrap_upgrade_step(
            handler=upgrade_info['callable'],
            upgrade_profile='profile-{0}:{1}'.format(dottedname,
                                                     upgrade_profile_name),
            base_profile=profile,
            target_version=upgrade_info['target-version'])

        step = UpgradeStep(upgrade_info['title'],
                           profile,
                           upgrade_info['source-version'] or start_version,
                           upgrade_info['target-version'],
                           '',
                           upgrade_handler)
        _registerUpgradeStep(step)

        _profile_registry.registerProfile(
            name=upgrade_profile_name,
            title='Upgrade {0} to {1}: {2}'.format(
                profile,
                upgrade_info['target-version'],
                upgrade_info['title']),
            description='',
            path=upgrade_info['path'],
            product=dottedname,
            profile_type=EXTENSION,
            for_=IMigratingPloneSiteRoot)

        last_version = upgrade_info['target-version']

    profile = GlobalRegistryStorage(IProfile).get(profile)
    profile['version'] = last_version
    profile['ftw.upgrade:dependencies'] = soft_dependencies
Ejemplo n.º 5
0
def upgrade_step_directory_action(profile, dottedname, path,
                                  soft_dependencies):
    start_version = find_start_version(profile)
    scanner = Scanner(dottedname, path)

    if profile not in _profile_registry.listProfiles():
        raise UpgradeStepConfigurationError(
            'The profile "{0}" needs to be registered before registering its'
            ' upgrade step directory.'.format(profile))

    profileinfo = _profile_registry.getProfileInfo(profile)
    if profileinfo.get('version', None) is not None:
        raise UpgradeStepConfigurationError(
            'Registering an upgrades directory for "{0}" requires this profile'
            ' to not define a version in its metadata.xml.'
            ' The version is automatically set to the latest upgrade.'.format(
                profile))

    _package, profilename = profile.split(':', 1)
    last_version = ''.join(find_start_version(profile))
    for upgrade_info in scanner.scan():
        upgrade_profile_name = '{0}-upgrade-{1}'.format(
            profilename, upgrade_info['target-version'])

        upgrade_handler = wrap_upgrade_step(
            handler=upgrade_info['callable'],
            upgrade_profile='profile-{0}:{1}'.format(dottedname,
                                                     upgrade_profile_name),
            base_profile=profile,
            target_version=upgrade_info['target-version'])

        step = UpgradeStep(upgrade_info['title'],
                           profile,
                           upgrade_info['source-version'] or start_version,
                           upgrade_info['target-version'],
                           '',
                           upgrade_handler)
        _registerUpgradeStep(step)

        _profile_registry.registerProfile(
            name=upgrade_profile_name,
            title='Upgrade {0} to {1}: {2}'.format(
                profile,
                upgrade_info['target-version'],
                upgrade_info['title']),
            description='',
            path=upgrade_info['path'],
            product=dottedname,
            profile_type=EXTENSION,
            for_=IMigratingPloneSiteRoot)

        last_version = upgrade_info['target-version']

    profile = GlobalRegistryStorage(IProfile).get(profile)
    profile['version'] = last_version
    profile['ftw.upgrade:dependencies'] = soft_dependencies
Ejemplo n.º 6
0
def runUpgradeSteps(profile_id):
    """run the upgrade steps for the given profile_id in the form of:

    profile-<package_name>:<profile_name>

    example:

    profile-my.package:default

    Basically this is the code from GS.tool.manage_doUpgrades() in step
    form.  Had to extract the code because it was doing a redirect back to the
    upgrades form in the GS tool.
    """
    portal = api.portal.get()
    setup_tool = getToolByName(portal, 'portal_setup')
    logger = logging.getLogger(__name__)
    logger.info('****** runUpgradeSteps BEGIN ******')
    upgrade_steps = setup_tool.listUpgrades(profile_id)
    steps_to_run = []
    for step in upgrade_steps:
        if isinstance(step, list):
            # this is a group of steps
            for new_step in step:
                steps_to_run.append(new_step['step'].id)
        else:
            steps_to_run.append(step['step'].id)

    #################
    # from GS tool...
    ##################
    for step_id in steps_to_run:
        step = _upgrade_registry.getUpgradeStep(profile_id, step_id)
        if step is not None:
            step.doStep(setup_tool)
            msg = "Ran upgrade step %s for profile %s" % (step.title,
                                                          profile_id)
            logger.info(msg)

    # XXX should be a bit smarter about deciding when to up the
    #     profile version
    profile_info = _profile_registry.getProfileInfo(profile_id)
    version = profile_info.get('version', None)
    if version is not None:
        setup_tool.setLastVersionForProfile(profile_id, version)

    logger.info('****** runUpgradeSteps END ******')
Ejemplo n.º 7
0
def runUpgradeSteps(profile_id):
    """run the upgrade steps for the given profile_id in the form of:

    profile-<package_name>:<profile_name>

    example:

    profile-my.package:default

    Basically this is the code from GS.tool.manage_doUpgrades() in step
    form.  Had to extract the code because it was doing a redirect back to the
    upgrades form in the GS tool.
    """
    portal = api.portal.get()
    setup_tool = getToolByName(portal, 'portal_setup')
    logger = logging.getLogger(__name__)
    logger.info('****** runUpgradeSteps BEGIN ******')
    upgrade_steps = setup_tool.listUpgrades(profile_id)
    steps_to_run = []
    for step in upgrade_steps:
        if isinstance(step, list):
            # this is a group of steps
            for new_step in step:
                steps_to_run.append(new_step['step'].id)
        else:
            steps_to_run.append(step['step'].id)

    #################
    # from GS tool...
    ##################
    for step_id in steps_to_run:
        step = _upgrade_registry.getUpgradeStep(profile_id, step_id)
        if step is not None:
            step.doStep(setup_tool)
            msg = "Ran upgrade step %s for profile %s" % (step.title,
                                                          profile_id)
            logger.info(msg)

    # XXX should be a bit smarter about deciding when to up the
    #     profile version
    profile_info = _profile_registry.getProfileInfo(profile_id)
    version = profile_info.get('version', None)
    if version is not None:
        setup_tool.setLastVersionForProfile(profile_id, version)

    logger.info('****** runUpgradeSteps END ******')
Ejemplo n.º 8
0
 def getProfileInfo(self, profile_id):
     if profile_id.startswith("profile-"):
         profile_id = profile_id[len('profile-'):]
     elif profile_id.startswith("snapshot-"):
         profile_id = profile_id[len('snapshot-'):]
     return _profile_registry.getProfileInfo(profile_id)
Ejemplo n.º 9
0
 def getProfileInfo(self, profile_id):
     if profile_id.startswith("profile-"):
         profile_id = profile_id[len('profile-'):]
     elif profile_id.startswith("snapshot-"):
         profile_id = profile_id[len('snapshot-'):]
     return _profile_registry.getProfileInfo(profile_id)
Ejemplo n.º 10
0
 def getProfileInfo(self, profile_id):
     return _profile_registry.getProfileInfo(profile_id)