forked from blawar/nut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nut.py
executable file
·95 lines (78 loc) · 2.39 KB
/
nut.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import sys
import os
from pathlib import Path
import urllib3
if not getattr(sys, 'frozen', False):
os.chdir(Path(__file__).resolve().parent)
from nut import config
from nut import printer
from nut import status
import server
import nut
if __name__ == '__main__':
try:
urllib3.disable_warnings()
parser = argparse.ArgumentParser()
parser.add_argument(
'--usb',
action="store_true",
help='Run usb daemon',
)
parser.add_argument(
'-S',
'--server',
action="store_true",
help='Run server daemon',
)
parser.add_argument('-m', '--hostname', help='Set server hostname')
parser.add_argument('-p', '--port', type=int, help='Set server port')
parser.add_argument(
'--silent',
action="store_true",
help='Suppresses stdout',
)
args = parser.parse_args()
if args.silent:
printer.silent = True
if args.hostname:
args.server = True
config.server.hostname = args.hostname
if args.port:
args.server = True
config.server.port = int(args.port)
status.start()
printer.info(' ,;:;;,')
printer.info(' ;;;;;')
printer.info(' .=\', ;:;;:,')
printer.info(' /_\', "=. \';:;:;')
printer.info(' @=:__, \\,;:;:\'')
printer.info(' _(\\.= ;:;;\'')
printer.info(' `"_( _/="`')
printer.info(' `"\'')
if args.usb:
try:
from nut import usb
except BaseException as e:
printer.error('pip3 install pyusb, required for USB coms: ' +
f'{str(e)}')
nut.scan()
usb.daemon()
if args.server:
nut.initFiles()
nut.scan()
server.run()
if len(sys.argv) == 1:
import nut_gui
nut_gui.run()
status.close()
except KeyboardInterrupt:
config.isRunning = False
status.close()
except BaseException:
config.isRunning = False
status.close()
raise
printer.info('fin')