当前位置: 首页>>代码示例>>Python>>正文


Python DictOp.addconf方法代码示例

本文整理汇总了Python中karesansui.lib.dict_op.DictOp.addconf方法的典型用法代码示例。如果您正苦于以下问题:Python DictOp.addconf方法的具体用法?Python DictOp.addconf怎么用?Python DictOp.addconf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karesansui.lib.dict_op.DictOp的用法示例。


在下文中一共展示了DictOp.addconf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _new_lines

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def _new_lines(self,search_key,new_key):

        try:
            attrs = self.dop.get(self._module,search_key,with_attr=True)
            action    = attrs['action']
            iscomment = attrs['comment']
            val       = attrs['value']
        except:
            action    = self.dop.action(self._module,search_key)
            iscomment = self.dop.iscomment(self._module,search_key)
            val       = self.dop.get(self._module,search_key)
            pass

        #print val
        dop = DictOp()
        dop.addconf('__',{})
        if action == "delete":
            dop.add('__',new_key,val)
            dop.delete('__',new_key)
        elif action == "set":
            dop.set('__',new_key,val)
        else:
            dop.add('__',new_key,val)
        if iscomment is True:
            dop.comment('__',new_key)

        #preprint_r(dop.getconf('__'))
        new_lines = self._value_to_lines(dop.getconf('__'))
        #print "\n".join(new_lines)

        return new_lines
开发者ID:AdUser,项目名称:karesansui,代码行数:33,代码来源:xml_like_conf_parser.py

示例2: _get_iscsi_config

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
def _get_iscsi_config(node):
    path = iscsi_get_config_path_node(node)
    parser = iscsidParser()
    dop = DictOp()

    dop.addconf(MODULE, parser.read_conf(path))
    return dop
开发者ID:goura,项目名称:karesansui,代码行数:9,代码来源:iscsi.py

示例3: convert_old_style

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def convert_old_style(self, conf_arr):

        dop = DictOp()
        dop.addconf("__",{})
        orders = []
        for cnt in range(0,20):
            try:
                try:
                    exec("action  = conf_arr['ADDRESS%d']['action']" % cnt)
                except:
                    action = None

                exec("address = conf_arr['ADDRESS%d']['value']" % cnt)
                exec("netmask = conf_arr['NETMASK%d']['value']" % cnt)
                exec("gateway = conf_arr['GATEWAY%d']['value']" % cnt)

                target = "%s/%s" % (address,netmask,)
                net = NetworkAddress(target)
                try:
                    target = net.cidr
                except:
                    pass
                dop.add("__",[target],gateway)

                if action == "delete":
                    dop.delete("__",[target])

                orders.append([target])
            except:
                pass

        if len(orders) != 0:
            dop.add("__",['@ORDERS'],orders)

        return dop.getconf("__")
开发者ID:goura,项目名称:karesansui,代码行数:37,代码来源:staticroute.py

示例4: __init__

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
class nullParser:

    _comment     = ""

    _module      = "null_parser"

    def __init__(self,paths=[]):
        self.dop = DictOp()
        self.dop.addconf(self._module,{})
        self.set_source_file(paths)

    def set_comment(self, comment=""):
        self._comment = comment

    def set_source_file(self,paths=[]):
        if type(paths) == str:
            paths = [paths]
        self.paths = paths
        return True

    def get_source_file(self):
        return self.paths

    def source_file(self):
        return self.get_source_file()

    def read_conf(self):
        return self.dop.getconf(self._module)

    def write_conf(self,conf_arr={},dryrun=False):
        retval = True
        return retval
开发者ID:AdUser,项目名称:karesansui,代码行数:34,代码来源:null_parser.py

示例5: convert_new_style

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def convert_new_style(self, conf_arr):

        dop = DictOp()
        dop.addconf("__",{})
        orders = []

        try:
            old_orders = conf_arr['@ORDERS']['value']
        except:
            old_orders = []

        cnt = 0
        for _k,_v in conf_arr.iteritems():

            if _k[0] != "@":
                net = NetworkAddress(_k)
                try:
                    ipaddr  = net.ipaddr
                    netmask = net.netmask
                    gateway = _v['value']
                    try:
                        action = _v['action']
                    except:
                        action = None
                    try:
                        index = old_orders.index([_k])
                    except:
                        index = cnt

                    dop.add("__",["ADDRESS%d" % index],ipaddr)
                    if action == "delete":
                        dop.delete("__",["ADDRESS%d" % index])
                    orders.insert(cnt*3+0,["ADDRESS%d" % index])

                    dop.add("__",["NETMASK%d" % index],netmask)
                    if action == "delete":
                        dop.delete("__",["NETMASK%d" % index])
                    orders.insert(cnt*3+1,["NETMASK%d" % index])

                    dop.add("__",["GATEWAY%d" % index],gateway)
                    if action == "delete":
                        dop.delete("__",["GATEWAY%d" % index])
                    orders.insert(cnt*3+2,["GATEWAY%d" % index])

                    cnt = cnt + 1
                except:
                    pass

        if len(orders) != 0:
            dop.add("__",['@ORDERS'],orders)

        return dop.getconf("__")
开发者ID:goura,项目名称:karesansui,代码行数:54,代码来源:staticroute.py

示例6: process

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(1)

        dop = DictOp()
        modules = opts.module.split(":")
        files   = opts.file.split(":")

        retval = True
        cnt = 0
        for _mod in modules:
            _file = files[cnt]
            try:
                exec("from karesansui.lib.parser.%s import %sParser as Parser" % (_mod,_mod,))

                self.up_progress(5)
                parser = Parser()

                self.up_progress(5)
                if opts.raw is True:
                    raw_str = "Config_Raw_%s = {}\n" % (_mod,)
                    for _src in parser.source_file():
                        raw_str = "%sConfig_Raw_%s['%s'] = \"\"\"%s\"\"\"\n" % (raw_str,_mod,_src,open(_src).read())
                    ConfigFile(_file).write(raw_str)

                else:
                    # 設定ファイルの読み込み
                    extra_args = {}
                    extra_args["include"] = opts.include
                    conf_arr = parser.read_conf(extra_args=extra_args)
                    dop.addconf(_mod,conf_arr)
                    #dop.preprint_r(_mod)

                    # 辞書配列ファイルに書き込み
                    _var = "Config_Dict_%s" % (_mod,)
                    if opts.php is True:
                        _str = python_dict_to_php_array(dop.getconf(_mod),_var)
                        ConfigFile(_file).write(_str)
                    else:
                        ConfigFile(_file).write("%s = %s\n" % (_var,str(dop.getconf(_mod)),))

            finally:
                cnt = cnt + 1

        self.up_progress(10)
        return True
开发者ID:fkei,项目名称:karesansui,代码行数:49,代码来源:read_conf.py

示例7: _PUT

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def _PUT(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        host = findbyhost1(self.orm, host_id)
        if not validates_iptables_save(self, host):
            return web.badrequest(self.view.alert)

        from karesansui.lib.dict_op import DictOp
        dop = DictOp()
        dop.addconf("iptables", {})
        dop.set("iptables",["config"],self.input.iptables_save.split("\r\n"))
        retval = write_conf(dop, self, host)
        if retval is False:
            return web.internalerror('Internal Server Error. (Adding Task)')

        return web.accepted(url=web.ctx.path)
开发者ID:AdUser,项目名称:karesansui,代码行数:19,代码来源:hostby1iptables.py

示例8: __init__

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
class iscsidParser:

    _module = "hosts"

    def __init__(self):
        self.dop = DictOp()
        self.dop.addconf(self._module,{})

        self.parser = Parser()
        self.parser.set_delim("[ \t]*=[ \t]*")
        self.parser.set_new_delim(" = ")
        self.parser.set_comment("#")
        self.base_parser_name = self.parser.__class__.__name__
        pass

    def set_footer(self, footer=""):
        self.parser.set_footer(footer)

    def source_file(self):
        retval = [ISCSI_DEFAULT_CONFIG_PATH]

        return retval

    def read_conf(self, conf_path=None, extra_args=None):
        retval = {}

        if conf_path is None:
            conf_path = ISCSI_DEFAULT_CONFIG_PATH

        self.parser.set_source_file([conf_path])
        conf_arr = self.parser.read_conf()
        try:
            self.dop.addconf(self._module,conf_arr[conf_path]['value'])
        except:
            pass

        self.dop.set(self._module,['@BASE_PARSER'],self.base_parser_name)
        #self.dop.preprint_r(self._module)
        return self.dop.getconf(self._module)

    def write_conf(self, conf_arr={}, conf_path=None, extra_args=None, dryrun=False):
        retval = True

        if conf_path is None:
            conf_path = ISCSI_DEFAULT_CONFIG_PATH

        try:
            self.dop.addconf("parser",{})
            self.dop.set("parser",[conf_path],conf_arr)
            #self.dop.preprint_r("parser")
            arr = self.dop.getconf("parser")
            self.parser.write_conf(arr,dryrun=dryrun)
        except:
            pass

        return retval
开发者ID:AdUser,项目名称:karesansui,代码行数:58,代码来源:iscsid.py

示例9: _pre_write_conf

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def _pre_write_conf(self,conf_arr={}):

        # Change permission to be able to read/write data kss group.
        if os.path.exists(COLLECTD_DATA_DIR):
            if os.getuid() == 0:
                r_chgrp(COLLECTD_DATA_DIR,KARESANSUI_GROUP)
                r_chmod(COLLECTD_DATA_DIR,"g+rwx")
                r_chmod(COLLECTD_DATA_DIR,"o-rwx")

        dop = DictOp()
        dop.addconf("__",conf_arr)

        if dop.isset("__",["python"]) is True:
            dop.cdp_unset("__",["python","Plugin","python","@ORDERS"],multiple_file=True)
            orders = []
            orders.append(['Encoding'])
            orders.append(['LogTraces'])
            orders.append(['Interactive'])
            orders.append(['ModulePath'])
            orders.append(['Import'])
            orders.append(['Module'])
            dop.cdp_set("__",["python","Plugin","python","@ORDERS"],orders,is_opt_multi=True,multiple_file=True)

        return dop.getconf("__")
开发者ID:AdUser,项目名称:karesansui,代码行数:26,代码来源:collectdplugin.py

示例10: __init__

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
class modprobe_confParser:

    _module = "modprobe_conf"

    def __init__(self):
        self.dop = DictOp()
        self.dop.addconf(self._module,{})

        self.parser = Parser()
        self.parser.set_delim(" ")
        self.parser.set_new_delim(" ")
        self.parser.set_comment("#")
        self.base_parser_name = self.parser.__class__.__name__

        pass

    def source_file(self):
        retval = [PARSER_MODPROBE_CONF]

        return retval

    def read_conf(self,extra_args=None):
        retval = {}

        self.parser.set_source_file([PARSER_MODPROBE_CONF])
        conf_arr = self.parser.read_conf()
        try:
            self.dop.addconf(self._module,conf_arr[PARSER_MODPROBE_CONF]['value'])
        except:
            pass

        self.dop.set(self._module,['@BASE_PARSER'],self.base_parser_name)
        #self.dop.preprint_r(self._module)
        return self.dop.getconf(self._module)

    def write_conf(self,conf_arr={},extra_args=None,dryrun=False):
        retval = True

        try:
            self.dop.addconf("parser",{})
            self.dop.set("parser",[PARSER_MODPROBE_CONF],conf_arr)
            #self.dop.preprint_r("parser")
            arr = self.dop.getconf("parser")
            self.parser.write_conf(arr,dryrun=dryrun)
        except:
            pass

        return retval
开发者ID:goura,项目名称:karesansui,代码行数:50,代码来源:modprobe_conf.py

示例11: process

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        config_path = iscsi_get_config_path(opts.host, opts.iqn, opts.port, opts.tpgt)
        parser = iscsidParser()
        dop = DictOp()
        dop.addconf("new", parser.read_conf(config_path))

        self.up_progress(10)

        dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth)
        if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP:
            password = ""
            if opts.password is not None:
                password = opts.password
            elif opts.password_file is not None and is_readable(opts.password_file):
                try:
                    fp = open(opts.password_file, "r")
                    try:
                        fcntl.lockf(fp.fileno(), fcntl.LOCK_SH)
                        try:
                            password = fp.readline().strip("\n")
                        finally:
                            fcntl.lockf(fp.fileno(), fcntl.LOCK_UN)

                        self.up_progress(10)
                    finally:
                        fp.close()

                except:
                    raise KssCommandException('Failed to read file. - target host=%s password_file=%s' \
                                                  % (opts.host,opts.password_file))

                try:
                    os.remove(opts.password_file)
                except:
                    raise KssCommandException('Failed to remove file. - target host=%s password_file=%s' \
                                                  % (opts.host,opts.password_file))

            dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_USER, opts.user)
            dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD, password)
        else:
            dop.comment("new", ISCSI_CONFIG_KEY_AUTH_USER)
            dop.comment("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD)

        self.up_progress(10)
        if opts.autostart:
            dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_ON)
        else:
            dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_OFF)

        self.up_progress(10)
        parser.write_conf(dop.getconf("new"), config_path)
        self.up_progress(30)

        self.logger.info("Updated iSCSI node. - host=%s iqn=%s" % (opts.host, opts.iqn))
        print >>sys.stdout, _("Updated iSCSI node. - host=%s iqn=%s") % (opts.host, opts.iqn)

        return True
开发者ID:goura,项目名称:karesansui,代码行数:63,代码来源:update_iscsi.py

示例12: _value_to_lines

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def _value_to_lines(self,conf_arr,level=0):
        lines = []
        orders_key = "%sORDERS" % (self._reserved_key_prefix,)

        dop = DictOp()
        dop.addconf("__",conf_arr)

        for _k,_v in dop.getconf("__").iteritems():

            action = dop.action("__",[_k])
            if action == "delete":
                continue

            iscomment = dop.iscomment("__",[_k])

            value = dop.get("__",[_k])

            if type(value) == list:

                _val          = value[0]

                if type(_val) != dict:
                    _pre_comment  = value[1][0]
                    _post_comment = value[1][1]

                    pre_comment = []
                    try:
                        for _aline in _pre_comment:
                            if _aline.strip() == "":
                                pass
                            elif _aline[0:1] != self._comment:
                                _prefix = ""
                                if level > 0:
                                    _prefix += str_repeat(self._indent,level)
                                _prefix += self._comment
                                _aline = "%s %s" % (_prefix,_aline,)
                            pre_comment.append(_aline)
                    except:
                        pass

                    if len(pre_comment) > 0:
                        #preprint_r(pre_comment)
                        lines = lines + pre_comment

                    post_comment = _post_comment
                    try:
                        if post_comment is not None and post_comment[0:1] != self._comment:
                            post_comment = "%s %s" % (self._comment,post_comment,)
                    except:
                        pass
                else:
                    pass

            else:
                _val = value

            _prefix = ""
            if iscomment is True:
                _prefix += self._comment
            if level > 0:
                _prefix += str_repeat(self._indent,level)

            if type(_val) == dict:

                # ORDER順に設定する
                orders = []
                try:
                    old_orders = _val[orders_key]['value']
                except:
                    old_orders = []

                for kk in old_orders:
                    if type(kk) is list:
                        orders.append(kk[0])
                    elif type(kk) is str:
                        orders.append(kk)

                for kk in _val.keys():
                    if not kk in orders:
                        orders.append(kk)

                #for _k2,_v2 in _val.iteritems():
                for _k2 in orders:

                    if _k2 == orders_key:
                        continue
                    _v2 = _val[_k2]

                    sub_value = {}
                    sub_value[_k2] = _v2

                    try:
                        iscomment = sub_value[_k2]['comment']
                    except:
                        iscomment = False

                    try:
                        action = sub_value[_k2]['action']
                    except:
                        action = ""
#.........这里部分代码省略.........
开发者ID:AdUser,项目名称:karesansui,代码行数:103,代码来源:xml_like_conf_parser.py

示例13: _read_conf

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def _read_conf(self,lines,level=0):

        dop = DictOp()
        dop.addconf("__",{})

        pre_comment  = []   # 設定の前のコメント リスト配列
        post_comment = None # 設定行のコメント 文字列
        _in_section = False
        _res = []
        for _aline in lines:

            if _in_section is True:
                regex = "[ \t]*(?P<comment>#*)[ \t]*</(?P<key>%s)>" % _section_key #'|'.join(self.opt_sect)
                _regex = re.compile(r"%s" % regex)
                m = _regex.match(_aline)
                if m:
                    _comment = m.group('comment')
                    _key     = m.group('key').strip()
                    values = self.build_value(self._read_conf(_res,level),pre_comment,post_comment)
                    dop.set("__",[_key,_section_val],values)
                    if _comment != "":
                        dop.comment("__",[_key,_section_val])
                    if level == 1:
                        self.orders.append([_key,_section_val])
                    pre_comment  = []
                    post_comment = None
                    _in_section = False
                    _res = []
                    level = level - 1
                else:
                    _res.append(_aline)

            else:

                _aline = _aline.rstrip('\r\n')

                if _aline.strip() == "":
                    pre_comment.append(_aline)
                    continue

                match = False
                for _type in ['uni','multi','sect']:
                    exec("regex = '|'.join(self.opt_%s)" % _type)
                    if _type == "sect":
                        regex = "[ \t]*(?P<comment>#*)[ \t]*<(?P<key>%s)(?P<section>.*)>" % regex
                    elif _type == "multi":
                        regex = "[ \t]*(?P<comment>#*)[ \t]*(?P<key>%s)[ \t]+(?P<value>.+)"  % regex
                    elif _type == "uni":
                        regex = "[ \t]*(?P<comment>#*)[ \t]*(?P<key>%s)[ \t]+(?P<value>.+)"  % regex

                    _regex = re.compile(r"%s" % regex)
                    m = _regex.match(_aline)
                    if m:
                        match = True
                        _comment = m.group('comment')
                        _key     = m.group('key').strip()
                        if _type == "sect":
                            _section_key = _key
                            _section_val = re.sub(r"[\"']","",m.group('section').strip())
                            _in_section = True
                            level = level + 1
                        elif _type == "multi":
                            _value = m.group('value').strip()
                            if _value.find(self._comment) > 0:
                                post_comment = _value[_value.find(self._comment):]
                            _value = re.sub("%s$" % post_comment, "", _value).rstrip()
                            values = self.build_value(_value,pre_comment,post_comment)
                            dop.set("__",[_key,_value],values)
                            if _comment != "":
                                dop.comment("__",[_key,_value])
                            if level == 0:
                                self.orders.append([_key,_value])
                            pre_comment  = []
                            post_comment = None
                        elif _type == "uni":
                            _value   = m.group('value').strip()
                            if _value.find(self._comment) > 0:
                                post_comment = _value[_value.find(self._comment):]
                            _value = re.sub("%s$" % post_comment, "", _value).rstrip()
                            values = self.build_value(_value,pre_comment,post_comment)
                            dop.set("__",[_key],values)
                            if _comment != "":
                                dop.comment("__",[_key])
                            if level == 0:
                                self.orders.append([_key])
                            pre_comment  = []
                            post_comment = None
                        break

                if match is False:

                    # ブラケットディレクティブのパラメータは除外する (よって、ブラケットディレクティブは全ての定義が必要!)
                    # example: "<undefined_directive 'foobar'>"
                    regex_exclude1 = "[ \t]*(?P<comment>#*)[ \t]*(?P<key>%s)[ \t]" % '|'.join(self.opt_sect)
                    _regex_exclude1 = re.compile(r"%s" % regex_exclude1)

                    # 未定義のパラメータの値がクオートせずにスペース区切りで3つ以上の値を指定している場合はコメント行とみなす
                    # example: "# Read this configuration file"
                    regex_exclude2 = "[ \t]*#+[ \t]*[^ \t]+([ \t]+[^ \t]+){3,}"
                    _regex_exclude2 = re.compile(r"%s" % regex_exclude2)
#.........这里部分代码省略.........
开发者ID:AdUser,项目名称:karesansui,代码行数:103,代码来源:xml_like_conf_parser.py

示例14: __init__

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
class lineParser:

    _comment     = ""

    _module      = "line_parser"

    def __init__(self,paths=[]):
        self.dop = DictOp()
        self.dop.addconf(self._module,{})
        self.set_source_file(paths)

    def set_comment(self, comment=""):
        self._comment = comment

    def set_source_file(self,paths=[]):
        if type(paths) == str:
            paths = [paths]
        self.paths = paths
        return True

    def get_source_file(self):
        return self.paths

    def source_file(self):
        return self.get_source_file()

    def read_conf(self):
        retval = {}

        for _afile in self.source_file():
            if _afile[0:4] == "cmd:":
                command_args = _afile[4:].split()
                (ret,res) = execute_command(command_args)
            else:
                res = ConfigFile(_afile).read()

            new_res = []
            for _aline in res:
                _aline = _aline.rstrip('\r\n')
                if self._comment != "" and not _aline.rfind(self._comment) == -1:
                    _aline = _aline[:_aline.rfind(self._comment)]
                if _aline != "":
                    new_res.append(_aline)
            self.dop.set(self._module,[_afile],new_res)

        #self.dop.preprint_r(self._module)
        return self.dop.getconf(self._module)

    def write_conf(self,conf_arr={},dryrun=False):
        retval = True

        for _path,_v in conf_arr.iteritems():

            if _path[0:1] != "/":
                continue

            try:
                _v['value']
            except:
                continue

            if dryrun is False:
                ConfigFile(_path).write("\n".join(_v['value']) + "\n")
            else:
                print "\n".join(_v['value'])

        return retval
开发者ID:goura,项目名称:karesansui,代码行数:69,代码来源:line_parser.py

示例15: process

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import addconf [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(1)

        uniq_id = time.strftime("%Y%m%d%H%M%S", time.localtime())

        if opts.pre_command is not None:
            if opts.pre_command[0:4] == "b64:":
                command = base64_decode(opts.pre_command[4:])
            else:
                command = opts.pre_command
            self.logger.info("execute command - %s" % command)
            (_ret,_res) = execute_command(command.split())
            if _ret != 0:
                error_msg = "execute error - %s" % command
                self.logger.error(error_msg)
                #raise KssCommandOptException("ERROR: %s" % error_msg)

        dop = DictOp()
        modules = opts.module.split(":")
        files   = opts.file.split(":")

        source_files = []
        retval = True
        cnt = 0
        for _mod in modules:
            _file = files[cnt]
            try:
                exec("from karesansui.lib.parser.%s import %sParser as Parser" % (_mod,_mod,))

                self.up_progress(5)
                parser = Parser()

                # 辞書オペレータに追加
                self.up_progress(5)
                if opts.php is True:
                    conf_arr = php_array_to_python_dict(open(_file).read())
                else:
                    exec("conf_arr = %s" % open(_file).read())
                dop.addconf(_mod,conf_arr)

                """
                必要ならここで配列操作
                通常は、配列操作後の辞書が_fileに書き込まれているので必要ない
                dop.add   (_mod,"foo","bar")
                dop.delete(_mod,"foo")
                """

                # 設定ファイル一覧に作成(バックアップ用)
                self.up_progress(5)
                source_file = parser.source_file()
                for _afile in source_file:
                    _bak_afile = "%s.%s" % (_afile,uniq_id)
                    copy_file(_afile,_bak_afile)
                source_files = source_files + source_file

                # 辞書に戻す
                self.up_progress(5)
                conf_arr = dop.getconf(_mod)
                #dop.preprint_r(_mod)

                # 設定ファイルに書き込み
                self.up_progress(5)
                extra_args = {}
                extra_args["include"] = opts.include
                if opts.early_exit is True:
                    retval = retval and parser.write_conf(conf_arr,extra_args=extra_args)
                else:
                    retval = parser.write_conf(conf_arr,extra_args=extra_args) and retval

                if opts.delete is True:
                    os.unlink(_file)

            finally:
                cnt = cnt + 1

        if retval is False:
            for _afile in source_files:
                _bak_afile = "%s.%s" % (_afile,uniq_id)
                os.unlink(_afile)
                copy_file(_bak_afile,_afile)
                os.unlink(_bak_afile)
            raise KssCommandOptException("ERROR: write configure failure")

        for _afile in source_files:
            _bak_afile = "%s.%s" % (_afile,uniq_id)
            os.unlink(_bak_afile)

        if opts.post_command is not None:
            if opts.post_command[0:4] == "b64:":
                command = base64_decode(opts.post_command[4:])
            else:
                command = opts.post_command
            self.logger.info("execute command - %s" % command)
            (_ret,_res) = execute_command(command.split())
            if _ret != 0:
                error_msg = "execute error - %s" % command
                self.logger.error(error_msg)
                raise KssCommandOptException("ERROR: %s" % error_msg)
#.........这里部分代码省略.........
开发者ID:AdUser,项目名称:karesansui,代码行数:103,代码来源:write_conf.py


注:本文中的karesansui.lib.dict_op.DictOp.addconf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。