<s> import subprocess , config , sys , config_gen , shlex , os , errno <EOL> from time import sleep <EOL> from common_methods import exit_script , exit_error <EOL> from config_hostapd import generate_confs <EOL> def make_dirs ( conf ) : <EOL> if conf . has_key ( '<STR_LIT>' ) : <EOL> dirname = os . path . dirname ( conf [ '<STR_LIT>' ] ) <EOL> try : <EOL> os . makedirs ( dirname ) <EOL> except OSError as exc : <EOL> if exc . errno != errno . EEXIST : <EOL> raise <EOL> def start_hostapd ( ) : <EOL> generate_confs ( ) <EOL> conf = config_gen . get_config ( ) <EOL> env_tups = [ ( section + '<STR_LIT:_>' + key , val ) for section in conf . keys ( ) for key , val in conf [ section ] . items ( ) ] <EOL> env_dict = dict ( os . environ . items ( ) + env_tups ) <EOL> print '<STR_LIT>' <EOL> for section in config . script_order : <EOL> if conf [ section ] . has_key ( '<STR_LIT>' ) : <EOL> make_dirs ( conf [ section ] ) <EOL> print '<STR_LIT>' % ( conf [ section ] [ '<STR_LIT>' ] , section ) , <EOL> ret = subprocess . call ( conf [ section ] [ '<STR_LIT>' ] , env = env_dict ) <EOL> if ret == <NUM_LIT:0> : <EOL> print '<STR_LIT>' <EOL> else : <EOL> print '<STR_LIT>' <EOL> exit_error ( '<STR_LIT>' % ( section , conf [ section ] [ '<STR_LIT>' ] ) ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> def stop_hostapd ( ) : <EOL> conf = config_gen . get_config ( ) <EOL> env_tups = [ ( section + '<STR_LIT:_>' + key , val ) for section in conf . keys ( ) for key , val in conf [ section ] . items ( ) ] <EOL> env_dict = dict ( os . environ . items ( ) + env_tups ) <EOL> print '<STR_LIT>' <EOL> for section in config . script_order [ : : - <NUM_LIT:1> ] : <EOL> if conf [ section ] . has_key ( '<STR_LIT>' ) : <EOL> make_dirs ( conf [ section ] ) <EOL> print '<STR_LIT>' % ( conf [ section ] [ '<STR_LIT>' ] , section ) , <EOL> ret = subprocess . call ( conf [ section ] [ '<STR_LIT>' ] , env = env_dict ) <EOL> if ret == <NUM_LIT:0> : <EOL> print '<STR_LIT>' <EOL> else : <EOL> print '<STR_LIT>' <EOL> exit_error ( '<STR_LIT>' % ( section , conf [ section ] [ '<STR_LIT>' ] ) ) <EOL> def restart_hostapd ( ) : <EOL> stop_hostapd ( ) <EOL> sleep ( <NUM_LIT:2> ) <EOL> start_hostapd ( ) </s>
