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
class UpgradeRegistry(object): """Registry of upgrade steps, by profile. Registry keys are profile ids. Each registry value is a nested mapping: - id -> step for single steps - id -> [ (id1, step1), (id2, step2) ] for nested steps """ def __init__(self): self._registry = GlobalRegistryStorage(IUpgradeSteps) def __getitem__(self, key): return self._registry.get(key) def keys(self): return self._registry.keys() def clear(self): self._registry.clear() def getUpgradeStepsForProfile(self, profile_id): """Return the upgrade steps mapping for a given profile, or None if there are no steps registered for a profile matching that id. """ prefix = "profile-" if profile_id.startswith(prefix): profile_id = profile_id[len(prefix) :] profile_steps = self._registry.get(profile_id) if profile_steps is None: self._registry[profile_id] = OOBTree() profile_steps = self._registry.get(profile_id) return profile_steps def getUpgradeStep(self, profile_id, step_id): """Returns the specified upgrade step for the specified profile, or None if it doesn't exist. """ prefix = "profile-" if profile_id.startswith(prefix): profile_id = profile_id[len(prefix) :] profile_steps = self._registry.get(profile_id) if profile_steps is not None: step = profile_steps.get(step_id, None) if step is None: for key in profile_steps.keys(): if type(profile_steps[key]) == list: subs = dict(profile_steps[key]) step = subs.get(step_id, None) if step is not None: break elif type(step) == list: subs = dict(step) step = subs.get(step_id, None) return step
class UpgradeRegistry(object): """Registry of upgrade steps, by profile. Registry keys are profile ids. Each registry value is a nested mapping: - id -> step for single steps - id -> [ (id1, step1), (id2, step2) ] for nested steps """ def __init__(self): self._registry = GlobalRegistryStorage(IUpgradeSteps) def __getitem__(self, key): return self._registry.get(key) def keys(self): return self._registry.keys() def clear(self): self._registry.clear() def getUpgradeStepsForProfile(self, profile_id): """Return the upgrade steps mapping for a given profile, or None if there are no steps registered for a profile matching that id. """ prefix = 'profile-' if profile_id.startswith(prefix): profile_id = profile_id[len(prefix):] profile_steps = self._registry.get(profile_id) if profile_steps is None: self._registry[profile_id] = OOBTree() profile_steps = self._registry.get(profile_id) return profile_steps def getUpgradeStep(self, profile_id, step_id): """Returns the specified upgrade step for the specified profile, or None if it doesn't exist. """ prefix = 'profile-' if profile_id.startswith(prefix): profile_id = profile_id[len(prefix):] profile_steps = self._registry.get(profile_id) if profile_steps is not None: step = profile_steps.get(step_id, None) if step is None: for key in profile_steps.keys(): if type(profile_steps[key]) == list: subs = dict(profile_steps[key]) step = subs.get(step_id, None) if step is not None: break elif type(step) == list: subs = dict(step) step = subs.get(step_id, None) return step
def __init__(self): self._registry = GlobalRegistryStorage(IUpgradeSteps)