|
1 #!/usr/bin/env python3 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
|
5 # |
|
6 |
|
7 """ |
|
8 eric FIDO2 Token Management. |
|
9 |
|
10 This is the main Python script that performs the necessary initialization |
|
11 of the FIDO2 Security Key Management module and starts the Qt event loop. |
|
12 This is a standalone version of the integrated FIDO2 Security Key Management |
|
13 module. |
|
14 """ |
|
15 |
|
16 import argparse |
|
17 import importlib |
|
18 import os |
|
19 import sys |
|
20 |
|
21 from PyQt6.QtGui import QGuiApplication |
|
22 |
|
23 |
|
24 def createArgparseNamespace(): |
|
25 """ |
|
26 Function to create an argument parser. |
|
27 |
|
28 @return created argument parser object |
|
29 @rtype argparse.ArgumentParser |
|
30 """ |
|
31 from eric7.__version__ import Version |
|
32 |
|
33 # 1. create the argument parser |
|
34 parser = argparse.ArgumentParser( |
|
35 description="Management tool for FIDO2 Security Keys.", |
|
36 epilog="Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>.", |
|
37 ) |
|
38 |
|
39 # 2. add the arguments |
|
40 parser.add_argument( |
|
41 "-V", |
|
42 "--version", |
|
43 action="version", |
|
44 version="%(prog)s {0}".format(Version), |
|
45 help="show version information and exit", |
|
46 ) |
|
47 parser.add_argument( |
|
48 "--config", |
|
49 metavar="config_dir", |
|
50 help="use the given directory as the one containing the config files", |
|
51 ) |
|
52 parser.add_argument( |
|
53 "--settings", |
|
54 metavar="settings_dir", |
|
55 help="use the given directory to store the settings files", |
|
56 ) |
|
57 |
|
58 # 3. create the Namespace object by parsing the command line |
|
59 args = parser.parse_args() |
|
60 return args |
|
61 |
|
62 |
|
63 args = createArgparseNamespace() |
|
64 if args.config: |
|
65 from eric7 import Globals |
|
66 |
|
67 Globals.setConfigDir(args.config) |
|
68 if args.settings: |
|
69 from PyQt6.QtCore import QSettings |
|
70 |
|
71 SettingsDir = os.path.expanduser(args.settings) |
|
72 if not os.path.isdir(SettingsDir): |
|
73 os.makedirs(SettingsDir) |
|
74 QSettings.setPath( |
|
75 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
|
76 ) |
|
77 |
|
78 if importlib.util.find_spec("fido2") is None: |
|
79 from PyQt6.QtCore import QTimer |
|
80 from PyQt6.QtWidgets import QApplication |
|
81 |
|
82 from eric7.EricWidgets import EricMessageBox |
|
83 |
|
84 app = QApplication([]) |
|
85 QTimer.singleShot( |
|
86 0, |
|
87 lambda: EricMessageBox.critical( |
|
88 None, |
|
89 "FIDO2 Security Key Management", |
|
90 "The required 'fido2' package is not installed. Aborting...", |
|
91 ), |
|
92 ) |
|
93 app.exec() |
|
94 sys.exit(100) |
|
95 |
|
96 from eric7.Toolbox import Startup |
|
97 |
|
98 |
|
99 def createMainWidget(_args): |
|
100 """ |
|
101 Function to create the main widget. |
|
102 |
|
103 @param _args namespace object containing the parsed command line parameters |
|
104 (unused) |
|
105 @type argparse.Namespace |
|
106 @return reference to the main widget |
|
107 @rtype QWidget |
|
108 """ |
|
109 from eric7.WebBrowser.WebAuth.Fido2ManagementDialog import Fido2ManagementDialog |
|
110 |
|
111 return Fido2ManagementDialog() |
|
112 |
|
113 |
|
114 def main(): |
|
115 """ |
|
116 Main entry point into the application. |
|
117 """ |
|
118 QGuiApplication.setDesktopFileName("eric7_fido2") |
|
119 |
|
120 res = Startup.appStartup(args, createMainWidget) |
|
121 sys.exit(res) |
|
122 |
|
123 |
|
124 if __name__ == "__main__": |
|
125 main() |