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


Python DictOp.add方法代码示例

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


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

示例1: _new_lines

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [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: convert_old_style

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [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

示例3: convert_new_style

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [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

示例4: staticrouteParser

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
        return retval

"""
"""
if __name__ == '__main__':
    """Testing
    """
    parser = staticrouteParser()

    preprint_r(parser.do_status())
    parser.do_add("eth0","5.6.7.0","172.16.0.1")
    parser.do_del("eth0","5.6.7.0")
    preprint_r(parser.do_status())

    conf_arr = parser.read_conf()
    preprint_r(conf_arr)

    dop = DictOp()
    dop.addconf("parser",conf_arr)
    dop.add("parser",["eth1","2.3.4.5/32"],"172.16.0.10")
    dop.add("parser",["eth1","2.3.4.6/32"],"172.16.0.10")
    dop.add("parser",["eth1","2.3.4.7/32"],"172.16.0.10")
    #dop.insert_order("parser",["eth1","2.3.4.5/32"],0,is_parent_parser=True)
    #dop.insert_order("parser",["eth1","2.3.4.6/32"],0,is_parent_parser=True)
    dop.insert_order("parser",["eth1","2.3.4.7/32"],1,is_parent_parser=True)
    #dop.delete("parser",["eth1","2.3.4.5/32"])
    #dop.delete("parser",["eth1","2.3.4.6/32"])
    conf_arr = dop.getconf("parser")
    preprint_r(conf_arr)
    parser.write_conf(conf_arr,dryrun=True)
开发者ID:goura,项目名称:karesansui,代码行数:32,代码来源:staticroute.py

示例5: write_conf

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
        #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_RESOLV_CONF],conf_arr)
            #self.dop.preprint_r("parser")
            arr = self.dop.getconf("parser")
            self.parser.write_conf(arr,dryrun=dryrun)
        except:
            pass

        return retval

"""
"""
if __name__ == '__main__':
    """Testing
    """
    parser = resolvParser()
    dop = DictOp()
    dop.addconf("dum",parser.read_conf())
    dop.comment("dum","search")
    dop.comment("dum","nameserver")
    dop.add("dum","domain","example.com localdomain")
    conf = dop.getconf("dum")
    parser.write_conf(conf,dryrun=True)
开发者ID:AdUser,项目名称:karesansui,代码行数:32,代码来源:resolv.py

示例6: collectdParser

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
"""
"""
if __name__ == '__main__':
    """Testing
    """
    parser = collectdParser()

    # 読み込み
    dop = DictOp()
    dop.addconf("dum",parser.read_conf())

    ##########################################################
    # Uniオプション (一箇所しか設定できないオプション) の追加
    ##########################################################
    # 'Foo foo' を追加(設定値リスト形式モードよる addメソッド)
    dop.add("dum",["Foo"],["foo",[["comment foo1","comment foo2"],"comment foo3"]])
    #print dop.cdp_get("dum",["Foo"])
    #print dop.cdp_get_pre_comment("dum",["Foo"])
    #print dop.cdp_get_post_comment("dum",["Foo"])
    dop.insert_order("dum",["Foo"])

    # 'Bar bar' を追加(設定値文字列形式モードによる cdp_setメソッド)
    dop.cdp_set("dum",["Bar"],"bar")
    dop.cdp_set_pre_comment("dum",["Bar"],["","comment bar1","comment bar2"])
    dop.cdp_set_post_comment("dum",["Bar"],"comment bar3")
    dop.insert_order("dum",["Bar"])

    ##########################################################
    # Multiオプション (複数設定できるオプション) の追加
    ##########################################################
    # 'LoadPlugin target_hoge' を追加
开发者ID:AdUser,项目名称:karesansui,代码行数:33,代码来源:collectd.py

示例7: hostsParser

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
        try:
            self.dop.addconf("parser",{})
            self.dop.set("parser",[PARSER_HOSTS_CONF],conf_arr)
            #self.dop.preprint_r("parser")
            arr = self.dop.getconf("parser")
            self.parser.write_conf(arr,dryrun=dryrun)
        except:
            pass

        return retval

"""
"""
if __name__ == '__main__':
    """Testing
    """
    parser = hostsParser()
    dop = DictOp()
    dop.addconf("dum",parser.read_conf())
    dop.add("dum",['key'],['value',[['comment foo','comment bar'],'comment hoge']])
    print dop.cdp_get("dum",['key'])
    print dop.cdp_get_pre_comment("dum",['key'])
    print dop.cdp_get_post_comment("dum",['key'])
    print dop.cdp_set("dum",['key'],"value2")
    print dop.cdp_set_pre_comment("dum",['key'],["comment foo2","comment bar2","a"])
    print dop.cdp_set_post_comment("dum",['key'],"comment fuga")
    conf = dop.getconf("dum")
    preprint_r(conf)
    parser.write_conf(conf,dryrun=True)
开发者ID:AdUser,项目名称:karesansui,代码行数:31,代码来源:hosts.py

示例8: iscsidParser

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
        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

"""
"""
if __name__ == '__main__':
    """Testing
    """
    parser = iscsidParser()
    dop = DictOp()
    dop.addconf("dum",parser.read_conf())
    dop.add("dum",['key'],['value',[['','comment mae1','comment mae2'],'comment ato']])
    dop.comment("dum",['node.session.iscsi.FastAbort'])
    dop.uncomment("dum",['node.session.iscsi.FastAbort'])
    conf = dop.getconf("dum")
    #preprint_r(conf)
    parser.write_conf(conf,dryrun=True)
开发者ID:AdUser,项目名称:karesansui,代码行数:32,代码来源:iscsid.py

示例9: collectdpluginParser

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
    """Testing
    """

    parser = collectdpluginParser()

    # 読み込み
    dop = DictOp()
    dop.addconf("dum",parser.read_conf())

    new_plugin_name = "takuma"

    ##########################################################
    # Uniオプション (一箇所しか設定できないオプション) の追加
    ##########################################################
    # 'Foo foo' を追加(設定値リスト形式モードよる addメソッド)
    dop.add("dum",[new_plugin_name,"Foo"],["foo",[["comment foo1","comment foo2"],"comment foo3"]])

    # 'Bar bar' を追加(設定値文字列形式モードによる cdp_setメソッド)
    dop.cdp_set("dum",[new_plugin_name,"Bar"],"bar",multiple_file=True)
    dop.cdp_set_pre_comment("dum",[new_plugin_name,"Bar"],["","comment bar1","comment bar2"],multiple_file=True)
    dop.cdp_set_post_comment("dum",[new_plugin_name,"Bar"],"comment bar3",multiple_file=True)

    ##########################################################
    # Multiオプション (複数設定できるオプション) の追加
    ##########################################################
    # 'LoadPlugin target_hoge' を追加
    dop.cdp_set("dum",[new_plugin_name,"LoadPlugin","target_hoge"],"target_hoge",multiple_file=True,is_opt_multi=True)
    dop.cdp_set_pre_comment("dum",[new_plugin_name,"LoadPlugin","target_hoge"],["","Dis is target_hoge"],multiple_file=True)

    ##########################################################
    # Sectオプション (<ブラケット>ディレクティブオプション) の追加
开发者ID:AdUser,项目名称:karesansui,代码行数:33,代码来源:collectdplugin.py

示例10: write_conf

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
        #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_NETWORK_CONF],conf_arr)
            #self.dop.preprint_r("parser")
            arr = self.dop.getconf("parser")
            self.parser.write_conf(arr,dryrun=dryrun)
        except:
            pass

        return retval

"""
"""
if __name__ == '__main__':
    """Testing
    """
    parser = networkParser()
    dop = DictOp()
    dop.addconf("dum",parser.read_conf())
    dop.add("dum","NETWORK","1.0.0.0")
    dop.add("dum","NETWORK2","1.0.0.0")
    dop.delete("dum","NETWORK")
    conf = dop.getconf("dum")
    parser.write_conf(conf,dryrun=True)
开发者ID:AdUser,项目名称:karesansui,代码行数:32,代码来源:network.py

示例11: emlParser

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
class emlParser(Parser):

    _module = "eml"

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

        self.base_parser_name = Parser.__name__

        self.encoding = "UTF-8"
        pass

    def source_file(self):
        try:
            retval = self.get_source_file()
        except:
            retval = []

        return retval

    def _parse_mail(self,mail):
        retval = {}
        try:
            body              = mail.get_payload()
            boundary          = mail.get_boundary()
            charsets          = mail.get_charsets()         # ['iso-8859-1']
            content_charset   = mail.get_content_charset()  # 'iso-8859-1'
            content_maintype  = mail.get_content_maintype() # 'text'
            content_subtype   = mail.get_content_subtype()  # 'plain'
            content_type      = mail.get_content_type()     # 'text/plain'
            default_type      = mail.get_default_type()     # 'text/plain'
            filename          = mail.get_filename()         # ??
            params            = mail.get_params()           # [('text/plain', ''), ('charset', 'iso-8859-1')]
            is_multipart      = mail.is_multipart()         # False
            if type(body) is list:
                new_body = []
                for _mail in body:
                    new_body.append(self._parse_mail(_mail))
                body = new_body
            retval = {}
            retval['body']             = body
            retval['boundary']         = boundary
            retval['charsets']         = charsets
            retval['content_charset']  = content_charset
            retval['content_maintype'] = content_maintype
            retval['content_subtype']  = content_subtype
            retval['content_type']     = content_type
            retval['default_type']     = default_type
            retval['filename']         = filename
            retval['params']           = params
            retval['is_multipart']     = is_multipart
        except:
            pass

        #preprint_r(retval)
        return retval

    def parse(self,file=None,message=None):
        retval = {}
        try:
            if file is not None and os.path.exists(file):
                message = open(file).read()

            mail = email.Parser.Parser().parsestr(message)

            headers  = mail._headers
            msgs     = self._parse_mail(mail)

            if type(msgs['body']) is list:
                rawbody = ""

                if file is not None and os.path.exists(file):
                    f = open(file)
                    line = f.readline()
                    while line:
                        line = f.readline()
                        if line.rstrip() == "":
                            rawbody += line
                            rawbody += ''.join(f.readlines())
                            break
                    f.close
                else:
                    in_body = False
                    for line in message.split("\n"):
                        if line.rstrip() == "":
                            in_body = True
                        if in_body is True:
                            rawbody += line + "\n"

            elif type(msgs['body']) is str:
                rawbody = msgs['body']

            retval["headers"] = headers
            retval["msgs"]    = msgs
            retval["rawbody"] = rawbody

        except:
            pass

#.........这里部分代码省略.........
开发者ID:goura,项目名称:karesansui,代码行数:103,代码来源:eml.py

示例12: modprobe_confParser

# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import add [as 别名]
blacklist modulename
    """

    parser = modprobe_confParser()

    # 読み込み
    dop = DictOp()
    dop.addconf("dum",parser.read_conf())

    #########################################
    # include と blacklist パラメータの場合

    # 1、パラメータを追加する
    new_key   = '/path/to/include/file1'
    new_value = ''   # valueを空にセットする
    dop.add("dum",["include",new_key],new_value)
    # コメントにするなら
    dop.comment("dum",["include",new_key])

    new_key   = '/path/to/include/file2'
    new_value = ''   # valueを空にセットする
    dop.add("dum",["include",new_key],new_value)

    # 2、パラメータを削除する
    delete_key = '/path/to/include/file2'
    dop.delete("dum",["include",delete_key])

    """
    # こっちの方式は、_multi_paramをTrueにしたときだけ

    # 1、パラメータを追加する
开发者ID:goura,项目名称:karesansui,代码行数:33,代码来源:modprobe_conf.py


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