Commits

ZyX_I committed a3b137c

@%aurum/drivers/subversion: Added rf-astatus()
python/repeatedcmd: Made paused processes use one second interval.

  • Participants
  • Parent commits 1dc9ed2

Comments (0)

Files changed (3)

autoload/aurum/drivers/subversion.vim

             \           'after “====<…>====” separator line',
             \ 'punimp': 'Cannot “pull” from non-default location',
             \'pulnimp': 'Cannot pull: use update instead',
+            \'aconimp': 'Can only get current status for one file',
         \}
 let s:svn={}
 let s:iterfuncs={}
                 \                                     a:opts.revrange[1]))
     return {'cslist': cslist, 'next': s:F.ancestorsnext}
 endfunction
+"▶1 astatus, agetcs, agetrepoprop
+if s:_r.repo.userepeatedcmd
+    try
+        python import aurum.rcdriverfuncs
+        let s:addafuncs=1
+    catch
+        let s:addafuncs=0
+    endtry
+    if s:addafuncs
+        function s:svn.astatus(repo, interval, ...)
+            if a:0<3 || a:1 isnot 0 || a:2 isnot 0 ||
+                        \type(a:3)!=type([]) || len(a:3)!=1
+                call s:_f.throw('aconimp')
+            endif
+            return pyeval('aurum.repeatedcmd.new('.string(a:interval).', '.
+                        \       'aurum.rcdriverfuncs.svn_status, '.
+                        \       'vim.eval("a:repo.path"), '.
+                        \       'vim.eval("a:3[0]"))')
+        endfunction
+    endif
+endif
 "▶1 Register driver
 call s:_f.regdriver('Subversion', s:svn)
 "▶1

python/aurum/rcdriverfuncs.py

 from aurum.utils import readlines
 from copy import deepcopy
 
-statchars={
+hgstatchars={
     'M': 'modified',
     'A': 'added',
     'R': 'removed',
 def hg_status(path, args, reverse=False):
     r=deepcopy(emptystatdct)
     for line in readlines(['hg']+args, cwd=path):
-        r[statchars[line[0]]].append(line[2:])
+        r[hgstatchars[line[0]]].append(line[2:])
     if reverse:
         r['deleted'], r['unknown'] = r['unknown'], r['deleted']
         r['added'],   r['removed'] = r['removed'], r['added']
             return line[2:]
     return ''
 
+svnstatchars=[
+    {
+        'C': 'modified',
+        'M': 'modified',
+        '~': 'modified',
+        'R': 'modified',
+        'A': 'added',
+        'D': 'removed',
+        '!': 'deleted',
+        '?': 'unknown',
+        'I': 'ignored',
+    },
+    {
+        'C': 'modified',
+        'M': 'modified',
+    },
+]
+def svn_status(path, fname):
+    r=deepcopy(emptystatdct)
+    try:
+        line=readlines(['svn', 'status', '--', fname]).next()
+        status=line[:7]
+        for schar, colschars in zip(status, svnstatchars):
+            if schar in colschars:
+                r[colschars[schar]].append(fname)
+                break
+    except StopIteration:
+        r['clean'].append(fname)
+    return r
+
 # vim: ft=python ts=4 sw=4 sts=4 et tw=100

python/aurum/repeatedcmd.py

 class ProcessHaltedError(Exception):
     pass
 
+notalive = 'Child process is not alive or is exiting'
+
 class RepeatedCmd(object):
     __slots__ = set(('interval', 'queue', 'qlock', 'vlock', 'func', 'process',
-                     'value', 'args', 'kwargs', 'paused'))
+                     'value', 'args', 'kwargs', 'paused', 'curinterval'))
     def __init__(self, interval, func, *args, **kwargs):
-        self.interval = Value('f', float(interval))
-        self.queue    = Queue()
-        self.vlock    = Lock()
-        self.qlock    = Lock()
-        self.func     = func
-        self.args     = args
-        self.kwargs   = kwargs
-        self.paused   = Value('b', 0)
+        self.curinterval = float(interval)
+        self.interval    = Value('f', self.curinterval)
+        self.queue       = Queue()
+        self.vlock       = Lock()
+        self.qlock       = Lock()
+        self.func        = func
+        self.args        = args
+        self.kwargs      = kwargs
+        self.paused      = Value('b', 0)
 
         def procfunc(queue, qlock, vlock, interval, func, args, kwargs):
             # Override default signal vim handler with system default behavior 
 
     def setinterval(self, interval):
         if not self.alive():
-            raise ProcessHaltedError('Child process is not alive')
-        self.interval.value = float(interval)
+            raise ProcessHaltedError(notalive)
+        self.curinterval    = float(interval)
+        self.interval.value = self.curinterval
 
     def getvalue(self):
         if not self.alive():
-            raise ProcessHaltedError('Child process is not alive')
+            raise ProcessHaltedError(notalive)
         self.qlock.acquire()
         if self.value is None or not self.queue.empty():
             while(not self.queue.empty()):
         return self.value
 
     def alive(self):
-        return self.process.is_alive()
+        return self.process.is_alive() and self.interval.value > 0
 
     def stop(self):
         if not self.alive():
-            raise ProcessHaltedError('Child process is not alive')
+            raise ProcessHaltedError(notalive)
         # For some reason process.terminate() sometimes may not seem to work. 
         # This is a workaround. Seems it is no longer needed with 
         # self.process.join(), just keeping it here for multiprocessing.
             pass
 
     def pause(self):
-        self.paused.value = 1
+        if not self.alive():
+            raise ProcessHaltedError(notalive)
+        if not self.paused.value:
+            self.paused.value   = 1
+            self.interval.value = 1.0
 
     def resume(self):
-        self.paused.value = 0
+        if not self.alive():
+            raise ProcessHaltedError(notalive)
+        if self.paused.value:
+            self.paused.value   = 0
+            self.interval.value = self.curinterval
 
     def __del__(self):
         if self.alive():