9 |
9 |
10 Depending on the file name given by the Mercurial histedit command one |
10 Depending on the file name given by the Mercurial histedit command one |
11 of two possible dialogs will be shown. |
11 of two possible dialogs will be shown. |
12 """ |
12 """ |
13 |
13 |
|
14 import argparse |
14 import os |
15 import os |
15 import sys |
16 import sys |
16 |
17 |
17 sys.path.insert( |
18 sys.path.insert( |
18 1, |
19 1, |
19 os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", ".."), |
20 os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", ".."), |
20 ) |
21 ) |
21 # five times up is our installation directory |
22 # five times up is our installation directory |
22 |
23 |
23 for arg in sys.argv[:]: |
|
24 if arg.startswith("--config="): |
|
25 from eric7 import Globals |
|
26 |
24 |
27 configDir = arg.replace("--config=", "") |
25 def createArgparseNamespace(): |
28 Globals.setConfigDir(configDir) |
26 """ |
29 sys.argv.remove(arg) |
27 Function to create an argument parser. |
30 elif arg.startswith("--settings="): |
|
31 from PyQt6.QtCore import QSettings |
|
32 |
28 |
33 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
29 @return created argument parser object |
34 if not os.path.isdir(settingsDir): |
30 @rtype argparse.ArgumentParser |
35 os.makedirs(settingsDir) |
31 """ |
36 QSettings.setPath( |
32 from eric7.UI.Info import Version |
37 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir |
|
38 ) |
|
39 sys.argv.remove(arg) |
|
40 |
33 |
41 from eric7.Globals import AppInfo |
34 # 1. create the argument parser |
|
35 parser = argparse.ArgumentParser( |
|
36 description="Graphical editor for the Mercurial 'histedit' command.", |
|
37 epilog="Copyright (c) 2016 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.", |
|
38 ) |
|
39 |
|
40 # 2. add the arguments |
|
41 parser.add_argument( |
|
42 "-V", |
|
43 "--version", |
|
44 action="version", |
|
45 version="%(prog)s {0}".format(Version), |
|
46 help="show version information and exit", |
|
47 ) |
|
48 parser.add_argument( |
|
49 "--config", |
|
50 metavar="config_dir", |
|
51 help="use the given directory as the one containing the config files", |
|
52 ) |
|
53 parser.add_argument( |
|
54 "--settings", |
|
55 metavar="settings_dir", |
|
56 help="use the given directory to store the settings files", |
|
57 ) |
|
58 parser.add_argument( |
|
59 "file", |
|
60 nargs="?", |
|
61 help="'histedit' file to be edited", |
|
62 ) |
|
63 |
|
64 # 3. create the Namespace object by parsing the command line |
|
65 args = parser.parse_args() |
|
66 return args |
|
67 |
|
68 |
|
69 args = createArgparseNamespace() |
|
70 if args.config: |
|
71 from eric7 import Globals |
|
72 |
|
73 Globals.setConfigDir(args.config) |
|
74 if args.settings: |
|
75 from PyQt6.QtCore import QSettings |
|
76 |
|
77 SettingsDir = os.path.expanduser(args.settings) |
|
78 if not os.path.isdir(SettingsDir): |
|
79 os.makedirs(SettingsDir) |
|
80 QSettings.setPath( |
|
81 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
|
82 ) |
|
83 |
42 from eric7.Toolbox import Startup |
84 from eric7.Toolbox import Startup |
43 |
85 |
44 |
86 |
45 def createMainWidget(argv): |
87 def createMainWidget(args): |
46 """ |
88 """ |
47 Function to create the main widget. |
89 Function to create the main widget. |
48 |
90 |
49 @param argv list of commandline parameters |
91 @param args namespace object containing the parsed command line parameters |
50 @type list of str |
92 @type argparse.Namespace |
51 @return reference to the main widget or None in case of an error |
93 @return reference to the main widget |
52 @rtype QWidget or None |
94 @rtype QWidget |
53 """ |
95 """ |
54 if len(argv) > 1: |
96 if args.file: |
55 fileName = os.path.basename(argv[1]) |
97 fileName = os.path.basename(args.file) |
56 if fileName.startswith("hg-histedit-"): |
98 if fileName.startswith("hg-histedit-"): |
57 from HgHisteditPlanEditor import ( # __IGNORE_WARNING_I10__ |
99 from HgHisteditPlanEditor import HgHisteditPlanEditor # noqa: I101, I102 |
58 HgHisteditPlanEditor, |
|
59 ) |
|
60 |
100 |
61 return HgHisteditPlanEditor(argv[1]) |
101 return HgHisteditPlanEditor(args.file) |
62 elif fileName.startswith("hg-editor-"): |
102 elif fileName.startswith("hg-editor-"): |
63 from HgHisteditCommitEditor import ( # __IGNORE_WARNING_I10__ |
103 from HgHisteditCommitEditor import ( # noqa: I101, I102 |
64 HgHisteditCommitEditor, |
104 HgHisteditCommitEditor, |
65 ) |
105 ) |
66 |
106 |
67 return HgHisteditCommitEditor(argv[1]) |
107 return HgHisteditCommitEditor(args.file) |
68 |
108 |
69 return None |
109 return None |
70 |
110 |
71 |
111 |
72 def main(): |
112 def main(): |
73 """ |
113 """ |
74 Main entry point into the application. |
114 Main entry point into the application. |
75 """ |
115 """ |
76 options = [ |
116 res = Startup.appStartup(args, createMainWidget) |
77 ( |
|
78 "--config=configDir", |
|
79 "use the given directory as the one containing the config files", |
|
80 ), |
|
81 ( |
|
82 "--settings=settingsDir", |
|
83 "use the given directory to store the settings files", |
|
84 ), |
|
85 ("", "name of file to edit"), |
|
86 ] |
|
87 appinfo = AppInfo.makeAppInfo( |
|
88 sys.argv, |
|
89 "Mercurial Histedit Editor", |
|
90 "", |
|
91 "Editor for the Mercurial histedit command", |
|
92 options, |
|
93 ) |
|
94 res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget) |
|
95 sys.exit(res) |
117 sys.exit(res) |
96 |
118 |
97 |
119 |
98 if __name__ == "__main__": |
120 if __name__ == "__main__": |
99 main() |
121 main() |