33import time
44
55import click
6+ import ConfigParser
67from twisted .internet import reactor
78
89from bwscanner .attacher import connect_to_tor
1213
1314
1415BWSCAN_VERSION = '0.0.1'
16+ APP_NAME = 'bwscanner'
1517
1618
1719class ScanInstance (object ):
@@ -26,12 +28,27 @@ def __repr__(self):
2628 return '<BWScan %r>' % self .data_dir
2729
2830
31+ def read_config (data_dir ):
32+ cfg = os .path .join (data_dir , 'config.ini' )
33+ print ('reading config %s' % cfg )
34+ parser = ConfigParser .RawConfigParser ()
35+ parser .read ([cfg ])
36+ # FIXME: handle section names
37+ section = 'default'
38+ return dict (parser .items (section ))
39+
40+
41+ CONTEXT_SETTINGS = dict (
42+ default_map = read_config (os .environ .get ("BWSCANNER_DATADIR" ,
43+ click .get_app_dir (APP_NAME )))
44+ )
45+
2946pass_scan = click .make_pass_decorator (ScanInstance )
3047
3148
32- @click .group ()
49+ @click .group (context_settings = CONTEXT_SETTINGS )
3350@click .option ('--data-dir' , type = click .Path (),
34- default = os .environ .get ("BWSCANNER_DATADIR" , click .get_app_dir ('bwscanner' )),
51+ default = os .environ .get ("BWSCANNER_DATADIR" , click .get_app_dir (APP_NAME )),
3552 help = 'Directory where bwscan should stores its measurements and '
3653 'other data.' )
3754@click .option ('-l' , '--loglevel' , help = 'The logging level the scanner will use (default: info)' ,
@@ -53,6 +70,7 @@ def cli(ctx, data_dir, loglevel, logfile, launch_tor, circuit_build_timeout):
5370 # Create the data directory if it doesn't exist
5471 data_dir = os .path .abspath (data_dir )
5572 ctx .obj = ScanInstance (data_dir )
73+ print (ctx .obj )
5674
5775 if not os .path .isdir (ctx .obj .measurement_dir ):
5876 os .makedirs (ctx .obj .measurement_dir )
0 commit comments