def create_command(args): upgrades_directory = args.upgrades_directory if upgrades_directory is None: upgrades_directory = default_upgrades_directory() if upgrades_directory is None: print >>sys.stderr, 'ERROR: Please provide the path to ' + \ 'the upgrades directory with --path.' sys.exit(1) creator = UpgradeStepCreator(upgrades_directory) upgrade_step_directory = creator.create(args.title) print 'Created upgrade step at:', upgrade_step_directory
def test_generate_upgrade_step_by_humanized_name(self): with freeze(datetime(2014, 11, 14, 22, 44, 55)): UpgradeStepCreator( self.upgrades_directory).create('Add controlpanel action') self.assert_upgrade({ 'name': '20141114224455_add_controlpanel_action', 'classname': 'AddControlpanelAction', 'docstring': 'Add controlpanel action.' })
def test_sentence_as_input_is_used_as_docstring_without_modification(self): with freeze(datetime(2014, 3, 4, 5, 6, 7)): UpgradeStepCreator(self.upgrades_directory).create( 'Update ftw.subsite to newest Version.') self.assert_upgrade({ 'name': '20140304050607_update_ftw_subsite_to_newest_version', 'classname': 'UpdateFtwSubsiteToNewestVersion', 'docstring': 'Update ftw.subsite to newest Version.' })
def update_all_specifications_with_upgrade_step(self, output_formatter=None): if not FTW_UPGRADE_INSTALLED: raise UpgradeStepCreationError('ftw.upgrade is not installed.') by_packages = defaultdict(list) for specification_path in self.update_all_specifications( output_formatter=output_formatter): pkg_path = (Path(specification_path).joinpath( '..', '..', '..', '..', '..').abspath()) by_packages[pkg_path].append(Path(specification_path)) for pkg_path, spec_paths in by_packages.items(): upgrades_path = pkg_path.joinpath('upgrades') if not upgrades_path.isdir(): raise UpgradeStepCreationError( 'Missing folder at {!r}'.format(upgrades_path)) wf_names_by_reindex_flag = {False: [], True: []} upgrade_dir = ( UpgradeStepCreator(upgrades_path).create('Update workflows.')) for spec_path in spec_paths: def_path = spec_path.joinpath('..', 'definition.xml').abspath() wf_name = spec_path.parent.name target_dir = upgrade_dir.joinpath('workflows', wf_name) target_dir.makedirs() def_path.copy(target_dir.joinpath('definition.xml')) wf_names_by_reindex_flag[self._has_view_permission_changed( def_path)].append(str(wf_name)) upgrade_module = upgrade_dir.joinpath('upgrade.py') for flag, wf_names in wf_names_by_reindex_flag.items(): if not wf_names: continue upgrade_module.write_bytes( upgrade_module.bytes() + ' self.update_workflow_security(\n' ' [\'{}\'],\n' ' reindex_security={!r})\n'.format( ('\',\n \'').join(wf_names), flag))
def test_generates_directory_and_upgrade_code(self): with freeze(datetime(2014, 11, 14, 22, 44, 55)): UpgradeStepCreator( self.upgrades_directory).create('AddControlpanelAction') upgrade_directory = os.path.join( self.upgrades_directory, '20141114224455_add_controlpanel_action') upgrade_code_file = os.path.join(upgrade_directory, 'upgrade.py') self.assertTrue(os.path.isdir(upgrade_directory)) self.assertTrue(os.path.isfile(upgrade_code_file)) with open(upgrade_code_file) as python_file: code = python_file.read() self.maxDiff = None self.assertMultiLineEqual( '\n'.join(('from ftw.upgrade import UpgradeStep', '', '', 'class AddControlpanelAction(UpgradeStep):', ' """Add controlpanel action.', ' """', '', ' def __call__(self):', ' self.install_upgrade_profile()', '')), code)