Ejemplo n.º 1
0
 def check(self):
     if not type(self.subs) == type([]):
         raise error.icmd_exception("%s.subs is not  []  " % (self.name))
     if not type(self.args) == type([]):
         raise error.icmd_exception("%s.args is not  []  " % (self.name))
     if self.name == "":
         raise error.icmd_exception("cmd not set name" % (self.name))
Ejemplo n.º 2
0
 def getcmd(self, val):
     if val == None:
         if isinstance(self.default, pipe):
             vals = self.default.get()
             if len(vals) > 0:
                 val = vals[0].strip()
     if val == None:
         raise error.icmd_exception("arg %s not set value" % (self.name))
     if self.call is None:
         return "--%s %s" % (self.name, val)
     else:
         try:
             debug_log(self.call, 'call')
             return string.Template(self.call).substitute({self.name: val})
         except:
             raise error.icmd_exception(
                 "error! args call:[%s], but key is: %s" %
                 (self.call, self.name))
Ejemplo n.º 3
0
def value_of(string, flag='$'):
    tpl = string
    var_exp = re.compile("\%s\{(\w+)\}" % (flag))
    ass = assigner(tpl, os.environ)
    try:
        while var_exp.search(tpl):
            tpl = var_exp.sub(ass.assign_value, tpl)
    except TypeError as e:
        raise error.icmd_exception(tpl + "tpl proc fail!")
    return tpl
Ejemplo n.º 4
0
    def get(self):
        self.cmd = value_of(self.cmd, '&')
        self.args = value_of(self.args, '&')

        if not os.path.exists(self.cmd):
            raise error.icmd_exception("cmd is not exists : %s" % (self.cmd))
        args = self.args.split(' ')
        args = [self.cmd] + args
        _logger.info("cmd: %r" % (args))
        p = Popen(args, bufsize=1024, stdout=PIPE, close_fds=True)
        return p.stdout.readlines()
Ejemplo n.º 5
0
def not_none(val, errmsg):
    if val is None:
        raise error.icmd_exception(errmsg)
    return val
Ejemplo n.º 6
0
def must_exists(path):
    if path is None or not os.path.exists(path):
        raise error.icmd_exception("file not exists : %s" % path)
Ejemplo n.º 7
0
def ok(val, errmsg):
    if not val:
        raise error.icmd_exception(errmsg)
    return val
Ejemplo n.º 8
0
def must_true(val, errmsg):
    if not val == True:
        raise error.icmd_exception(errmsg)
    return val