def _rename_module(self, resource, new_name, changes): if not resource.is_folder(): new_name = new_name + '.py' parent_path = resource.parent.path if parent_path == '': new_location = new_name else: new_location = parent_path + '/' + new_name changes.add_change(MoveResource(resource, new_location))
def get_changes(self): changes = ChangeSet('Transform <%s> module to package' % self.resource.path) new_content = self._transform_relatives_to_absolute(self.resource) if new_content is not None: changes.add_change(ChangeContents(self.resource, new_content)) parent = self.resource.parent name = self.resource.name[:-3] changes.add_change(CreateFolder(parent, name)) parent_path = parent.path + '/' if not parent.path: parent_path = '' new_path = parent_path + '%s/__init__.py' % name if self.resource.project == self.project: changes.add_change(MoveResource(self.resource, new_path)) return changes
def _calculate_changes(self, dest, resources, task_handle): changes = ChangeSet('Moving module <%s>' % self.old_name) job_set = task_handle.create_jobset('Collecting changes', len(resources)) for module in resources: job_set.started_job(module.path) if module == self.source: self._change_moving_module(changes, dest) else: source = self._change_occurrences_in_module(dest, resource=module) if source is not None: changes.add_change(ChangeContents(module, source)) job_set.finished_job() if self.project == self.source.project: changes.add_change(MoveResource(self.source, dest.path)) return changes