author | Steve Borho <steve@borho.org> |
Sun, 16 Dec 2007 09:54:43 -0600 | |
changeset 397 | 517f7511f496 |
parent 395 | 46c87c1ecc2b |
child 401 | 9ab309fbc25c |
permissions | -rw-r--r-- |
291 | 1 |
# |
397
517f7511f496
hggtk: fix comment at top of clone.py
Steve Borho <steve@borho.org>
parents:
395
diff
changeset
|
2 |
# TortoiseHg dialog to clone a repo |
291 | 3 |
# |
4 |
# Copyright (C) 2007 TK Soh <teekaysoh@gmail.com> |
|
5 |
# |
|
6 |
||
7 |
try: |
|
8 |
import pygtk |
|
9 |
pygtk.require("2.0") |
|
10 |
except: |
|
11 |
pass |
|
12 |
||
13 |
import os |
|
14 |
import sys |
|
15 |
import gtk |
|
16 |
from dialog import question_dialog, error_dialog, info_dialog |
|
17 |
from mercurial import hg, ui, cmdutil, util |
|
18 |
from mercurial.i18n import _ |
|
19 |
from mercurial.node import * |
|
20 |
||
21 |
class CloneDialog(gtk.Dialog): |
|
22 |
""" Dialog to add tag to Mercurial repo """ |
|
299
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
23 |
def __init__(self, cwd='', repos=[]): |
291 | 24 |
""" Initialize the Dialog """ |
25 |
buttons = (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) |
|
26 |
super(CloneDialog, self).__init__(flags=gtk.DIALOG_MODAL, |
|
27 |
buttons=buttons) |
|
28 |
||
29 |
if cwd: os.chdir(cwd) |
|
30 |
||
31 |
# set dialog title |
|
32 |
title = "hg clone " |
|
33 |
title += " - %s" % (os.getcwd()) |
|
34 |
self.set_title(title) |
|
35 |
||
299
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
36 |
self._src_path = '' |
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
37 |
self._dest_path = '' |
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
38 |
|
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
39 |
try: |
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
40 |
self._src_path = repos[0] |
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
41 |
self._dest_path = repos[1] |
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
42 |
except: |
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
43 |
pass |
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
44 |
|
291 | 45 |
# build dialog |
46 |
self._create() |
|
47 |
||
48 |
def _create(self): |
|
49 |
self.set_default_size(400, 180) |
|
50 |
ewidth = 16 |
|
51 |
||
52 |
# clone source |
|
53 |
srcbox = gtk.HBox() |
|
54 |
lbl = gtk.Label("Source Path:") |
|
55 |
lbl.set_property("width-chars", ewidth) |
|
56 |
lbl.set_alignment(0, 0.5) |
|
57 |
self._src_input = gtk.Entry() |
|
299
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
58 |
self._src_input.set_text(self._src_path) |
291 | 59 |
self._btn_src_browse = gtk.Button("Browse...") |
60 |
self._btn_src_browse.connect('clicked', self._btn_src_clicked) |
|
61 |
srcbox.pack_start(lbl, False, False) |
|
62 |
srcbox.pack_start(self._src_input, True, True) |
|
63 |
srcbox.pack_end(self._btn_src_browse, False, False, 5) |
|
64 |
self.vbox.pack_start(srcbox, False, False, 2) |
|
299
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
65 |
|
291 | 66 |
|
67 |
# clone destination |
|
68 |
destbox = gtk.HBox() |
|
69 |
lbl = gtk.Label("Destination Path:") |
|
70 |
lbl.set_property("width-chars", ewidth) |
|
71 |
lbl.set_alignment(0, 0.5) |
|
72 |
self._dest_input = gtk.Entry() |
|
299
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
73 |
self._dest_input.set_text(self._dest_path) |
291 | 74 |
self._btn_dest_browse = gtk.Button("Browse...") |
75 |
self._btn_dest_browse.connect('clicked', self._btn_dest_clicked) |
|
76 |
destbox.pack_start(lbl, False, False) |
|
77 |
destbox.pack_start(self._dest_input, True, True) |
|
78 |
destbox.pack_end(self._btn_dest_browse, False, False, 5) |
|
79 |
self.vbox.pack_start(destbox, False, False, 2) |
|
80 |
||
81 |
# revision input |
|
82 |
revbox = gtk.HBox() |
|
303
8107174c1d1e
hggtk/clone: rev option is for cloning instead of updating
TK Soh <teekaysoh@yahoo.com>
parents:
299
diff
changeset
|
83 |
lbl = gtk.Label("Clone To Revision:") |
291 | 84 |
lbl.set_property("width-chars", ewidth) |
85 |
lbl.set_alignment(0, 0.5) |
|
86 |
self._rev_input = gtk.Entry() |
|
303
8107174c1d1e
hggtk/clone: rev option is for cloning instead of updating
TK Soh <teekaysoh@yahoo.com>
parents:
299
diff
changeset
|
87 |
self._rev_input.set_text("") |
304
6a49f3883031
hggtk/clone: add checkbox for cloning all revisions
TK Soh <teekaysoh@yahoo.com>
parents:
303
diff
changeset
|
88 |
self._opt_allrev = gtk.CheckButton("Clone all revisions") |
6a49f3883031
hggtk/clone: add checkbox for cloning all revisions
TK Soh <teekaysoh@yahoo.com>
parents:
303
diff
changeset
|
89 |
self._opt_allrev.set_active(True) |
291 | 90 |
self._btn_rev_browse = gtk.Button("Select...") |
91 |
self._btn_rev_browse.connect('clicked', self._btn_rev_clicked) |
|
92 |
revbox.pack_start(lbl, False, False) |
|
93 |
revbox.pack_start(self._rev_input, False, False) |
|
94 |
#revbox.pack_start(self._btn_rev_browse, False, False, 5) |
|
304
6a49f3883031
hggtk/clone: add checkbox for cloning all revisions
TK Soh <teekaysoh@yahoo.com>
parents:
303
diff
changeset
|
95 |
revbox.pack_start(self._opt_allrev, False, False) |
291 | 96 |
self.vbox.pack_start(revbox, False, False, 2) |
97 |
||
98 |
# options |
|
99 |
option_box = gtk.VBox() |
|
100 |
self._opt_update = gtk.CheckButton("do not update the new working directory") |
|
101 |
self._opt_pull = gtk.CheckButton("use pull protocol to copy metadata") |
|
102 |
self._opt_uncomp = gtk.CheckButton("use uncompressed transfer") |
|
103 |
option_box.pack_start(self._opt_update, False, False) |
|
104 |
option_box.pack_start(self._opt_pull, False, False) |
|
105 |
option_box.pack_start(self._opt_uncomp, False, False) |
|
106 |
self.vbox.pack_start(option_box, False, False, 15) |
|
107 |
||
108 |
# remote cmd |
|
109 |
lbl = gtk.Label("Remote Cmd:") |
|
110 |
lbl.set_alignment(0, 0.5) |
|
111 |
self._remote_cmd = gtk.Entry() |
|
112 |
self.vbox.pack_end(self._remote_cmd, False, False, 1) |
|
113 |
self.vbox.pack_end(lbl, False, False, 1) |
|
114 |
||
115 |
# add action buttn |
|
116 |
self._btn_clone = gtk.Button("Clone") |
|
117 |
self._btn_clone.connect('clicked', self._btn_clone_clicked) |
|
118 |
self.action_area.pack_end(self._btn_clone) |
|
119 |
||
120 |
# show them all |
|
121 |
self.vbox.show_all() |
|
122 |
||
123 |
def _btn_dest_clicked(self, button): |
|
124 |
""" select folder as clone destination """ |
|
125 |
dialog = gtk.FileChooserDialog(title=None, |
|
126 |
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, |
|
127 |
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, |
|
128 |
gtk.STOCK_OPEN,gtk.RESPONSE_OK)) |
|
129 |
dialog.set_default_response(gtk.RESPONSE_OK) |
|
130 |
response = dialog.run() |
|
131 |
if response == gtk.RESPONSE_OK: |
|
132 |
self._dest_input.set_text(dialog.get_filename()) |
|
133 |
dialog.destroy() |
|
134 |
||
135 |
def _btn_src_clicked(self, button): |
|
136 |
""" select source folder to clone """ |
|
137 |
dialog = gtk.FileChooserDialog(title=None, |
|
138 |
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, |
|
139 |
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, |
|
140 |
gtk.STOCK_OPEN,gtk.RESPONSE_OK)) |
|
141 |
dialog.set_default_response(gtk.RESPONSE_OK) |
|
142 |
response = dialog.run() |
|
143 |
if response == gtk.RESPONSE_OK: |
|
144 |
self._src_input.set_text(dialog.get_filename()) |
|
145 |
dialog.destroy() |
|
146 |
||
147 |
def _btn_rev_clicked(self, button): |
|
148 |
""" select revision from history dialog """ |
|
392
21df78721916
hggtk: copy history select code to new file
Steve Borho <steve@borho.org>
parents:
304
diff
changeset
|
149 |
import histselect |
21df78721916
hggtk: copy history select code to new file
Steve Borho <steve@borho.org>
parents:
304
diff
changeset
|
150 |
rev = histselect.select(self.root) |
291 | 151 |
if rev is not None: |
152 |
self._rev_input.set_text(rev) |
|
153 |
||
154 |
def _btn_clone_clicked(self, button): |
|
155 |
# gather input data |
|
156 |
src = self._src_input.get_text() |
|
157 |
dest = self._dest_input.get_text() |
|
158 |
remotecmd = self._remote_cmd.get_text() |
|
159 |
rev = self._rev_input.get_text() |
|
304
6a49f3883031
hggtk/clone: add checkbox for cloning all revisions
TK Soh <teekaysoh@yahoo.com>
parents:
303
diff
changeset
|
160 |
|
291 | 161 |
# verify input |
162 |
if src == "": |
|
163 |
error_dialog("Source path is empty", "Please enter") |
|
164 |
self._src_input.grab_focus() |
|
165 |
return False |
|
166 |
||
167 |
# start cloning |
|
168 |
try: |
|
169 |
cmdline = 'hg clone' |
|
170 |
if self._opt_update.get_active(): |
|
171 |
cmdline += ' --noupdate' |
|
172 |
if self._opt_uncomp.get_active(): |
|
173 |
cmdline += ' --uncompressed' |
|
174 |
if self._opt_pull.get_active(): |
|
175 |
cmdline += ' --pull' |
|
176 |
if remotecmd: |
|
177 |
cmdline += ' --remotecmd %s' % util.shellquote(remotecmd) |
|
304
6a49f3883031
hggtk/clone: add checkbox for cloning all revisions
TK Soh <teekaysoh@yahoo.com>
parents:
303
diff
changeset
|
178 |
if not self._opt_allrev.get_active() and rev: |
291 | 179 |
cmdline += ' --rev %s' % rev |
180 |
||
181 |
cmdline += ' --verbose' |
|
182 |
cmdline += ' %s' % util.shellquote(src) |
|
183 |
if dest: |
|
184 |
cmdline += ' %s' % util.shellquote(dest) |
|
185 |
print "cmdline: ", cmdline |
|
395
46c87c1ecc2b
hggtk: rename cmd.py to hgcmd.py
Steve Borho <steve@borho.org>
parents:
392
diff
changeset
|
186 |
import hgcmd |
46c87c1ecc2b
hggtk: rename cmd.py to hgcmd.py
Steve Borho <steve@borho.org>
parents:
392
diff
changeset
|
187 |
hgcmd.run(cmdline) |
291 | 188 |
except util.Abort, inst: |
189 |
error_dialog("Clone aborted", str(inst)) |
|
190 |
return False |
|
191 |
except: |
|
192 |
import traceback |
|
193 |
error_dialog("Clone error", traceback.format_exc()) |
|
194 |
return False |
|
195 |
||
299
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
196 |
def run(cwd='', repos=[]): |
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
197 |
dialog = CloneDialog(cwd, repos) |
291 | 198 |
dialog.run() |
199 |
||
200 |
if __name__ == "__main__": |
|
201 |
import sys |
|
299
f9ca63c50859
hggtk/clone: accept src and dest paths from command line
TK Soh <teekaysoh@yahoo.com>
parents:
298
diff
changeset
|
202 |
run(os.getcwd(), sys.argv[1:]) |