eric6/Plugins/VcsPlugins/vcsMercurial/HisteditExtension/HgHisteditEditor.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

5283
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 #!/usr/bin/env python3
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
4 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
5283
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5 #
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 """
5291
e93d14b48c34 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5283
diff changeset
8 Module implementing the main script for histedit.
e93d14b48c34 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5283
diff changeset
9
e93d14b48c34 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5283
diff changeset
10 Depending on the file name given by the Mercurial histedit command one
e93d14b48c34 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5283
diff changeset
11 of two possible dialogs will be shown.
5283
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 """
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import sys
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import os
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 sys.path.insert(1, os.path.join(
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 os.path.dirname(__file__), "..", "..", "..", ".."))
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 # four times up is the eric6 package directory
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 for arg in sys.argv[:]:
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 if arg.startswith("--config="):
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 import Globals
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 configDir = arg.replace("--config=", "")
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Globals.setConfigDir(configDir)
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 sys.argv.remove(arg)
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 elif arg.startswith("--settings="):
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 from PyQt5.QtCore import QSettings
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 settingsDir = os.path.expanduser(arg.replace("--settings=", ""))
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 if not os.path.isdir(settingsDir):
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 os.makedirs(settingsDir)
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 QSettings.setPath(QSettings.IniFormat, QSettings.UserScope,
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 settingsDir)
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 sys.argv.remove(arg)
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 from Globals import AppInfo
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 from Toolbox import Startup
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 def createMainWidget(argv):
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Function to create the main widget.
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @param argv list of commandline parameters
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @type list of str
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @return reference to the main widget or None in case of an error
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @rtype QWidget or None
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 if len(argv) > 1:
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 fileName = os.path.basename(argv[1])
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 if fileName.startswith("hg-histedit-"):
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 from HgHisteditPlanEditor import HgHisteditPlanEditor
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 return HgHisteditPlanEditor(argv[1])
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 elif fileName.startswith("hg-editor-"):
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 from HgHisteditCommitEditor import HgHisteditCommitEditor
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 return HgHisteditCommitEditor(argv[1])
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 return None
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 def main():
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 Main entry point into the application.
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 options = [
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 ("--config=configDir",
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 "use the given directory as the one containing the config files"),
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 ("--settings=settingsDir",
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 "use the given directory to store the settings files"),
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 ("", "name of file to edit")
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 ]
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 appinfo = AppInfo.makeAppInfo(sys.argv,
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 "Mercurial Histedit Editor",
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 "",
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 "Editor for the Mercurial histedit command",
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 options)
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 res = Startup.simpleAppStartup(sys.argv,
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 appinfo,
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 createMainWidget)
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 sys.exit(res)
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 if __name__ == '__main__':
06423d65a2b8 Added support for the Mercurial histedit extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 main()

eric ide

mercurial