예제 #1
0
def get_config(key, files):
    c = {}
    for i in files:
        if os.path.exists(i):
            d = yaml.load(open(i))
            c = dict(c.items() + d.items())

    for k in key.split('.'):
        if k in c:
            c = c[k]
        else:
            return None
    return c
예제 #2
0
    def load(self, raw_content, key):
        """
        Load json or yaml content.

        :param raw_content: json/yaml raw_content
        :type raw_content: bytes

        :param key: path + filename
        :type key: string

        :returns: content of the file (json/yaml)
        :rype: dict
        """
        if self.is_json(key):
            return json.loads(raw_content)
        else:
            return yaml.load(raw_content)
예제 #3
0
    exit = Button(win_bot, text="quit", command=lambda: root.destroy()
                  )  #width = 50,bg = "red",fg = "green",height = 20
    exit.bind("<Return>", lambda e: root.destroy())
    exit.focus_set()
    exit.pack(expand=YES, fill=BOTH)
    root.mainloop()


def big_alert(msg):
    print '=' * 80
    print msg
    print '=' * 80


try:
    import __init__ as dev_tool
    from dependencies import yaml
except ImportError:
    traceback.print_exc()
    big_alert('can not find a directory')
    sys.exit(1)

config_filenames = ['../config.yaml']
config = {}
for f in config_filenames:
    if os.path.exists(f):
        d = yaml.load(open(f))
        if d:
            config = dict(config.items() + d.items())
# print(config)
menu(dev_tool, config)
예제 #4
0
파일: tool.py 프로젝트: zhc921106/museTools
    print msg
    print '='*80
try:
    import __init__ as dev_tool
    from dependencies import yaml
except ImportError:
    traceback.print_exc()
    big_alert('can not find a directory')
    sys.exit(1)

# 获取配置文件
config_filenames = ['config.yaml']
config = {}
for f in config_filenames:
    if os.path.exists(f) :
        d = yaml.load(open(f))
        if d:
            config = dict(config.items() + d.items())


action_keys = dev_tool.actions['keys']
action_values = dev_tool.actions['values']
action_indexes = sys.argv[1:]

# 当需要额外参数时,可以在这里进行设置,传递到config中
optlist,action_indexes = getopt.getopt(sys.argv[1:],'d',["language=",'sys='])
for opt in optlist:
    if opt[0] == '--language':
    	os.environ['language']=opt[1]
    	config['language'] = opt[1]
    elif opt[0] == '--sys' :
예제 #5
0
파일: tool.py 프로젝트: aeshion/game


# 检查config.yaml文件是否存在
if not os.path.exists(deploy_dir + os.sep + 'config.yaml') :
    logging.error('在deploy目录下找不到config.yaml文件')
    raw_input()
    sys.exit(1)

# 加载主配置文件
config_files = ['config.yaml']
config = {}
for file in config_files :
    filepath = deploy_dir + os.sep + file
    if os.path.exists(filepath) :
        yaml_dict = yaml.load(open(filepath))
        if yaml_dict :
            config = dict(config.items() + yaml_dict.items())


# 检查主配置文件里面的内容
for config_name in ['project_root', 'project_name'] :
    cfg = config.get(config_name)
    if not cfg :
        logging.error("主配置文件中缺少 %s 的配置"%config_name)
        raw_input()
        sys.exit(1)
    vars()[config_name] = cfg # 设置全局变量
    print "%s:%s"%(config_name, cfg)

# 重新加载配置