Exemple #1
0
 def replace(self, matchobj):
     filepath = matchobj.groups()[0]
     filepath = re.sub("^\.", self.curpath, filepath)
     filepath = env_exp.value(filepath)
     rg_logger.debug("import yaml:%s", filepath)
     doc = open(filepath).read()
     return doc
Exemple #2
0
 def replace(self, matchobj):
     filepath = matchobj.groups()[0]
     filepath = re.sub("^\.", self.curpath, filepath)
     filepath = env_exp.value(filepath)
     rg_logger.debug("import yaml:%s", filepath)
     doc = open(filepath).read()
     return doc
 def proc_single_file(self, src, dst):
     rgrg_logger.info( "proc single tpl file: %s -> %s" %(src,dst) )
     if dst and os.path.isdir(dst):
         dst = sys.stdout
     elif dst and os.path.isfile(dst):
         rg_logger.debug( "overwriten exsits file: %s" %(dst) )
     self.ng.file( src  , dst )
 def proc_single_file(self, src, dst):
     rgrg_logger.info("proc single tpl file: %s -> %s" % (src, dst))
     if dst and os.path.isdir(dst):
         dst = sys.stdout
     elif dst and os.path.isfile(dst):
         rg_logger.debug("overwriten exsits file: %s" % (dst))
     self.ng.file(src, dst)
 def __call__(self, match):
     var = str(match.group(1))
     val = getattr(self.tpl_vars, var)
     rg_logger.debug("path is pass %s : %s" % (var, val))
     if val == 'FALSE' or len(val.strip()) == 0:
         self.passed = True
     if val == 'TRUE':
         val = ""
     return val
Exemple #6
0
 def _before(self, context):
     # import pdb
     # pdb.set_trace()
     vars_data = self.vars_data()
     for name, val in vars_data.items():
         name = name.upper()
         rg_logger.debug("%s =%s" % (name, val))
         setattr(context, name, val)
     utls.rg_var.import_dict(vars_data)
Exemple #7
0
 def _before(self,context):
     # import pdb
     # pdb.set_trace()
     vars_data = self.vars_data()
     for name , val in   vars_data.items():
         name= name.upper()
         rg_logger.debug("%s =%s" %(name,val))
         setattr(context,name,val)
     utls.rg_var.import_dict(vars_data)
 def __call__(self,match):
     var = str(match.group(1))
     val = getattr(self.tpl_vars,var)
     rg_logger.debug( "path is pass %s : %s" %(var,val))
     if val == 'FALSE' or   len(val.strip()) == 0 :
         self.passed = True
     if val == 'TRUE' :
         val = ""
     return val
Exemple #9
0
def list_res() :
    import  res
    for name,module in interface.registed_resource.items() :
        code = "obj = res.%s()" %(name)
        rg_logger.debug("exec code : %s" %code)
        try :
            exec code
            utls.rg_io.export_objdoc(name,obj )
        except  Exception as e :
            raise interface.rigger_exception("@list_res() code error: %s \n %s" %(code,e) )
Exemple #10
0
def list_cmd() :
    import  impl.rg_cmd
    for name in interface.cmds_index :
        code = "obj = impl.rg_cmd.%s_cmd()" %(name)
        rg_logger.debug("exec code : %s" %code)
        try :
            exec code
            utls.rg_io.export_objdoc(name,obj )
        except  Exception as e :
            raise interface.rigger_exception("@list_cmd() code error: %s \n %s" %(code,e) )
Exemple #11
0
def list_cmd():
    import impl.rg_cmd
    for name, module in interface.registed_cmd.items():
        code = "obj = impl.rg_cmd.%s_cmd()" % (name)
        rg_logger.debug("exec code : %s" % code)
        try:
            exec code
            utls.rg_io.export_objdoc(name, obj)
        except Exception as e:
            raise interface.rigger_exception(
                "@list_cmd() code error: %s \n %s" % (code, e))
Exemple #12
0
def parse_assgin(defstr):
    """x=1,y=2 """
    res={}
    for ass  in defstr.split(','):
        match = re.match(r'(\w+)=(.+)',ass)
        if match:

            key = match.group(1).strip()
            val = match.group(2).strip()
            rg_logger.debug( "parse %s:%s " %(key,val))
            res[key]=val
    return res
Exemple #13
0
def list_res():
    import res
    sorted_res = sorted(interface.registed_resource)
    for name in sorted_res:
        code = "obj = res.%s()" % (name)
        rg_logger.debug("exec code : %s" % code)
        try:
            exec code
            utls.rg_io.export_objdoc(name, obj)
        except Exception as e:
            raise interface.rigger_exception(
                "@list_res() code error: %s \n %s" % (code, e))
Exemple #14
0
def parse_assign(defstr):
    """x=1,y=2 """
    res={}
    for ass  in defstr.split(','):
        match = re.match(r'(\w+)=(.+)',ass)
        if match:

            key = match.group(1).strip()
            val = match.group(2).strip()
            rg_logger.debug( "parse %s:%s " %(key,val))
            res[key]=val
    return res
Exemple #15
0
def ins_cmd(name) :
    import  impl.rg_cmd
    for cmd,module in interface.registed_cmd.items() :
        if  cmd == name :
            code = "obj = impl.rg_cmd.%s_cmd()" %(name)
            rg_logger.debug("exec code : %s" %code)
            try :
                exec code
                return obj
            except  Exception as e :
                raise interface.rigger_exception("@ins_cmd() code error: %s \n %s" %(code,e) )
    return None
Exemple #16
0
def ins_res(name) :
    import  res
    for res_name,module in interface.registed_resource.items() :
        if  res_name == name :
            code = "obj = res.%s()" %(name)
            rg_logger.debug("exec code : %s" %code)
            try :
                exec code
                return obj
            except  Exception as e :
                raise interface.rigger_exception("@ins_res() code error: %s \n %s" %(code,e) )
    return None
Exemple #17
0
    def _before(self,context):
        # import pdb
        # pdb.set_trace()
        items = self.__dict__

        for name , val in   items.items():
            if re.match(r'__.+__',name):
                continue
            name= name.upper()
            rg_logger.debug("%s =%s" %(name,val))
            setattr(context,name,val)
        utls.rg_var.import_dict(items)
 def execute(self,src,dst):
     self.src = src
     self.dst = dst
     rg_logger.debug("src: %s dst: %s" %(src,dst))
     if not os.path.exists(src):
         raise interface.rigger_exception("tpl src not found : %s" %src)
     self.ng = engine( src + "/_tpl.yaml")
     #process single file
     if os.path.isfile(src):
         self.proc_single_file(self.src, self.dst)
     else:
     #process dir
         os.path.walk(self.src,self.proc_files,None)
 def execute(self, src, dst):
     self.src = src
     self.dst = dst
     rg_logger.debug("src: %s dst: %s" % (src, dst))
     if not os.path.exists(src):
         raise interface.rigger_exception("tpl src not found : %s" % src)
     self.ng = engine(src + "/_tpl.yaml")
     #process single file
     if os.path.isfile(src):
         self.proc_single_file(self.src, self.dst)
     else:
         #process dir
         os.path.walk(self.src, self.proc_files, None)
Exemple #20
0
def ins_cmd(name):
    import impl.rg_cmd
    for cmd, module in interface.registed_cmd.items():
        if cmd == name:
            code = "obj = impl.rg_cmd.%s_cmd()" % (name)
            rg_logger.debug("exec code : %s" % code)
            try:
                exec code
                return obj
            except Exception as e:
                raise interface.rigger_exception(
                    "@ins_cmd() code error: %s \n %s" % (code, e))
    return None
Exemple #21
0
def ins_res(name):
    import res
    for res_name, module in interface.registed_resource.items():
        if res_name == name:
            code = "obj = res.%s()" % (name)
            rg_logger.debug("exec code : %s" % code)
            try:
                exec code
                return obj
            except Exception as e:
                raise interface.rigger_exception(
                    "@ins_res() code error: %s \n %s" % (code, e))
    return None
    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)
Exemple #24
0
 def __init__(self, conf):
     self.conf = conf
     utls.dbc.must_exists(self.conf)
     self.curpath = os.path.dirname(self.conf)
     rg_logger.debug("yaml current path:%s" % self.curpath)
Exemple #25
0
 def _allow(self,context):
     allowd =  self.allow_res == "ALL"  or self.allow_res == self.clsname()
     if allowd:
         rg_logger.debug( "allowd resource %s ,current resouce is %s " %(self.allow_res,self._resname()))
     return  allowd
 def var_matched(self, match):
     var = str(match.group(1))
     val = getattr(self.tpl_vars, var)
     rg_logger.debug("key[%s] val[%s]" % (var, val))
     return val
Exemple #27
0
 def __init__(self, conf):
     self.conf = conf
     utls.dbc.must_exists(self.conf)
     self.curpath = os.path.dirname(self.conf)
     rg_logger.debug("yaml current path:%s" % self.curpath)
Exemple #28
0
import interface
import logging
from utls.rg_io import rg_logger

if len(interface.registed_resource.items()) == 0:
    raise interface.rigger_exception("@res.__init__ no regist res to module")

for res, module in interface.registed_resource.items():
    code = "from %s import %s" % (module, res)
    rg_logger.debug(" load module: %s" % code)
    try:
        exec code
    except Exception as e:
        raise interface.rigger_exception("@res.__init__ code error: %s \n %s" %
                                         (code, e))
 def var_matched(self,match):
     var = str(match.group(1))
     val = getattr(self.tpl_vars,var)
     rg_logger.debug( "key[%s] val[%s]" %(var,val))
     return val
Exemple #30
0
import interface
import logging

from utls.rg_io import rg_logger

if len(interface.registed_cmd.items()) == 0:
    raise interface.rigger_exception("@cmd.__init__ no regist cmd to module")

for cmd, module in interface.registed_cmd.items():
    code = "from %s import %s_cmd" % (module, cmd)
    rg_logger.debug(" load module: %s" % code)
    try:
        exec code
    except Exception as e:
        raise interface.rigger_exception("@cmd.__init__ code error: %s \n %s" % (code, e))
Exemple #31
0
 def _allow(self,context):
     allowd =  self.allow_res == "ALL"  or self.allow_res == self.__class__.__name__
     if not allowd:
         rg_logger.debug( "not allowd resource %s " %(self._resname()))
     return  allowd
Exemple #32
0
 def _allow(self, context):
     allowd = self.allow_res == "ALL" or self.allow_res == self.clsname()
     if allowd:
         rg_logger.debug("allowd resource %s ,current resouce is %s " %
                         (self.allow_res, self._resname()))
     return allowd