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