-
Notifications
You must be signed in to change notification settings - Fork 5
/
frosty.py
83 lines (70 loc) · 2.04 KB
/
frosty.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
#!/bin/env python2.7
from getopt import getopt
import sys
from icestats import daemon
from settings import *
import logging
from datetime import datetime
logging.captureWarnings(True)
if __name__ == '__main__':
args, opts = getopt(
sys.argv[1:],
"h:b:u:w:r:d",
["help",
"host=",
"bind=",
"username=",
"password=",
"realm=",
"daemonize"])
daemonize = False
realm = None
for k, v in args:
if k == '--help':
print "ZOMG"
sys.exit(1)
elif k in ('-d', '--daemonize'):
daemonize = True
elif k in ('-h', '--host'):
if not v:
raise Exception()
host = v
elif k in ('-b', '--bind'):
if not v:
raise Exception()
port = int(v)
elif k in ('-u', '--username'):
if not v:
raise Exception()
username = v
elif k in ('-w', '--password'):
if not v:
raise Exception()
password = v
elif k in ('-r', '--realm'):
realm = v
formatter = logging.Formatter(
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
)
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
filename='logs/access_{}.log'.format(
datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
)
)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
logging.getLogger('').addHandler(console)
logger = logging.getLogger(__name__)
logger.debug("Process starting")
try:
process = daemon.Daemon('.', host, username, password, realm, port, useragent_bots)
logger.debug("Process started")
except:
process = daemon.Daemon('.', host, username, password, realm, port)
logger.debug("Process started")
if daemonize:
process.daemonize()
logger.debug("Process daemonized")
process.run()