def _cleanup_package(configurator): """Cleanup and make nested if needed. Transform into a nested package if that was the selected option. Remove parts that are not needed depending on the chosen configuration. """ nested = configurator.variables['package.nested'] # construct full path '.../src/collective' start_path = make_path( configurator.target_directory, 'src', configurator.variables['package.namespace'], ) # path for normal packages: '.../src/collective/myaddon' base_path = make_path( start_path, configurator.variables['package.name'], ) if nested: # Event though the target-dir was 'collective.behavior.myaddon' mrbob # created a package collective.behavior.myaddon/src/collective/myaddon # since the template does not hava a folder for namespace2. # Here this package is turned into a nested package # collective.behavior.myaddon/src/collective/behavior/myaddon by # inserting a folder with the namepsace2 ('behavior') and oopying # a __init__.py into it. # full path for nested packages: '.../src/collective/behavior/myaddon' base_path_nested = make_path( start_path, configurator.variables['package.namespace2'], configurator.variables['package.name'], ) # directory to be created: .../src/collective/behavior newpath = make_path( start_path, configurator.variables['package.namespace2'], ) if not os.path.exists(newpath): # create new directory .../src/collective/behavior os.makedirs(newpath) # copy .../src/collective/__init__.py to # .../src/collective/myaddon/__init__.py init = make_path(start_path, '__init__.py') shutil.copy2(init, newpath) # move .../src/collective/myaddon to .../src/collective/behavior shutil.move(base_path, base_path_nested) # use the new path for deleting base_path = base_path_nested
def fix_process_manager(configurator): pm_path = make_path( configurator.target_directory, configurator.variables['process_manager'], ) remove_not_selected_pm(configurator) for f in os.listdir(pm_path): file_path = make_path(pm_path, f) shutil.move(file_path, configurator.target_directory) shutil.rmtree(pm_path)
def remove_not_selected_pm(configurator): delimiter = configurator.raw_questions['process_manager'][ 'choices_delimiter' ] choices = configurator.raw_questions['process_manager']['choices'].split( delimiter ) selected = configurator.variables['process_manager'] for choice in choices: if choice != selected: shutil.rmtree(make_path(configurator.target_directory, choice))
def _cleanup_package(configurator): """Cleanup and make nested if needed. Transform into a nested package if that was the selected option. Remove parts that are not needed depending on the chosen configuration. """ nested = configurator.variables['package.nested'] # construct full path '.../src/collective' start_path = make_path( configurator.target_directory, 'src', configurator.variables['package.namespace'], ) # path for normal packages: '.../src/collective/myaddon' base_path = make_path( start_path, configurator.variables['package.name'], ) if nested: # Event though the target-dir was 'collective.behavior.myaddon' mrbob # created a package collective.behavior.myaddon/src/collective/myaddon # since the template does not hava a folder for namespace2. # Here this package is turned into a nested package # collective.behavior.myaddon/src/collective/behavior/myaddon by # inserting a folder with the namepsace2 ('behavior') and oopying # a __init__.py into it. # full path for nested packages: '.../src/collective/behavior/myaddon' base_path_nested = make_path( start_path, configurator.variables['package.namespace2'], configurator.variables['package.name'], ) # directory to be created: .../src/collective/behavior newpath = make_path( start_path, configurator.variables['package.namespace2'], ) if not os.path.exists(newpath): # create new directory .../src/collective/behavior os.makedirs(newpath) # copy .../src/collective/__init__.py to # .../src/collective/myaddon/__init__.py init = make_path(start_path, '__init__.py') shutil.copy2(init, newpath) # move .../src/collective/myaddon to .../src/collective/behavior shutil.move(base_path, base_path_nested) # use the new path for deleting base_path = base_path_nested # find out what to delete to_delete = [] # remove parts for path in to_delete: if os.path.exists(path): if os.path.isdir(path): shutil.rmtree(path) else: os.remove(path)