forked from adamrehn/ue4-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiagnostics_cmd.py
62 lines (50 loc) · 2.11 KB
/
diagnostics_cmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from .infrastructure import Logger, PrettyPrinting
from .diagnostics import *
import sys
def diagnostics():
# The diagnostics that can be run
DIAGNOSTICS = {
'all': allDiagnostics(),
'8gig': diagnostic8Gig(),
'maxsize': diagnosticMaxSize()
}
# Create our logger to generate coloured output on stderr
logger = Logger(prefix='[{} diagnostics] '.format(sys.argv[0]))
# Parse the supplied command-line arguments
stripped = list([arg for arg in sys.argv if arg.strip('-') not in ['h', 'help']])
args = {
'help': len(sys.argv) > len(stripped),
'diagnostic': stripped[1] if len(stripped) > 1 else None,
}
# If a diagnostic name has been specified, verify that it is valid
if args['diagnostic'] is not None and args['diagnostic'] not in DIAGNOSTICS:
logger.error('Error: unrecognised diagnostic "{}".'.format(args['diagnostic']), False)
sys.exit(1)
# Determine if we are running a diagnostic
if args['help'] == False and args['diagnostic'] is not None:
# Run the diagnostic
diagnostic = DIAGNOSTICS[args['diagnostic']]
logger.action('Running diagnostic: "{}"'.format(diagnostic.getName()), False)
passed = diagnostic.run(logger, stripped[2:])
# Print the result
if passed == True:
logger.action('Diagnostic result: passed', False)
else:
logger.error('Diagnostic result: failed', False)
# Determine if we are displaying the help for a specific diagnostic
elif args['help'] == True and args['diagnostic'] is not None:
# Display the help for the diagnostic
diagnostic = DIAGNOSTICS[args['diagnostic']]
print('{} diagnostics {}'.format(sys.argv[0], args['diagnostic']))
print(diagnostic.getName() + '\n')
print(diagnostic.getDescription())
else:
# Print usage syntax
print('Usage: {} diagnostics DIAGNOSTIC\n'.format(sys.argv[0]))
print('Runs diagnostics to detect issues with the host system configuration\n')
print('Available diagnostics:')
PrettyPrinting.printColumns([
(diagnostic, DIAGNOSTICS[diagnostic].getName())
for diagnostic in DIAGNOSTICS
])
print('\nRun `{} diagnostics DIAGNOSTIC --help` for more information on a diagnostic.'.format(sys.argv[0]))