<s> from src . platform . weblogic . interfaces import WINTERFACES <EOL> from time import sleep <EOL> from subprocess import Popen , PIPE , check_output , STDOUT <EOL> from requests import get <EOL> from signal import SIGINT <EOL> from os import kill , remove <EOL> from sys import stdout <EOL> from shutil import copy <EOL> from log import LOG <EOL> import importlib <EOL> import pkgutil <EOL> import state <EOL> import utility <EOL> def _serve ( war_file = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if war_file : <EOL> try : <EOL> copy ( war_file , state . serve_dir ) <EOL> except : pass <EOL> proc = Popen ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , str ( state . external_port ) ] , <EOL> stdout = PIPE , stderr = PIPE , cwd = state . serve_dir ) <EOL> while '<STR_LIT:GET>' not in proc . stderr . readline ( ) : <EOL> sleep ( <NUM_LIT:1.0> ) <EOL> sleep ( <NUM_LIT> ) <EOL> except Exception , e : <EOL> utility . Msg ( e , LOG . DEBUG ) <EOL> finally : <EOL> kill ( proc . pid , SIGINT ) <EOL> if war_file : <EOL> war_name = parse_war_path ( war_file , True ) <EOL> remove ( "<STR_LIT>" % ( state . serve_dir , war_name ) ) <EOL> def waitServe ( servert ) : <EOL> """<STR_LIT>""" <EOL> timeout = <NUM_LIT:10> <EOL> status = False <EOL> try : <EOL> while servert . is_alive ( ) and timeout > <NUM_LIT:0> : <EOL> stdout . flush ( ) <EOL> stdout . write ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( utility . timestamp ( ) , timeout ) ) <EOL> sleep ( <NUM_LIT:1.0> ) <EOL> timeout -= <NUM_LIT:1> <EOL> except : <EOL> timeout = <NUM_LIT:0> <EOL> if timeout is not <NUM_LIT:10> : <EOL> print '<STR_LIT>' <EOL> if timeout is <NUM_LIT:0> : <EOL> utility . Msg ( "<STR_LIT>" , LOG . ERROR ) <EOL> else : <EOL> status = True <EOL> return status <EOL> def wc_invoke ( url , local_url , usr = None , pswd = None ) : <EOL> """<STR_LIT>""" <EOL> res = None <EOL> try : <EOL> res = check_output ( [ "<STR_LIT>" , url , local_url , str ( usr ) , <EOL> str ( pswd ) ] , <EOL> cwd = "<STR_LIT>" ) <EOL> except Exception , e : <EOL> utility . Msg ( e , LOG . DEBUG ) <EOL> res = e <EOL> return res <EOL> def invkdeploy ( version , url , local_url , random_int ) : <EOL> """<STR_LIT:U+0020>""" <EOL> res = None <EOL> creds = None <EOL> if state . usr_auth != None : <EOL> creds = state . usr_auth . split ( '<STR_LIT::>' ) <EOL> try : <EOL> if creds != None : <EOL> res = check_output ( [ "<STR_LIT>" , version , url , <EOL> local_url , str ( random_int ) , creds [ <NUM_LIT:0> ] , creds [ <NUM_LIT:1> ] ] , <EOL> cwd = "<STR_LIT>" , stderr = STDOUT ) <EOL> else : <EOL> res = check_output ( [ "<STR_LIT>" , version , url , <EOL> local_url , str ( random_int ) ] , <EOL> cwd = "<STR_LIT>" , stderr = STDOUT ) <EOL> except Exception , e : <EOL> utility . Msg ( e , LOG . DEBUG ) <EOL> res = str ( e ) <EOL> return res <EOL> def bsh_deploy ( arch , url , version , usr = None , pswd = None ) : <EOL> """<STR_LIT>""" <EOL> res = None <EOL> try : <EOL> res = check_output ( [ "<STR_LIT>" , url , arch , version , <EOL> str ( usr ) , str ( pswd ) ] , <EOL> cwd = "<STR_LIT>" ) <EOL> except Exception , e : <EOL> utility . Msg ( e , LOG . DEBUG ) <EOL> res = e <EOL> return res <EOL> def deploy_list ( usr_platform = None ) : <EOL> """<STR_LIT>""" <EOL> for platform in state . supported_platforms : <EOL> if usr_platform != '<STR_LIT>' and usr_platform != platform : <EOL> continue <EOL> utility . Msg ( "<STR_LIT>" % platform , LOG . UPDATE ) <EOL> load = importlib . import_module ( '<STR_LIT>' % platform ) <EOL> modules = list ( pkgutil . iter_modules ( load . __path__ ) ) <EOL> if len ( modules ) <= <NUM_LIT:0> : <EOL> utility . Msg ( "<STR_LIT>" ) <EOL> continue <EOL> for deployer in modules : <EOL> try : <EOL> dp = deployer [ <NUM_LIT:0> ] . find_module ( deployer [ <NUM_LIT:1> ] ) . load_module ( deployer [ <NUM_LIT:1> ] ) <EOL> if '<STR_LIT>' in dp . versions : dp . versions . remove ( "<STR_LIT>" ) <EOL> utility . Msg ( "<STR_LIT>" % ( dp . title , deployer [ <NUM_LIT:1> ] , <EOL> '<STR_LIT:|>' . join ( dp . versions ) ) ) <EOL> except Exception , e : <EOL> utility . Msg ( e , LOG . DEBUG ) <EOL> continue <EOL> def auxiliary_list ( usr_platform = None ) : <EOL> """<STR_LIT>""" <EOL> for platform in state . supported_platforms : <EOL> if usr_platform != '<STR_LIT>' and usr_platform != platform : <EOL> continue <EOL> utility . Msg ( "<STR_LIT>" % platform , LOG . UPDATE ) <EOL> load = importlib . import_module ( '<STR_LIT>' % platform ) <EOL> modules = list ( pkgutil . iter_modules ( load . __path__ ) ) <EOL> if len ( modules ) <= <NUM_LIT:0> : <EOL> utility . Msg ( "<STR_LIT>" ) <EOL> continue <EOL> for auxiliary in modules : <EOL> try : <EOL> aux = auxiliary [ <NUM_LIT:0> ] . find_module ( auxiliary [ <NUM_LIT:1> ] ) . load_module ( auxiliary [ <NUM_LIT:1> ] ) . Auxiliary ( ) <EOL> except : <EOL> utility . Msg ( "<STR_LIT>" % <EOL> auxiliary [ <NUM_LIT:1> ] , LOG . DEBUG ) <EOL> utility . Msg ( "<STR_LIT>" % ( aux . name , <EOL> '<STR_LIT:|>' . join ( aux . versions ) , aux . flag ) ) <EOL> def parse_war_path ( war , include_war = False ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT:/>' in war : <EOL> war = war . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> if include_war : <EOL> return war <EOL> else : <EOL> return war . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> def killServe ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> get ( "<STR_LIT>" % state . external_port , timeout = <NUM_LIT:1.0> ) <EOL> except : <EOL> pass </s>
