Commits

Anonymous committed 38e6e11

refactor: moved runtask() to refactor

Comments (0)

Files changed (3)

ropemacs/__init__.py

 """ropemacs, an emacs mode for using rope refactoring library"""
 from Pymacs import lisp
-from rope.base import taskhandle, utils
+from rope.base import utils
 
+import ropemode.decorators
 import ropemode.dialog
 import ropemode.interface
-import ropemode.decorators
 
 
 class LispUtils(object):
     def _emacs_version(self):
         return int(lisp['emacs-version'].value().split('.')[0])
 
-    def runtask(self, command, name, interrupts=True):
-        return RunTask(command, name, interrupts)()
-
     def create_progress(self, name):
         if lisp.fboundp(lisp['make-progress-reporter']):
             progress = _LispProgress(name)
         message('%s ... done' % self.name)
 
 
-class RunTask(object):
-
-    def __init__(self, task, name, interrupts=True):
-        self.task = task
-        self.name = name
-        self.interrupts = interrupts
-
-    def __call__(self):
-        handle = taskhandle.TaskHandle(name=self.name)
-        progress = LispUtils().create_progress(self.name)
-        def update_progress():
-            jobset = handle.current_jobset()
-            if jobset:
-                percent = jobset.get_percent_done()
-                if percent is not None:
-                    progress.update(percent)
-        handle.add_observer(update_progress)
-        result = self.task(handle)
-        progress.done()
-        return result
-
-
 def occurrences_goto_occurrence():
     start = lisp.line_beginning_position()
     end = lisp.line_end_position()

ropemode/interface.py

             def undo(handle):
                 for changes in self.project.history.undo(task_handle=handle):
                     self._reload_buffers(changes, undo=True)
-            self.env.runtask(undo, 'Undo refactoring', interrupts=False)
+            refactor.runtask(self.env, undo, 'Undo refactoring',
+                             interrupts=False)
 
     @decorators.global_command('r')
     def redo(self):
             def redo(handle):
                 for changes in self.project.history.redo(task_handle=handle):
                     self._reload_buffers(changes)
-            self.env.runtask(redo, 'Redo refactoring', interrupts=False)
+            refactor.runtask(self.env, redo, 'Redo refactoring',
+                             interrupts=False)
 
     @decorators.local_command('a g', shortcut='C-c g')
     def goto_definition(self):
                                                 values.get('resources'))
                 return do_find(self.project, resource, offset,
                                resources=resources, task_handle=handle, **kwds)
-            result = self.env.runtask(calculate, 'Find Occurrences')
+            result = refactor.runtask(self.env, calculate, 'Find Occurrences')
             locations = []
             for occurrence in result:
                 note = ''
         def generate(handle):
             self.autoimport.generate_cache(task_handle=handle)
             self.autoimport.generate_modules_cache(modules, task_handle=handle)
-        self.env.runtask(generate, 'Generate autoimport cache')
+        refactor.runtask(self.env, generate, 'Generate autoimport cache')
 
     @decorators.global_command('f', 'P')
     def find_file(self, prefix):
         self._check_project()
         def _analyze_modules(handle):
             libutils.analyze_modules(self.project, task_handle=handle)
-        self.env.runtask(_analyze_modules, 'Analyze project modules')
+        refactor.runtask(self.env, _analyze_modules, 'Analyze project modules')
 
     def _create(self, name, callback, parentname='source'):
         self._check_project()

ropemode/refactor.py

 import rope.refactor.rename
 import rope.refactor.restructure
 import rope.refactor.usefunction
+from rope.base import taskhandle
 
 from ropemode import dialog, filter
 
         def calculate(handle):
             return self._calculate_changes(result, handle)
         name = 'Calculating %s changes' % self.name
-        changes = self.env.runtask(calculate, name=name)
+        changes = runtask(self.env, calculate, name=name)
         if action == 'perform':
             self._perform(changes)
         if action == 'preview':
             self.project.do(changes, task_handle=handle)
             self.interface._reload_buffers(changes)
             self._done()
-        self.env.runtask(perform, 'Making %s changes' % self.name,
-                          interrupts=False)
+        runtask(self.env, perform, 'Making %s changes' % self.name,
+                interrupts=False)
         self.env.message(str(changes.description) + ' finished')
 
     def _get_confs(self):
     if text is None or text.strip() == '':
         return None
     return filter.resources(project, text)
+
+
+def runtask(env, command, name, interrupts=True):
+    return RunTask(env, command, name, interrupts)()
+
+class RunTask(object):
+
+    def __init__(self, env, task, name, interrupts=True):
+        self.env = env
+        self.task = task
+        self.name = name
+        self.interrupts = interrupts
+
+    def __call__(self):
+        handle = taskhandle.TaskHandle(name=self.name)
+        progress = self.env.create_progress(self.name)
+        def update_progress():
+            jobset = handle.current_jobset()
+            if jobset:
+                percent = jobset.get_percent_done()
+                if percent is not None:
+                    progress.update(percent)
+        handle.add_observer(update_progress)
+        result = self.task(handle)
+        progress.done()
+        return result
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.