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 ):
@@ -21,17 +23,33 @@ class ScanInstance(object):
2123 def __init__ (self , data_dir ):
2224 self .data_dir = data_dir
2325 self .measurement_dir = os .path .join (data_dir , 'measurements' )
26+ self .tor_dir = os .path .join (data_dir , 'tordata' )
2427
2528 def __repr__ (self ):
2629 return '<BWScan %r>' % self .data_dir
2730
2831
32+ def read_config (data_dir ):
33+ cfg = os .path .join (data_dir , 'config.ini' )
34+ print ('reading config %s' % cfg )
35+ parser = ConfigParser .RawConfigParser ()
36+ parser .read ([cfg ])
37+ # FIXME: handle section names
38+ section = 'default'
39+ return dict (parser .items (section ))
40+
41+
42+ CONTEXT_SETTINGS = dict (
43+ default_map = read_config (os .environ .get ("BWSCANNER_DATADIR" ,
44+ click .get_app_dir (APP_NAME )))
45+ )
46+
2947pass_scan = click .make_pass_decorator (ScanInstance )
3048
3149
32- @click .group ()
50+ @click .group (context_settings = CONTEXT_SETTINGS )
3351@click .option ('--data-dir' , type = click .Path (),
34- default = os .environ .get ("BWSCANNER_DATADIR" , click .get_app_dir ('bwscanner' )),
52+ default = os .environ .get ("BWSCANNER_DATADIR" , click .get_app_dir (APP_NAME )),
3553 help = 'Directory where bwscan should stores its measurements and '
3654 'other data.' )
3755@click .option ('-l' , '--loglevel' , help = 'The logging level the scanner will use (default: info)' ,
@@ -53,6 +71,7 @@ def cli(ctx, data_dir, loglevel, logfile, launch_tor, circuit_build_timeout):
5371 # Create the data directory if it doesn't exist
5472 data_dir = os .path .abspath (data_dir )
5573 ctx .obj = ScanInstance (data_dir )
74+ print (ctx .obj )
5675
5776 if not os .path .isdir (ctx .obj .measurement_dir ):
5877 os .makedirs (ctx .obj .measurement_dir )
0 commit comments