9 |
9 |
10 This is the main Python script to install eric plugins from outside of the |
10 This is the main Python script to install eric plugins from outside of the |
11 IDE. |
11 IDE. |
12 """ |
12 """ |
13 |
13 |
|
14 import argparse |
14 import os |
15 import os |
15 import sys |
16 import sys |
16 |
17 |
17 from PyQt6.QtGui import QGuiApplication |
18 from PyQt6.QtGui import QGuiApplication |
18 |
19 |
19 for arg in sys.argv[:]: |
|
20 if arg.startswith("--config="): |
|
21 from eric7 import Globals |
|
22 |
20 |
23 configDir = arg.replace("--config=", "") |
21 def createArgparseNamespace(): |
24 Globals.setConfigDir(configDir) |
22 """ |
25 sys.argv.remove(arg) |
23 Function to create an argument parser. |
26 elif arg.startswith("--settings="): |
|
27 from PyQt6.QtCore import QSettings |
|
28 |
24 |
29 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
25 @return created argument parser object |
30 if not os.path.isdir(settingsDir): |
26 @rtype argparse.ArgumentParser |
31 os.makedirs(settingsDir) |
27 """ |
32 QSettings.setPath( |
28 from eric7.UI.Info import Version |
33 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir |
|
34 ) |
|
35 sys.argv.remove(arg) |
|
36 |
29 |
37 from eric7.Globals import AppInfo |
30 # 1. create the argument parser |
|
31 parser = argparse.ArgumentParser( |
|
32 description="Graphical plugin installation tool of the eric tool suite.", |
|
33 epilog="Copyright (c) 2007 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.", |
|
34 ) |
|
35 |
|
36 # 2. add the arguments |
|
37 parser.add_argument( |
|
38 "-V", |
|
39 "--version", |
|
40 action="version", |
|
41 version="%(prog)s {0}".format(Version), |
|
42 help="show version information and exit", |
|
43 ) |
|
44 parser.add_argument( |
|
45 "--config", |
|
46 metavar="config_dir", |
|
47 help="use the given directory as the one containing the config files", |
|
48 ) |
|
49 parser.add_argument( |
|
50 "--settings", |
|
51 metavar="settings_dir", |
|
52 help="use the given directory to store the settings files", |
|
53 ) |
|
54 parser.add_argument( |
|
55 "plugin", |
|
56 nargs="*", |
|
57 default=[], |
|
58 help="plugin archive file to be installed", |
|
59 ) |
|
60 |
|
61 # 3. create the Namespace object by parsing the command line |
|
62 args = parser.parse_args() |
|
63 return args |
|
64 |
|
65 |
|
66 args = createArgparseNamespace() |
|
67 if args.config: |
|
68 from eric7 import Globals |
|
69 |
|
70 Globals.setConfigDir(args.config) |
|
71 if args.settings: |
|
72 from PyQt6.QtCore import QSettings |
|
73 |
|
74 SettingsDir = os.path.expanduser(args.settings) |
|
75 if not os.path.isdir(SettingsDir): |
|
76 os.makedirs(SettingsDir) |
|
77 QSettings.setPath( |
|
78 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
|
79 ) |
|
80 |
38 from eric7.Toolbox import Startup |
81 from eric7.Toolbox import Startup |
39 |
82 |
40 |
83 |
41 def createMainWidget(argv): |
84 def createMainWidget(args): |
42 """ |
85 """ |
43 Function to create the main widget. |
86 Function to create the main widget. |
44 |
87 |
45 @param argv list of commandline parameters (list of strings) |
88 @param args namespace object containing the parsed command line parameters |
46 @return reference to the main widget (QWidget) |
89 @type argparse.Namespace |
|
90 @return reference to the main widget |
|
91 @rtype QWidget |
47 """ |
92 """ |
48 from eric7.PluginManager.PluginInstallDialog import PluginInstallWindow |
93 from eric7.PluginManager.PluginInstallDialog import PluginInstallWindow |
49 |
94 |
50 return PluginInstallWindow(argv[1:]) |
95 return PluginInstallWindow(args.plugin) |
51 |
96 |
52 |
97 |
53 def main(): |
98 def main(): |
54 """ |
99 """ |
55 Main entry point into the application. |
100 Main entry point into the application. |
56 """ |
101 """ |
57 QGuiApplication.setDesktopFileName("eric7_plugininstall") |
102 QGuiApplication.setDesktopFileName("eric7_plugininstall") |
58 |
103 |
59 options = [ |
104 res = Startup.appStartup(args, createMainWidget) |
60 ( |
|
61 "--config=configDir", |
|
62 "use the given directory as the one containing the config files", |
|
63 ), |
|
64 ( |
|
65 "--settings=settingsDir", |
|
66 "use the given directory to store the settings files", |
|
67 ), |
|
68 ("", "names of plugins to install"), |
|
69 ] |
|
70 appinfo = AppInfo.makeAppInfo( |
|
71 sys.argv, |
|
72 "eric Plugin Installer", |
|
73 "", |
|
74 "Plugin installation utility for eric", |
|
75 options, |
|
76 ) |
|
77 res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget) |
|
78 sys.exit(res) |
105 sys.exit(res) |
79 |
106 |
80 |
107 |
81 if __name__ == "__main__": |
108 if __name__ == "__main__": |
82 main() |
109 main() |