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
|
import argparse
import shelve
from config import CONFIG_DB_PATH
from sys import argv
parser = argparse.ArgumentParser()
parser.add_argument(
'--chunk-size', type=int, default=1024,
help='Size of chunk that server uses when fetching data from connection'
)
parser.add_argument(
'--bg-color', type=str, default='white',
help='Default background color of all webpages'
)
parser.add_argument('--short-log', action='store_true')
parser.add_argument('--show-errors', action='store_true')
parser.add_argument(
'--log', default='logs/log.log',
help='File where log will be written'
)
parser.add_argument(
'--cookies-db', default='db/cookies.db',
help='Path to file where cookies will be stored'
)
parser.add_argument(
'--host', default='0.0.0.0',
help='IP of interface where server will be started'
)
parser.add_argument(
'--port', type=int, default=8888,
help='Port on which server will be started'
)
args = parser.parse_known_args(argv[1:])[0]
with shelve.open(CONFIG_DB_PATH) as config:
config['chunk'] = args.chunk_size
config['short_log'] = args.short_log
config['log_path'] = args.log
config['show_errors'] = args.show_errors
config['cookies_db_path'] = args.cookies_db
config['host'] = args.host
config['port'] = args.port
cookies = shelve.open(args.cookies_db)
cookies['bg_color'] = args.bg_color
cookies.close()
import http_handler
http_handler.main()
|