Anonymous avatar Anonymous committed b44cd49

fixmodnames: better task handle

Comments (0)

Files changed (1)

rope/contrib/fixmodnames.py

 
         """
         stack = changestack.ChangeStack(self.project, 'Fixing module names')
+        jobset = task_handle.create_jobset('Fixing module names',
+                                           self._count_fixes(fixer) + 1)
         try:
             while True:
-                for resource in self.project.pycore.get_python_files():
-                    modname = resource.name.rsplit('.', 1)[0]
-                    if modname == '__init__':
-                        modname = resource.parent.name
-                    if modname != fixer(modname):
-                        renamer = rename.Rename(self.project, resource)
-                        changes = renamer.get_changes(modname.lower(),
-                                                      task_handle=handle)
-                        stack.push(changes)
-                        break
+                for resource in self._tobe_fixed(fixer):
+                    jobset.started_job(resource.path)
+                    renamer = rename.Rename(self.project, resource)
+                    changes = renamer.get_changes(fixer(self._name(resource)))
+                    stack.push(changes)
+                    jobset.finished_job()
+                    break
                 else:
                     break
         finally:
+            jobset.started_job('Reverting to original state')
             stack.pop_all()
+            jobset.finished_job()
         return stack.merged()
+
+    def _count_fixes(self, fixer):
+        return len(list(self._tobe_fixed(fixer)))
+
+    def _tobe_fixed(self, fixer):
+        for resource in self.project.pycore.get_python_files():
+            modname = self._name(resource)
+            if modname != fixer(modname):
+                yield resource
+
+    def _name(self, resource):
+        modname = resource.name.rsplit('.', 1)[0]
+        if modname == '__init__':
+            modname = resource.parent.name
+        return modname
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.