/tortoisehg/util/thgstatus.py

https://bitbucket.org/tortoisehg/hgtk/ · Python · 63 lines · 45 code · 11 blank · 7 comment · 14 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. '''update TortoiseHg status cache'''
  8. from mercurial import hg
  9. from tortoisehg.util import paths, shlib
  10. import os
  11. def cachefilepath(repo):
  12. return repo.join("thgstatus")
  13. def run(_ui, *pats, **opts):
  14. if opts.get('all'):
  15. roots = []
  16. base = os.getcwd()
  17. for f in os.listdir(base):
  18. r = paths.find_root(os.path.join(base, f))
  19. if r is not None:
  20. roots.append(r)
  21. for r in roots:
  22. _ui.note("%s\n" % r)
  23. shlib.update_thgstatus(_ui, r, wait=False)
  24. shlib.shell_notify([r])
  25. return
  26. root = paths.find_root()
  27. if opts.get('repository'):
  28. root = opts.get('repository')
  29. if root is None:
  30. _ui.status("no repository\n")
  31. return
  32. repo = hg.repository(_ui, root)
  33. if opts.get('remove'):
  34. try:
  35. os.remove(cachefilepath(repo))
  36. except OSError:
  37. pass
  38. return
  39. if opts.get('show'):
  40. try:
  41. f = open(cachefilepath(repo), 'rb')
  42. for e in f:
  43. _ui.status("%s %s\n" % (e[0], e[1:-1]))
  44. f.close()
  45. except IOError:
  46. _ui.status("*no status*\n")
  47. return
  48. wait = opts.get('delay') is not None
  49. shlib.update_thgstatus(_ui, root, wait=wait)
  50. if opts.get('notify'):
  51. shlib.shell_notify(opts.get('notify'))
  52. _ui.note("thgstatus updated\n")