def runcmd(self,rargs,fun,extra=None) : import utls.rg_yaml,copy utls.check.must_exists(rargs.prj.conf) rg_logger.info("load prj conf: %s" %(rargs.prj.conf)) loader = utls.rg_yaml.conf_loader(rargs.prj.conf) data = loader.load_data("!R","res") prj_cmd_base.check_data(data) env_data = data['_env'] sys_data = data['_sys'] if data.has_key('_mod') : for m in data['_mod'] : res.node.regist_mod(m) main = res.prj_main() if len(self.env) == 0 : return #import pdb #pdb.set_trace() for env_obj in env_data : res.node.env_regist(env_obj) if self.env == "@all" : main.append(env_obj) if self.env != "@all" : for need_env in self.env : obj = res.node.env_find(need_env) if obj is not None : main.append(obj) else: raise interface.rigger_exception("env [%s] not found" %(need_env)) for sys_obj in sys_data : res.node.sys_regist(sys_obj) if self.sys == "@all": main.append(sys_obj) if len(self.sys) > 1 and extra is not None : raise interface.rigger_exception("extra obj will execute in muti sys" %(len(self.sys))) if self.sys != "@all" : for need_sys in self.sys : obj = res.node.sys_find(need_sys) if obj is not None : if extra is not None : obj.append(extra) main.append(obj) else : raise interface.rigger_exception("sys [%s] not found" %(need_sys)) context = interface.run_context() project = res.project() project.setup4start(context) interface.control_call(main,fun,context,"unknow")
def _before(self,context): rg_logger.info("env:%s _before" %(self._name)) if self._mix is not None : for key in self._mix.split(",") : obj = res.node.env_find(key) if obj is None : raise interface.rigger_exception("env [%s] : mix [%s] not found " %(self._name,key)) self.append(obj)
def parse_cmd(self): if len(self.cmds) == 0 : raise badargs_exception("没æå½ä»¤") if len(self.cmds) > 1: self.subcmd = self.cmds[1:] rg_logger.info("subcmd: %s" %self.subcmd) cmdarr = self.cmds[0].split(',') return cmdarr
def parse_cmd(self): if len(self.cmds) == 0: raise badargs_exception("没æå½ä»¤") if len(self.cmds) > 1: self.subcmd = self.cmds[1:] rg_logger.info("subcmd: %s" % self.subcmd) cmdarr = self.cmds[0].split(',') return cmdarr
def loadconf(self, rargs): import utls.rg_yaml, copy utls.dbc.must_file(rargs.dev.conf) rg_logger.info("load prj conf: %s" % (rargs.dev.conf)) loader = utls.rg_yaml.conf_loader(rargs.dev.conf) data = loader.load_data("!C", "conf") dev_data = data['_dev'] for confobj in dev_data: confobj._load()
def loadconf(self,rargs) : # import pdb # pdb.set_trace() import utls.rg_yaml,copy utls.dbc.must_exists(rargs.dev.conf) rg_logger.info("load prj conf: %s" %(rargs.dev.conf)) loader = utls.rg_yaml.conf_loader(rargs.dev.conf) data = loader.load_data("!C","conf") dev_data = data['_dev'] for confobj in dev_data : confobj._load()
def run_rigger(rargs, argv) : #TODO: muti cmd support if len(rargs.prj.cmds) == 0 : raise interface.rigger_exception("No Cmd!") cmds = rargs.prj.cmds[0] for cmd in cmds.split(',') : obj = rg_ioc.ins_cmd(cmd) if obj is None : raise interface.rigger_exception( "unfound '%s' cmd instance" %cmd) rg_logger.info("cmd: %s , cmd_ins : %s" %(cmd,obj.__class__.__name__)) obj._config(argv,rargs) obj._execute(rargs)
def _before(self,context): context.use_env(self._name) rg_logger.info("env:%s _before" %(self._name)) mix_obj = [] if self._mix is not None : for key in self._mix.split(",") : obj = interface.res_proxy(res.node.env_find,key,"env") mix_obj.append(obj) # obj = res.node.env_find(key) # if obj is None : # raise interface.rigger_exception("env [%s] : mix [%s] not found " %(self._name,key)) # self.append(obj) self.extend_left(mix_obj)
def run_rigger(rargs, argv): #TODO: muti cmd support if len(rargs.prj.cmds) == 0: raise interface.rigger_exception("No Cmd!") cmds = rargs.prj.cmds[0] for cmd in cmds.split(','): obj = rg_ioc.ins_cmd(cmd) if obj is None: raise interface.rigger_exception("unfound '%s' cmd instance" % cmd) rg_logger.info("cmd: %s , cmd_ins : %s" % (cmd, obj.__class__.__name__)) obj._config(argv, rargs) obj._execute(rargs)
def _before(self, context): context.use_env(self._name) rg_logger.info("env:%s _before" % (self._name)) mix_obj = [] if self._mix is not None: for key in self._mix.split(","): obj = interface.res_proxy(res.node.env_find, key, "env") mix_obj.append(obj) # obj = res.node.env_find(key) # if obj is None : # raise interface.rigger_exception("env [%s] : mix [%s] not found " %(self._name,key)) # self.append(obj) self.extend_left(mix_obj)
def file(self, tplfile, dstfile): tpl = open(tplfile, 'r') isstdout = dstfile == sys.stdout dst = dstfile if isstdout else open(dstfile, 'w') st = tplstatus.NONE block = [] cond = "" expect = None for line in tpl: if st == tplstatus.BLOCK_IN: if self.re_block_end.match(line): st = tplstatus.NONE code = "cond_val = %s" % cond code = code.replace("T.", "self.tpl_vars.") exec code rg_logger.debug(" code in block '%s'[%s]" % (cond, str(cond_val))) if str(cond_val).upper() == expect.upper(): xblock = [] for line in block: rg_logger.debug("proc line: %s" % (line)) xblock.append(self.value(line)) dst.writelines(xblock) block = [] else: block.append(line) continue if st == tplstatus.NONE: code_match = self.re_code.match(line) block_match = self.re_block_beg.match(line) if block_match: st = tplstatus.BLOCK_IN cond = block_match.group(1).strip() expect = block_match.group(2).strip() if len(expect) == 0: expect = "TRUE" pass elif code_match: code = code_match.group(1).strip() code = code.replace("T.", "self.tpl_vars") rg_logger.info(code) exec code else: line = self.value(line) dst.write(line) tpl.close() dst.close() if not isstdout: stat = os.stat(tplfile) os.chmod(dstfile, stat.st_mode)
def file(self,tplfile,dstfile): tpl = open(tplfile, 'r') isstdout = dstfile == sys.stdout dst = dstfile if isstdout else open(dstfile, 'w') st = tplstatus.NONE block = [] cond = "" expect = None for line in tpl: if st == tplstatus.BLOCK_IN: if self.re_block_end.match(line) : st=tplstatus.NONE code = "cond_val = %s" %cond code = code.replace("T.","self.tpl_vars.") exec code rg_logger.debug(" code in block '%s'[%s]" %(cond,str(cond_val)) ) if str(cond_val).upper() == expect.upper() : xblock = [] for line in block : rg_logger.debug("proc line: %s" %(line) ) xblock.append(self.value(line)) dst.writelines(xblock) block = [] else: block.append(line) continue if st == tplstatus.NONE: code_match = self.re_code.match(line) block_match = self.re_block_beg.match(line) if block_match: st=tplstatus.BLOCK_IN cond = block_match.group(1).strip() expect = block_match.group(2).strip() if len(expect) == 0 : expect = "TRUE" pass elif code_match : code = code_match.group(1).strip() code = code.replace("T.","self.tpl_vars") rg_logger.info(code) exec code else: line = self.value(line) dst.write(line) tpl.close() dst.close() if not isstdout: stat = os.stat(tplfile) os.chmod(dstfile,stat.st_mode)
def _before(self,context): rg_logger.info("system:%s _before " %(self._name)) utls.rg_var.keep() context.keep() #support run_path var auto_vars = vars() auto_vars.SYS_NAME = self._name auto_vars.RUN_PATH = "%s/run/%s" %(context.prj.root,self._name) run_path = res.files.path() run_path.dst = auto_vars.RUN_PATH self.push(run_path) self.push(auto_vars)
def _before(self, context): rg_logger.info("system:%s _before " % (self._name)) utls.rg_var.keep() context.keep() #support run_path var auto_vars = vars() auto_vars.SYS_NAME = self._name auto_vars.RUN_PATH = "%s/run/%s" % (context.prj.root, self._name) run_path = res.files.path() run_path.dst = auto_vars.RUN_PATH self.push(run_path) self.push(auto_vars)
def proc_files(self,arg,dirname,names): src_path = dirname relat_path = src_path.replace(self.src,'').lstrip('/') dst_path = os.path.join(self.dst , relat_path) dst_path = self.ng.convert_path(dst_path) if dst_path is None : return rg_logger.info("proc file : src[ %s ] --> dst [%s]" %(src_path,dst_path) ) if not os.path.exists(dst_path): os.makedirs(dst_path) for n in names: src = os.path.join(src_path ,n) dst = self.ng.value(os.path.join(dst_path ,n)) if n != "_tpl.yaml" and not os.path.isdir(src): rg_logger.info( "proc tpl file: %s -> %s" %(src,dst) ) self.ng.file( src , dst )
def _before(self, context): rg_logger.info("system:%s _before " % (self._name)) utls.rg_var.keep() context.keep() base_run = res_utls.value("${BASE_RUN_PATH}") #support run_path var auto_vars = vars() auto_vars.SYS_NAME = self._name auto_vars.RUN_PATH = "%s/%s" % (base_run, self._name) context.run_path = auto_vars.RUN_PATH run_path = res.files.path() run_path.dst = auto_vars.RUN_PATH self.push(run_path) self.push(auto_vars)
def _before(self,context): rg_logger.info("system:%s _before " %(self._name)) utls.rg_var.keep() context.keep() base_run = res_utls.value("${BASE_RUN_PATH}") #support run_path var auto_vars = vars() auto_vars.SYS_NAME = self._name auto_vars.RUN_PATH = "%s/%s" %(base_run,self._name) context.run_path = auto_vars.RUN_PATH run_path = res.files.path() run_path.dst = auto_vars.RUN_PATH self.push(run_path) self.push(auto_vars)
def proc_files(self, arg, dirname, names): src_path = dirname relat_path = src_path.replace(self.src, '').lstrip('/') dst_path = os.path.join(self.dst, relat_path) dst_path = self.ng.convert_path(dst_path) if dst_path is None: return rg_logger.info("proc file : src[ %s ] --> dst [%s]" % (src_path, dst_path)) if not os.path.exists(dst_path): os.makedirs(dst_path) for n in names: src = os.path.join(src_path, n) dst = self.ng.value(os.path.join(dst_path, n)) if n != "_tpl.yaml" and not os.path.isdir(src): rg_logger.info("proc tpl file: %s -> %s" % (src, dst)) self.ng.file(src, dst)
def load(conf_yaml): import utls.rg_yaml, copy rg_logger.info("load prj conf: %s" % (conf_yaml)) loader = utls.rg_yaml.conf_loader(conf_yaml) data = loader.load_data("!R", "res") # print("-------------%s----------" %(conf_yaml)) check_data(data) if data.has_key('_mod'): for m in data['_mod']: res.node.module_regist(m) if data.has_key('_env'): for obj in data['_env']: res.node.env_regist(obj) if data.has_key('_sys'): for obj in data['_sys']: res.node.sys_regist(obj)
def load(conf_yaml) : import utls.rg_yaml,copy rg_logger.info("load prj conf: %s" %(conf_yaml)) loader = utls.rg_yaml.conf_loader(conf_yaml) data = loader.load_data("!R","res") # print("-------------%s----------" %(conf_yaml)) check_data(data) if data.has_key('_mod') : for m in data['_mod'] : res.node.module_regist(m) if data.has_key('_env') : for obj in data['_env']: res.node.env_regist(obj) if data.has_key('_sys') : for obj in data['_sys']: res.node.sys_regist(obj)
def runcmd(self,rargs,fun) : import utls.rg_yaml,copy utls.dbc.must_exists(rargs.prj.conf) rg_logger.info("load prj conf: %s" %(rargs.prj.conf)) loader = utls.rg_yaml.conf_loader(rargs.prj.conf) data = loader.load_data("!R","res") prj_cmd_base.check_data(data) env_data = data['_env'] sys_data = data['_sys'] if data.has_key('_mod') : for m in data['_mod'] : res.node.regist_mod(m) main = res.prj_main() if len(self.env) == 0 : return #import pdb #pdb.set_trace() for env in self.env : for env_obj in env_data : res.node.env_regist(env_obj) if env_obj._name == env : main.append(env_obj) context = interface.run_context() # interface.control_call(main,fun,context) if len(self.sys) > 0 : for sys in self.sys : for sysobj in sys_data : res.node.sys_regist(sysobj) if sysobj._name == sys : main.append(sysobj) # interface.control_call(sysobj,fun,context) interface.control_call(main,fun,context,"unknow")
def runcmd(self, rargs, fun): import utls.rg_yaml, copy utls.dbc.must_exists(rargs.prj.conf) rg_logger.info("load prj conf: %s" % (rargs.prj.conf)) loader = utls.rg_yaml.conf_loader(rargs.prj.conf) data = loader.load_data("!R", "res") prj_cmd_base.check_data(data) env_data = data['_env'] sys_data = data['_sys'] if data.has_key('_mod'): for m in data['_mod']: res.node.regist_mod(m) main = res.prj_main() if len(self.env) == 0: return #import pdb #pdb.set_trace() for env in self.env: for env_obj in env_data: res.node.env_regist(env_obj) if env_obj._name == env: main.append(env_obj) context = interface.run_context() # interface.control_call(main,fun,context) if len(self.sys) > 0: for sys in self.sys: for sysobj in sys_data: res.node.sys_regist(sysobj) if sysobj._name == sys: main.append(sysobj) # interface.control_call(sysobj,fun,context) interface.control_call(main, fun, context, "unknow")
def _before(self,context): rg_logger.info("main: _before")
def _after(self,context): context.rollback() utls.rg_var.rollback() rg_logger.info("system:%s _after" %(self._name))
def _before(self, context): # run_struct.push("modul %s" %(self._name)) rg_logger.info("modul:%s _before" % (self._name)) if self._sandbox: utls.rg_var.keep() context.keep()
def _after(self,context): rg_logger.info("env:%s _after " %(self._name))
def _after(self,context): if self._sandbox: context.rollback() utls.rg_var.rollback() rg_logger.info("modul:%s _after" %(self._name))
def _after(self, context): if self._sandbox: context.rollback() utls.rg_var.rollback() rg_logger.info("modul:%s _after" % (self._name))
def _before(self, context): rg_logger.info("modul:%s _before" % (self._name)) if self._sandbox: utls.rg_var.keep() context.keep() self.load_default_args()
def _after(self, context): rg_logger.info("main: _after")
def _before(self, context): rg_logger.info("main: _before")
def _after(self, context): context.rollback() utls.rg_var.rollback() rg_logger.info("system:%s _after" % (self._name))
def load_args(self,saved ) : if hasattr(saved,'vars_def') and saved.vars_def is not None: if not self.argv.has_key('-v') : self.argv['-v'] = saved.vars_def else: rg_logger.info ( "old prior vars ignore: %s " % rargs.vars_def)
def _after(self,context): rg_logger.info("main: _after")
def _before(self,context): # run_struct.push("modul %s" %(self._name)) rg_logger.info("modul:%s _before" %(self._name)) if self._sandbox: utls.rg_var.keep() context.keep()
def _after(self, context): rg_logger.info("env:%s _after " % (self._name))
def _before(self,context): rg_logger.info("env:%s _before" %(self._name)) if self._mix is not None : for key in self._mix.split(",") : self.append(res.node.env_find(key))
def _before(self, context): rg_logger.info("env:%s _before" % (self._name)) if self._mix is not None: for key in self._mix.split(","): self.append(res.node.env_find(key))
def _before(self,context): rg_logger.info("modul:%s _before" %(self._name)) if self._sandbox: utls.rg_var.keep() context.keep() self.load_default_args()
def load_args(self, saved): if hasattr(saved, 'vars_def') and saved.vars_def is not None: if not self.argv.has_key('-v'): self.argv['-v'] = saved.vars_def else: rg_logger.info("old prior vars ignore: %s " % rargs.vars_def)