scripts/install-i18n.py

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

eric ide

mercurial