|
1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2004 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 # This is the install script for eric4's translation files. |
|
7 |
|
8 """ |
|
9 Installation script for the eric4 IDE translation files. |
|
10 """ |
|
11 |
|
12 import sys |
|
13 import os |
|
14 import shutil |
|
15 import glob |
|
16 |
|
17 from PyQt4.QtCore import QDir |
|
18 |
|
19 try: |
|
20 from eric4config import getConfig |
|
21 except ImportError: |
|
22 print "The eric4 IDE doesn't seem to be installed. Aborting." |
|
23 sys.exit(1) |
|
24 |
|
25 def getConfigDir(): |
|
26 """ |
|
27 Global function to get the name of the directory storing the config data. |
|
28 |
|
29 @return directory name of the config dir (string) |
|
30 """ |
|
31 if sys.platform.startswith("win"): |
|
32 cdn = "_eric5" |
|
33 else: |
|
34 cdn = ".eric5" |
|
35 |
|
36 hp = QDir.homePath() |
|
37 dn = QDir(hp) |
|
38 dn.mkdir(cdn) |
|
39 hp.append("/").append(cdn) |
|
40 try: |
|
41 return unicode(QDir.toNativeSeparators(hp)) |
|
42 except AttributeError: |
|
43 return unicode(QDir.convertSeparators(hp)) |
|
44 |
|
45 # Define the globals. |
|
46 progName = None |
|
47 configDir = getConfigDir() |
|
48 privateInstall = False |
|
49 |
|
50 def usage(rcode = 2): |
|
51 """ |
|
52 Display a usage message and exit. |
|
53 |
|
54 @param rcode return code passed back to the calling process (integer) |
|
55 """ |
|
56 global progName, configDir |
|
57 |
|
58 print |
|
59 print "Usage:" |
|
60 print " %s [-hp]" % (progName) |
|
61 print "where:" |
|
62 print " -h display this help message" |
|
63 print " -p install into the private area (%s)" % (configDir) |
|
64 |
|
65 sys.exit(rcode) |
|
66 |
|
67 def installTranslations(): |
|
68 """ |
|
69 Install the translation files into the right place. |
|
70 """ |
|
71 global privateInstall, configDir |
|
72 |
|
73 if privateInstall: |
|
74 targetDir = configDir |
|
75 else: |
|
76 targetDir = getConfig('ericDir') |
|
77 |
|
78 try: |
|
79 for fn in glob.glob(os.path.join('eric', 'i18n', '*.qm')): |
|
80 shutil.copy2(fn, targetDir) |
|
81 except IOError, msg: |
|
82 sys.stderr.write('IOError: %s\nTry install-i18n as root.\n' % msg) |
|
83 |
|
84 def main(argv): |
|
85 """ |
|
86 The main function of the script. |
|
87 |
|
88 @param argv list of command line arguments (list of strings) |
|
89 """ |
|
90 import getopt |
|
91 |
|
92 # Parse the command line. |
|
93 global progName, privateInstall |
|
94 progName = os.path.basename(argv[0]) |
|
95 |
|
96 try: |
|
97 optlist, args = getopt.getopt(argv[1:],"hp") |
|
98 except getopt.GetoptError: |
|
99 usage() |
|
100 |
|
101 global platBinDir |
|
102 |
|
103 depChecks = 1 |
|
104 |
|
105 for opt, arg in optlist: |
|
106 if opt == "-h": |
|
107 usage(0) |
|
108 elif opt == "-p": |
|
109 privateInstall = 1 |
|
110 |
|
111 installTranslations() |
|
112 |
|
113 if __name__ == "__main__": |
|
114 try: |
|
115 main(sys.argv) |
|
116 except SystemExit: |
|
117 raise |
|
118 except: |
|
119 print \ |
|
120 """An internal error occured. Please report all the output of the program, |
|
121 including the following traceback, to eric5-bugs@eric-ide.python-projects.org. |
|
122 """ |
|
123 raise |