PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tortoisehg/util/thgstatus.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 63 lines | 45 code | 11 blank | 7 comment | 15 complexity | 5424d2f7adac6287cc1648ca8c79c5e8 MD5 | raw file
 1# thgstatus.py - update TortoiseHg status cache
 2#
 3# Copyright 2009 Adrian Buehlmann
 4#
 5# This software may be used and distributed according to the terms of the
 6# GNU General Public License version 2, incorporated herein by reference.
 7
 8'''update TortoiseHg status cache'''
 9
10from mercurial import hg
11from tortoisehg.util import paths, shlib
12import os
13
14def cachefilepath(repo):
15    return repo.join("thgstatus")
16
17def run(_ui, *pats, **opts):
18
19    if opts.get('all'):
20        roots = []
21        base = os.getcwd()
22        for f in os.listdir(base):
23            r = paths.find_root(os.path.join(base, f))
24            if r is not None:
25                roots.append(r)
26        for r in roots:
27            _ui.note("%s\n" % r) 
28            shlib.update_thgstatus(_ui, r, wait=False)
29            shlib.shell_notify([r])
30        return
31
32    root = paths.find_root()
33    if opts.get('repository'):
34        root = opts.get('repository')
35    if root is None:
36        _ui.status("no repository\n")
37        return
38
39    repo = hg.repository(_ui, root)
40
41    if opts.get('remove'):
42        try:
43            os.remove(cachefilepath(repo))
44        except OSError:
45            pass
46        return
47
48    if opts.get('show'):
49        try:
50            f = open(cachefilepath(repo), 'rb')
51            for e in f:
52                _ui.status("%s %s\n" % (e[0], e[1:-1]))
53            f.close()
54        except IOError:
55            _ui.status("*no status*\n")
56        return
57
58    wait = opts.get('delay') is not None
59    shlib.update_thgstatus(_ui, root, wait=wait)
60
61    if opts.get('notify'):
62        shlib.shell_notify(opts.get('notify'))
63    _ui.note("thgstatus updated\n")