66from twisted .internet import reactor
77
88from bwscanner .attacher import connect_to_tor
9+ from bwscanner .configutil import read_config
910from bwscanner .logger import setup_logging , log
1011from bwscanner .measurement import BwScan
1112from bwscanner .aggregate import write_aggregate_data
1213
1314
1415BWSCAN_VERSION = '0.0.1'
16+ APP_NAME = 'bwscanner'
17+ DATA_DIR = os .environ .get ("BWSCANNER_DATADIR" , click .get_app_dir (APP_NAME ))
18+ CONFIG_FILE = 'config.ini'
19+ LOG_FILE = 'bwscanner.log'
20+
21+ CTX = dict (
22+ default_map = read_config (os .path .join (DATA_DIR , CONFIG_FILE ))
23+ )
1524
1625
1726class ScanInstance (object ):
@@ -29,18 +38,27 @@ def __repr__(self):
2938pass_scan = click .make_pass_decorator (ScanInstance )
3039
3140
32- @click .group ()
41+ # FIXME: change all options to take defaults from CTX, ie config file?
42+ @click .group (context_settings = CTX )
3343@click .option ('--data-dir' , type = click .Path (),
34- default = os .environ .get ("BWSCANNER_DATADIR" , click .get_app_dir ('bwscanner' )),
44+ default = os .environ .get ("BWSCANNER_DATADIR" ,
45+ CTX .get ('data_dir' ,
46+ click .get_app_dir (APP_NAME ))),
3547 help = 'Directory where bwscan should stores its measurements and '
3648 'other data.' )
37- @click .option ('-l' , '--loglevel' , help = 'The logging level the scanner will use (default: info)' ,
38- default = 'info' , type = click .Choice (['debug' , 'info' , 'warn' , 'error' , 'critical' ]))
39- @click .option ('-f' , '--logfile' , type = click .Path (), help = 'The file the log will be written to' ,
40- default = os .environ .get ("BWSCANNER_LOGFILE" , 'bwscanner.log' ))
41- @click .option ('--launch-tor/--no-launch-tor' , default = False ,
49+ @click .option ('-l' , '--loglevel' ,
50+ help = 'The logging level the scanner will use (default: info)' ,
51+ default = CTX .get ('loglevel' , 'info' ),
52+ type = click .Choice (['debug' , 'info' , 'warn' , 'error' , 'critical' ]))
53+ @click .option ('-f' , '--logfile' , type = click .Path (),
54+ help = 'The file the log will be written to' ,
55+ default = os .environ .get ("BWSCANNER_LOGFILE" ,
56+ CTX .get ('logfile' , LOG_FILE )))
57+ @click .option ('--launch-tor/--no-launch-tor' ,
58+ default = CTX .get ('launch_tor' , False ),
4259 help = 'Launch Tor or try to connect to an existing Tor instance.' )
43- @click .option ('--circuit-build-timeout' , default = 20 ,
60+ @click .option ('--circuit-build-timeout' ,
61+ default = CTX .get ('circuit_build_timeout' , 20 ),
4462 help = 'Option passed when launching Tor.' )
4563@click .version_option (BWSCAN_VERSION )
4664@click .pass_context
0 commit comments