<s> import logging , os , datetime , sys <EOL> import glob , tempfile , subprocess <EOL> from OpenMesher . lib import nested_dict_merge <EOL> from OpenMesher . interfaces import IOpenMesherPackagePlugin <EOL> def dump_config_files ( base_path , files_dict ) : <EOL> for router in files_dict : <EOL> for cfgfile in files_dict [ router ] : <EOL> cfgfile_path = os . path . abspath ( base_path + '<STR_LIT:/>' + router + '<STR_LIT:/>' + cfgfile ) <EOL> logging . debug ( '<STR_LIT>' % ( cfgfile_path , router ) ) <EOL> fpath , fname = os . path . split ( cfgfile_path ) <EOL> _mkdirs ( fpath ) <EOL> fh = open ( cfgfile_path , '<STR_LIT:w>' ) <EOL> fh . write ( files_dict [ router ] [ cfgfile ] ) <EOL> fh . close ( ) <EOL> if fname == '<STR_LIT>' or fname == '<STR_LIT>' : <EOL> os . chmod ( cfgfile_path , <NUM_LIT:0> <NUM_LIT> ) <EOL> def _mkdirs ( path ) : <EOL> try : <EOL> os . makedirs ( path ) <EOL> except OSError as e : <EOL> if e . errno == <NUM_LIT> : <EOL> pass <EOL> else : <EOL> raise <EOL> class MakeDEBs ( IOpenMesherPackagePlugin ) : <EOL> def activate ( self ) : <EOL> self . _register ( '<STR_LIT>' ) <EOL> self . _register ( '<STR_LIT>' ) <EOL> self . _register ( '<STR_LIT>' ) <EOL> self . _register ( '<STR_LIT>' ) <EOL> self . _register ( '<STR_LIT>' ) <EOL> def setupargs ( self , parser ) : <EOL> parser . add_argument ( '<STR_LIT>' , default = '<STR_LIT:1.0>' , action = '<STR_LIT:store>' , help = '<STR_LIT>' ) <EOL> super ( MakeDEBs , self ) . setupargs ( parser ) <EOL> def process ( self , mesh , configPlugins = None , cliargs = None , include_dirs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , restart_services = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) : <EOL> base_path = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> logging . warn ( '<STR_LIT>' % ( base_path ) ) <EOL> _mkdirs ( base_path ) <EOL> logging . info ( '<STR_LIT>' ) <EOL> for router in mesh . routers : <EOL> self . _files [ router ] = { } <EOL> changelog_date = datetime . datetime . strftime ( datetime . datetime . now ( ) , '<STR_LIT>' ) <EOL> self . _files [ router ] [ '<STR_LIT>' ] = self . _templates [ '<STR_LIT>' ] . render ( <EOL> hostname = mesh . routers [ router ] . hostname . lower ( ) , <EOL> package_version = cliargs . dpkg_version , <EOL> changelog_date = changelog_date , <EOL> ) <EOL> self . _files [ router ] [ '<STR_LIT>' ] = self . _templates [ '<STR_LIT>' ] . render ( ) <EOL> self . _files [ router ] [ '<STR_LIT>' ] = self . _templates [ '<STR_LIT>' ] . render ( <EOL> hostname = mesh . routers [ router ] . hostname . lower ( ) , <EOL> fqdn = mesh . routers [ router ] . fqdn , <EOL> changelog_date = changelog_date , <EOL> ) <EOL> self . _files [ router ] [ '<STR_LIT>' ] = self . _templates [ '<STR_LIT>' ] . render ( <EOL> hostname = mesh . routers [ router ] . hostname . lower ( ) , <EOL> dirs = include_dirs , <EOL> ) <EOL> self . _files [ router ] [ '<STR_LIT>' ] = self . _templates [ '<STR_LIT>' ] . render ( <EOL> restart = restart_services , <EOL> ) <EOL> self . _packages [ router ] = '<STR_LIT>' % ( base_path , mesh . routers [ router ] . hostname . lower ( ) ) <EOL> logging . debug ( '<STR_LIT>' ) <EOL> dump_config_files ( base_path , self . _files ) <EOL> logging . info ( '<STR_LIT>' ) <EOL> for plugin in configPlugins : <EOL> logging . debug ( '<STR_LIT>' % ( plugin ) ) <EOL> dump_config_files ( base_path , plugin . files ( ) ) <EOL> for router in self . _files : <EOL> logging . info ( '<STR_LIT>' % ( router ) ) <EOL> router_path = os . path . abspath ( base_path + '<STR_LIT:/>' + router ) <EOL> sCMD = '<STR_LIT>' <EOL> process = subprocess . Popen ( sCMD , shell = True , stdout = subprocess . PIPE , cwd = router_path ) <EOL> process . wait ( ) <EOL> if process . returncode != <NUM_LIT:0> : <EOL> raise Exception ( '<STR_LIT>' % ( base_path ) ) </s>
