def rename(target, new_name): """Rename the global entry TARGET to NEW_NAME. All references to the entry will be adjusted to refer to the new name, including in documentation. e.g. rope rename modulea.py::MyClass MyAwesomeClass or rope rename modulea.py moduleb """ project = rope.base.project.Project(".", ropefolder=".clirope") resource, offset = resourcespec_to_resource_offset(project, target) def very_sure(_): return True renamer = rope.refactor.rename.Rename(project, resource, offset) changes = renamer.get_changes(new_name, docs=True, unsure=very_sure) project.do(changes)
def do_move(project, source, target_file): filefrom, offset = resourcespec_to_resource_offset(project, source) fileto = project.get_resource(target_file) mover = rope.refactor.move.create_move(project, filefrom, offset) changes = mover.get_changes(fileto) project.do(changes)
def move_all_api_modules_to_package(): print('API modules are moving their own packages.') for api_resource in api_resources.get_files(): if api_resource.name != '__init__.py': print('\tfileName: ' + api_resource.name) moduleToPackage = ModuleToPackage(project, api_resource) changes = moduleToPackage.get_changes() project.do(changes)
def rename_all_api_modules(): print('API modules are renaming (drop redundant "_api" suffix).') for api_resource in api_resources.get_folders(): if api_resource.name.endswith('_api'): rename = Rename(project, api_resource) new_name = rename.get_old_name().split('_api')[0] print('\told: ' + api_resource.name + ' new: ' + new_name) changes = rename.get_changes(new_name) project.do(changes)
def get_result(changes, project, resource): # perform the changes project.do(changes) project.validate(resource) project.close() # get the refactored code from the temp file and return it file = io.open(TEMP_PATH) refactored_code = file.read() file.close() return refactored_code
def move_domain_models(): print('Domain specific models are moving to related api packages.') with open(sdk_generated_path + 'opsgenieCodegenModels.csv', mode='r') as csv_file: csv_reader = csv.DictReader(csv_file) for row in csv_reader: if row['opsgenieDomain'] != 'common': model_resource = libutils.path_to_resource(project, sdk_generated_path + sdk_path + 'models/' + row['classFilename'] + '.py', 'file') model_dest_resource = libutils.path_to_resource(project, sdk_generated_path + sdk_path + 'api/' + row['opsgenieDomain'], 'folder') if model_resource.exists() and model_dest_resource.exists(): print('\tclassname: ' + row["classname"] + ' classFilename: ' + row["classFilename"] + ' opsgenieDomain: ' + row["opsgenieDomain"]) moveModule = MoveModule(project, model_resource) changes = moveModule.get_changes(model_dest_resource) project.do(changes)
def perform(project_changes): for project, changes in project_changes: project.do(changes)
def perform(project_changes): for project, changes in project_changes: project.do(changes)
import rope.base.project from rope.base import libutils from rope.refactor.extract import ExtractVariable project = rope.base.project.Project('../lib/ansible') resource = libutils.path_to_resource( project, '../lib/ansible/collections/list.py') extractor = ExtractVariable(project, resource, 1, 50) changes = extractor.get_changes('extracted_variable') project.do(changes)