Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

nautilus: allow nautilus-thg.py to be symlinked

Changeset d34966f48492

Parent 07af2dd1e6dd

by Steve Borho

Changes to one file · Browse files at d34966f48492 Showing diff from parent 07af2dd1e6dd Diff from another changeset...

 
9
10
11
12
13
14
15
16
17
 
18
19
20
21
22
23
24
25
26
 
 
 
 
 
 
 
 
27
28
29
 
30
31
32
 
38
39
40
41
42
43
44
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
47
48
 
116
117
118
119
 
120
121
122
 
209
210
211
212
 
213
214
215
 
256
257
258
259
 
260
261
262
263
264
 
265
266
267
 
9
10
11
 
12
13
 
 
 
14
15
 
16
17
18
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
42
43
44
 
 
 
 
 
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
145
146
147
 
148
149
150
151
 
238
239
240
 
241
242
243
244
 
285
286
287
 
288
289
290
291
292
 
293
294
295
296
@@ -9,24 +9,28 @@
 #  # Published under the GNU GPL   -import gconf  import gtk  import gobject -from mercurial import hg, ui, match, util -from mercurial.node import short -import tortoise.menuthg +import os  import nautilus -import os  import subprocess  import sys  import tempfile -import time  import urllib    try: + from mercurial import hg, ui, match, util +except ImportError: + # workaround to use user's local python libs + userlib = os.path.expanduser('~/lib/python') + if os.path.exists(userlib) and userlib not in sys.path: + sys.path.append(userlib) + from mercurial import hg, ui, match, util +try:   from mercurial.error import RepoError  except ImportError:   from mercurial.repo import RepoError +from mercurial.node import short    TORTOISEHG_PATH = '~/tools/tortoisehg-dev'   @@ -38,11 +42,36 @@
  def __init__(self):   self.cacherepo = None   self.cacheroot = None - self.client = gconf.client_get_default() - thgpath = os.environ.get('TORTOISEHG_PATH', - os.path.expanduser(TORTOISEHG_PATH)) - os.environ['TORTOISEHG_PATH'] = thgpath - os.environ['THG_ICON_PATH'] = os.path.join(thgpath, 'icons') + + # check if nautilus-thg.py is a symlink first + pfile = __file__ + if pfile.endswith('.pyc'): + pfile = pfile[:-1] + path = os.path.dirname(os.path.realpath(pfile)) + thgpath = os.path.normpath(os.path.join(path, '..')) + testpath = os.path.join(thgpath, 'tortoise') + if os.path.isdir(testpath): + if thgpath not in sys.path: + sys.path.append(thgpath) + else: + # try environment or hard-coded path + thgpath = os.environ.get('TORTOISEHG_PATH', TORTOISEHG_PATH) + thgpath = os.path.normpath(os.path.expanduser(thgpath)) + if os.path.exists(thgpath) and thgpath not in sys.path: + sys.path.insert(0, thgpath) + # else assume tortoise is already in PYTHONPATH + try: + import tortoise.menuthg + except ImportError: + print 'unable to import tortoise.menuthg' + self.menu = None + return + + self.env = os.environ + self.env['PYTHONPATH'] = ':'.join(sys.path) + self.env['TORTOISEHG_PATH'] = thgpath + self.env['THG_ICON_PATH'] = os.path.join(thgpath, 'icons') +   self.hgproc = os.path.join(thgpath, 'hgproc.py')   self.ipath = os.path.join(thgpath, 'icons', 'tortoise')   self.menu = tortoise.menuthg.menuThg() @@ -116,7 +145,7 @@
  cmdline = ['hg', diffcmd]   cwd = os.path.isdir(path) and path or os.path.dirname(path)   paths = [self.get_path_for_vfs_file(f) for f in vfs_files] - subprocess.Popen(cmdline + paths, shell=False, cwd=cwd) + subprocess.Popen(cmdline+paths, shell=False, env=self.env, cwd=cwd)     def _history(self, window, info):   self._run_dialog('history') @@ -209,7 +238,7 @@
  cmdopts += ['--listfile', tmpfile, '--deletelistfile']   cmdopts.extend(extras)   - subprocess.Popen(cmdopts, cwd=cwd, shell=False) + subprocess.Popen(cmdopts, cwd=cwd, env=self.env, shell=False)     # Remove cached repo object, dirstate may change   self.cacherepo = None @@ -256,12 +285,12 @@
    def get_background_items(self, window, vfs_file):   '''Build context menu for current directory''' - if vfs_file: + if vfs_file and self.menu:   return self.buildMenu(self.menu.get_commands, [vfs_file])     def get_file_items(self, window, vfs_files):   '''Build context menu for selected files/directories''' - if vfs_files: + if vfs_files and self.menu:   return self.buildMenu(self.menu.get_commands, vfs_files)     def get_columns(self):