forked from blawar/nut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nut.py
executable file
·100 lines (76 loc) · 2.05 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
96
97
98
99
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import sys
import os
import re
import pathlib
import urllib3
import json
if not getattr(sys, 'frozen', False):
os.chdir(os.path.dirname(os.path.abspath(__file__)))
#sys.path.insert(0, 'nut')
from nut import Nsps
from nut import Config
import requests
from nut import Print
import threading
import signal
from nut import Status
import time
import colorama
import Server
import pprint
import random
import queue
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:
Print.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()
Print.info(' ,;:;;,')
Print.info(' ;;;;;')
Print.info(' .=\', ;:;;:,')
Print.info(' /_\', "=. \';:;:;')
Print.info(' @=:__, \,;:;:\'')
Print.info(' _(\.= ;:;;\'')
Print.info(' `"_( _/="`')
Print.info(' `"\'')
if args.usb:
try:
from nut import Usb
except BaseException as e:
Print.error('pip3 install pyusb, required for USB coms: ' + str(e))
nut.scan()
Usb.daemon()
if args.server:
nut.initFiles()
nut.scan()
Server.run()
if len(sys.argv)==1:
import server
server.run()
Status.close()
except KeyboardInterrupt:
Config.isRunning = False
Status.close()
except BaseException as e:
Config.isRunning = False
Status.close()
raise
Print.info('fin')