author | Germán Póo-Caamaño <gpoo@calcifer.org> |
Sun, 20 Jul 2008 09:43:33 -0400 | |
changeset 1181 | ab9654ce0550 |
parent 1148 | e30153694940 |
permissions | -rw-r--r-- |
157
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
1 |
# |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
2 |
# front-end for TortoiseHg dialogs |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
3 |
# |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
4 |
# Copyright (C) 2007 TK Soh <teekaysoh@gmail.com> |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
5 |
# |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
6 |
|
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
7 |
import os |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
8 |
import sys |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
9 |
from mercurial import ui |
1006 | 10 |
from tortoise.thgutil import get_prog_root |
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
11 |
|
413
fedc552d40c1
hgproc: always use our own hg exe
TK Soh <teekaysoh@yahoo.com>
parents:
412
diff
changeset
|
12 |
# always use hg exe installed with TortoiseHg |
417
977ce2ff9fd4
hgproc: portable path insertion code
Steve Borho <steve@borho.org>
parents:
413
diff
changeset
|
13 |
thgdir = get_prog_root() |
977ce2ff9fd4
hgproc: portable path insertion code
Steve Borho <steve@borho.org>
parents:
413
diff
changeset
|
14 |
try: |
977ce2ff9fd4
hgproc: portable path insertion code
Steve Borho <steve@borho.org>
parents:
413
diff
changeset
|
15 |
os.environ['PATH'] = os.path.pathsep.join([thgdir, os.environ['PATH']]) |
977ce2ff9fd4
hgproc: portable path insertion code
Steve Borho <steve@borho.org>
parents:
413
diff
changeset
|
16 |
except KeyError: |
977ce2ff9fd4
hgproc: portable path insertion code
Steve Borho <steve@borho.org>
parents:
413
diff
changeset
|
17 |
os.environ['PATH'] = thgdir |
413
fedc552d40c1
hgproc: always use our own hg exe
TK Soh <teekaysoh@yahoo.com>
parents:
412
diff
changeset
|
18 |
|
412
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
19 |
if not sys.stdin.isatty(): |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
20 |
try: |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
21 |
import win32traceutil |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
22 |
|
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
23 |
# FIXME: quick workaround traceback caused by missing "closed" |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
24 |
# attribute in win32trace. |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
25 |
from mercurial import ui |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
26 |
def write_err(self, *args): |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
27 |
for a in args: |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
28 |
sys.stderr.write(str(a)) |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
29 |
ui.ui.write_err = write_err |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
30 |
except ImportError: |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
31 |
pass |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
32 |
except pywintypes.error: |
a7fb2f5548fa
hgproc: do not redirect output if run from command line
TK Soh <teekaysoh@yahoo.com>
parents:
411
diff
changeset
|
33 |
pass |
279
7e4ceb3c0df8
hgproc: Safely catch win32traceutil import failure
Steve Borho <steve@borho.org>
parents:
258
diff
changeset
|
34 |
|
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
35 |
# Map hgproc commands to dialog modules in hggtk/ |
411
5dce1d702fd9
hgproc: import dialog modules so py2exe can pick them up
TK Soh <teekaysoh@yahoo.com>
parents:
410
diff
changeset
|
36 |
from hggtk import commit, status, addremove, tagadd, tags, history, merge |
422 | 37 |
from hggtk import diff, revisions, update, serve, clone, synch, hgcmd, about |
831
e6d57d498d29
hgproc: add datamine to dialog list
Steve Borho <steve@borho.org>
parents:
770
diff
changeset
|
38 |
from hggtk import recovery, thgconfig, datamine |
411
5dce1d702fd9
hgproc: import dialog modules so py2exe can pick them up
TK Soh <teekaysoh@yahoo.com>
parents:
410
diff
changeset
|
39 |
_dialogs = { 'commit' : commit, 'status' : status, 'revert' : status, |
5dce1d702fd9
hgproc: import dialog modules so py2exe can pick them up
TK Soh <teekaysoh@yahoo.com>
parents:
410
diff
changeset
|
40 |
'add' : addremove, 'remove' : addremove, 'tag' : tagadd, |
5dce1d702fd9
hgproc: import dialog modules so py2exe can pick them up
TK Soh <teekaysoh@yahoo.com>
parents:
410
diff
changeset
|
41 |
'tags' : tags, 'log' : history, 'history': history, |
5dce1d702fd9
hgproc: import dialog modules so py2exe can pick them up
TK Soh <teekaysoh@yahoo.com>
parents:
410
diff
changeset
|
42 |
'diff' : diff, 'merge' : merge, 'tip' : revisions, |
5dce1d702fd9
hgproc: import dialog modules so py2exe can pick them up
TK Soh <teekaysoh@yahoo.com>
parents:
410
diff
changeset
|
43 |
'parents': revisions, 'heads' : revisions, 'update' : update, |
422 | 44 |
'clone' : clone, 'serve' : serve, 'synch' : synch, |
831
e6d57d498d29
hgproc: add datamine to dialog list
Steve Borho <steve@borho.org>
parents:
770
diff
changeset
|
45 |
'about' : about, 'config' : thgconfig, 'recovery': recovery, |
949
fa59112eb06a
cmenu: add 'Annotate File' menu
TK Soh <teekaysoh@yahoo.com>
parents:
907
diff
changeset
|
46 |
'datamine': datamine } |
157
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
47 |
|
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
48 |
def get_list_from_file(filename): |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
49 |
fd = open(filename, "r") |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
50 |
lines = [ x.replace("\n", "") for x in fd.readlines() ] |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
51 |
fd.close() |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
52 |
return lines |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
53 |
|
157
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
54 |
def get_option(args): |
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
55 |
import getopt |
877
acc1a66acfc5
hgproc: add --nogui option, remove obsolete options
Steve Borho <steve@borho.org>
parents:
831
diff
changeset
|
56 |
long_opt_list = ('command=', 'exepath=', 'listfile=', 'root=', 'cwd=', |
acc1a66acfc5
hgproc: add --nogui option, remove obsolete options
Steve Borho <steve@borho.org>
parents:
831
diff
changeset
|
57 |
'deletelistfile', 'nogui') |
acc1a66acfc5
hgproc: add --nogui option, remove obsolete options
Steve Borho <steve@borho.org>
parents:
831
diff
changeset
|
58 |
opts, args = getopt.getopt(args, "c:e:l:dR:", long_opt_list) |
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
59 |
# Set default options |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
60 |
options = {} |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
61 |
options['hgcmd'] = 'help' |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
62 |
options['cwd'] = os.getcwd() |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
63 |
options['files'] = [] |
877
acc1a66acfc5
hgproc: add --nogui option, remove obsolete options
Steve Borho <steve@borho.org>
parents:
831
diff
changeset
|
64 |
options['gui'] = True |
406
4c73d42e0f73
hgproc: prevent deletion before listfile is read
Steve Borho <steve@borho.org>
parents:
401
diff
changeset
|
65 |
listfile = None |
4c73d42e0f73
hgproc: prevent deletion before listfile is read
Steve Borho <steve@borho.org>
parents:
401
diff
changeset
|
66 |
delfile = False |
157
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
67 |
|
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
68 |
for o, a in opts: |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
69 |
if o in ("-c", "--command"): |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
70 |
options['hgcmd'] = a |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
71 |
elif o in ("-l", "--listfile"): |
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
72 |
listfile = a |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
73 |
elif o in ("-d", "--deletelistfile"): |
406
4c73d42e0f73
hgproc: prevent deletion before listfile is read
Steve Borho <steve@borho.org>
parents:
401
diff
changeset
|
74 |
delfile = True |
877
acc1a66acfc5
hgproc: add --nogui option, remove obsolete options
Steve Borho <steve@borho.org>
parents:
831
diff
changeset
|
75 |
elif o in ("--nogui"): |
acc1a66acfc5
hgproc: add --nogui option, remove obsolete options
Steve Borho <steve@borho.org>
parents:
831
diff
changeset
|
76 |
options['gui'] = False |
157
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
77 |
elif o in ("-R", "--root"): |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
78 |
options['root'] = a |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
79 |
elif o in ("--cwd"): |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
80 |
options['cwd'] = a |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
81 |
|
406
4c73d42e0f73
hgproc: prevent deletion before listfile is read
Steve Borho <steve@borho.org>
parents:
401
diff
changeset
|
82 |
if listfile: |
4c73d42e0f73
hgproc: prevent deletion before listfile is read
Steve Borho <steve@borho.org>
parents:
401
diff
changeset
|
83 |
options['files'] = get_list_from_file(listfile) |
4c73d42e0f73
hgproc: prevent deletion before listfile is read
Steve Borho <steve@borho.org>
parents:
401
diff
changeset
|
84 |
if delfile: |
4c73d42e0f73
hgproc: prevent deletion before listfile is read
Steve Borho <steve@borho.org>
parents:
401
diff
changeset
|
85 |
os.unlink(listfile) |
4c73d42e0f73
hgproc: prevent deletion before listfile is read
Steve Borho <steve@borho.org>
parents:
401
diff
changeset
|
86 |
|
157
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
87 |
return (options, args) |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
88 |
|
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
89 |
def parse(args): |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
90 |
option, args = get_option(args) |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
91 |
|
877
acc1a66acfc5
hgproc: add --nogui option, remove obsolete options
Steve Borho <steve@borho.org>
parents:
831
diff
changeset
|
92 |
cmdline = ['hg', option['hgcmd']] |
770
bd7591a5fe6e
switch from 'dict.has_key(key)' to 'key in dict'
Steve Borho <steve@borho.org>
parents:
541
diff
changeset
|
93 |
if 'root' in option: |
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
94 |
cmdline.append('--repository') |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
95 |
cmdline.append(option['root']) |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
96 |
cmdline.extend(args) |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
97 |
cmdline.extend(option['files']) |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
98 |
option['cmdline'] = cmdline |
157
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
99 |
|
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
100 |
global _dialogs |
411
5dce1d702fd9
hgproc: import dialog modules so py2exe can pick them up
TK Soh <teekaysoh@yahoo.com>
parents:
410
diff
changeset
|
101 |
dialog = _dialogs.get(option['hgcmd'], hgcmd) |
5dce1d702fd9
hgproc: import dialog modules so py2exe can pick them up
TK Soh <teekaysoh@yahoo.com>
parents:
410
diff
changeset
|
102 |
dialog.run(**option) |
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
103 |
|
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
104 |
|
248
332bc04020ec
hgproc: add basic error handling
TK Soh <teekaysoh@yahoo.com>
parents:
237
diff
changeset
|
105 |
def run_trapped(args): |
332bc04020ec
hgproc: add basic error handling
TK Soh <teekaysoh@yahoo.com>
parents:
237
diff
changeset
|
106 |
try: |
332bc04020ec
hgproc: add basic error handling
TK Soh <teekaysoh@yahoo.com>
parents:
237
diff
changeset
|
107 |
dlg = parse(sys.argv[1:]) |
332bc04020ec
hgproc: add basic error handling
TK Soh <teekaysoh@yahoo.com>
parents:
237
diff
changeset
|
108 |
except: |
332bc04020ec
hgproc: add basic error handling
TK Soh <teekaysoh@yahoo.com>
parents:
237
diff
changeset
|
109 |
import traceback |
332bc04020ec
hgproc: add basic error handling
TK Soh <teekaysoh@yahoo.com>
parents:
237
diff
changeset
|
110 |
from hggtk.dialog import error_dialog |
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
111 |
tr = traceback.format_exc() |
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
112 |
print tr |
1148
e30153694940
hgproc: add missing param to error_dialog
TK Soh <teekaysoh@yahoo.com>
parents:
1006
diff
changeset
|
113 |
error_dialog(None, "Error executing hgproc", tr) |
248
332bc04020ec
hgproc: add basic error handling
TK Soh <teekaysoh@yahoo.com>
parents:
237
diff
changeset
|
114 |
|
157
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
115 |
if __name__=='__main__': |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
116 |
#dlg = parse(['-c', 'help', '--', '-v']) |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
117 |
#dlg = parse(['-c', 'log', '--root', 'c:\hg\h1', '--', '-l1']) |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
118 |
#dlg = parse(['-c', 'status', '--root', 'c:\hg\h1', ]) |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
119 |
#dlg = parse(['-c', 'add', '--root', 'c:\hg\h1', '--listfile', 'c:\\hg\\h1\\f1', '--notify']) |
b2d6126fa639
add hgproc module as dialog front-end
TK Soh <teekaysoh@yahoo.com>
parents:
diff
changeset
|
120 |
#dlg = parse(['-c', 'rollback', '--root', 'c:\\hg\\h1']) |
401
9ab309fbc25c
hggtk: gtk threads and hgproc cleanup
Steve Borho <steve@borho.org>
parents:
370
diff
changeset
|
121 |
print "hgproc sys.argv =", sys.argv |
248
332bc04020ec
hgproc: add basic error handling
TK Soh <teekaysoh@yahoo.com>
parents:
237
diff
changeset
|
122 |
dlg = run_trapped(sys.argv[1:]) |