Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.4, 2.0.5, and 2.1

stable setup, hgqt: build Qt translation resource and load it if frozen

It switches QTranslator's load path to :/translations if frozen.
And add 'setup.py build_qt --frozen' option to build translation resource.

Changeset 9ccf60504e07

Parent e44f6f508a07

by Yuya Nishihara

Changes to 4 files · Browse files at 9ccf60504e07 Showing diff from parent e44f6f508a07 Diff from another changeset...

Change 1 of 3 Show Entire File setup.py Stacked
 
13
14
15
 
 
16
17
18
 
110
111
112
113
114
 
 
 
115
116
117
 
118
119
120
 
186
187
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
190
191
192
193
194
 
 
195
196
197
 
13
14
15
16
17
18
19
20
 
112
113
114
 
 
115
116
117
118
119
120
121
122
123
124
 
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
@@ -13,6 +13,8 @@
 import shutil  import subprocess  import cgi +import tempfile +import re  from fnmatch import fnmatch  from distutils import log  from distutils.core import setup, Command @@ -110,11 +112,13 @@
 class build_qt(Command):   description = "build PyQt GUIs (.ui) and resources (.qrc)"   user_options = [('force', 'f', 'forcibly compile everything' - ' (ignore file timestamps)')] - boolean_options = ('force',) + ' (ignore file timestamps)'), + ('frozen', None, 'include resources for frozen exe')] + boolean_options = ('force', 'frozen')     def initialize_options(self):   self.force = None + self.frozen = False     def finalize_options(self):   self.set_undefined_options('build', ('force', 'force')) @@ -186,12 +190,33 @@
  finally:   os.unlink(qrc_file)   + def _build_translations(self, basepath): + """Build translations_rc.py which inclues qt_xx.qm""" + from PyQt4.QtCore import QLibraryInfo + trpath = unicode(QLibraryInfo.location(QLibraryInfo.TranslationsPath)) + d = tempfile.mkdtemp() + try: + for e in os.listdir(trpath): + if re.match(r'qt_[a-z]{2}(_[A-Z]{2})?\.ts$', e): + r = os.system('lrelease "%s" -qm "%s"' + % (os.path.join(trpath, e), + os.path.join(d, e[:-3] + '.qm'))) + if r > 0: + self.warn('Unable to generate Qt message file' + ' from %s' % e) + self.build_rc(os.path.join(basepath, 'translations_rc.py'), + d, '/translations') + finally: + shutil.rmtree(d) +   def run(self):   self._wrapuic()   basepath = join(os.path.dirname(__file__), 'tortoisehg', 'hgqt')   self.build_rc(os.path.join(basepath, 'icons_rc.py'),   os.path.join(os.path.dirname(__file__), 'icons'),   '/icons') + if self.frozen: + self._build_translations(basepath)   for dirpath, _, filenames in os.walk(basepath):   for filename in filenames:   if filename.endswith('.ui'):
Change 1 of 1 Show Changes Only thg Stacked
1
2
3
4
5
6
7
8
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
37
38
39
40
41
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
1
2
3
4
5
6
7
8
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
37
38
39
40
41
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 #!/usr/bin/env python  #  # thg - front-end script for TortoiseHg dialogs  #  # Copyright (C) 2008-2011 Steve Borho <steve@borho.org>  # Copyright (C) 2008 TK Soh <teekaysoh@gmail.com>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    import os  import sys    if hasattr(sys, "frozen"):   if sys.frozen == 'windows_exe' and 'THGDEBUG' in os.environ:   import win32traceutil   print 'starting'   # os.Popen() needs this, and Mercurial still uses os.Popen   if 'COMSPEC' not in os.environ:   comspec = os.path.join(os.environ.get('SystemRoot', r'C:\Windows'),   'system32', 'cmd.exe')   os.environ['COMSPEC'] = comspec  else:   thgpath = os.path.dirname(os.path.realpath(__file__))   testpath = os.path.join(thgpath, 'tortoisehg')   if os.path.isdir(testpath) and thgpath not in sys.path:   sys.path.insert(0, thgpath)     # compile .ui and .qrc for in-place use   fpath = os.path.realpath(__file__)   if os.path.exists(os.path.join(os.path.dirname(fpath), 'setup.py')):   from distutils.dist import Distribution   from setup import build_qt   build_qt(Distribution()).run()     if 'HGPATH' in os.environ:   hgpath = os.environ['HGPATH']   testpath = os.path.join(hgpath, 'mercurial')   if os.path.isdir(testpath) and hgpath not in sys.path:   sys.path.insert(0, hgpath)    from mercurial import demandimport  demandimport.ignore.append('win32com.shell')  demandimport.ignore.append('tortoisehg.util.config')  demandimport.ignore.append('icons_rc') +demandimport.ignore.append('translations_rc')  demandimport.enable()  from mercurial import ui as uimod, util  from tortoisehg.util.hgversion import hgversion, checkhgversion  import cStringIO  import traceback    try:   import tortoisehg.hgqt.run  except ImportError, e:   sys.stderr.write(str(e)+'\n')   sys.stderr.write("abort: couldn't find tortoisehg libraries in [%s]\n" %   os.pathsep.join(sys.path))   sys.stderr.write("(check your install and PYTHONPATH)\n")   sys.exit(-1)    ui = uimod.ui()  capt = ui.configbool('tortoisehg', 'stderrcapt', True)    errors = ('Traceback', 'TypeError', 'NameError', 'AttributeError',   'NotImplementedError')    err = checkhgversion(hgversion)  if err:   from tortoisehg.hgqt.bugreport import run   from tortoisehg.hgqt.run import qtrun   opts = {}   opts['cmd'] = ' '.join(sys.argv[1:])   opts['error'] = '\n' + err + '\n'   opts['nofork'] = True   qtrun(run, ui, **opts)   sys.exit(1)    if not capt or 'THGDEBUG' in os.environ or '--profile' in sys.argv:   sys.exit(tortoisehg.hgqt.run.dispatch(sys.argv[1:]))  else:   mystderr = cStringIO.StringIO()   origstderr = sys.stderr   sys.stderr = mystderr   ret = 0   try:   ret = tortoisehg.hgqt.run.dispatch(sys.argv[1:])   sys.stderr = origstderr   mystderr.seek(0)   for l in mystderr.readlines():   if l.startswith(errors):   from tortoisehg.hgqt.bugreport import run   from tortoisehg.hgqt.run import qtrun   error = 'Recoverable runtime error (stderr):\n'   error += mystderr.getvalue()   opts = {}   opts['cmd'] = ' '.join(sys.argv[1:])   opts['error'] = error   opts['nofork'] = True   qtrun(run, ui, **opts)   break   sys.exit(ret)   except:   if sys.exc_info()[0] not in [SystemExit, KeyboardInterrupt]:   sys.stderr = origstderr   traceback.print_exc()   else:   raise SystemExit(ret)
 
1
2
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
@@ -1,2 +1,8 @@
 # load icon resources  import icons_rc + +# load Qt translations for frozen environment +try: + import translations_rc +except ImportError: + pass
 
394
395
396
397
 
 
 
 
398
399
400
 
394
395
396
 
397
398
399
400
401
402
403
@@ -394,7 +394,10 @@
   def gettranslationpath():   """Return path to Qt's translation file (.qm)""" - return QLibraryInfo.location(QLibraryInfo.TranslationsPath) + if getattr(sys, 'frozen', False): + return ':/translations' + else: + return QLibraryInfo.location(QLibraryInfo.TranslationsPath)    def CommonMsgBox(icon, title, main, text='', buttons=QMessageBox.Ok,   labels=[], parent=None, defaultbutton=None):