Created
May 14, 2014 12:25
-
-
Save mather/f0d8d937b92f3b6bee28 to your computer and use it in GitHub Desktop.
fabricのenvをyamlで定義する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from fabric.api import * | |
from yaml_loader import load_env_from_yaml | |
load_env_from_yaml('env.yaml', globals()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os, time | |
import yaml | |
from fabric.api import env,task | |
def load_env_from_yaml(yaml_file, namespace): | |
u'''yamlファイルから実行環境タスクを作成''' | |
if os.path.exists(yaml_file): | |
env_data = yaml.safe_load(open(yaml_file).read()) | |
for env_name, env_dict in env_data.items(): | |
__create_env_task(env_name, env_dict, namespace) | |
else: | |
print('No {0} found. skipped.'.format(yaml_file)) | |
class EnvTask(object): | |
def __init__(self, name): | |
self.name = name | |
def set_env(self, env_dict): | |
env.update(env_dict) | |
def __create_env_task(env_name, env_dict, namespace): | |
u'''実行環境タスクの定義''' | |
e = EnvTask(env_name) | |
f = e.set_env | |
f.__func__.__doc__ = 'Set environment for {0}'.format(env_name) | |
task_name = 'env_{0}'.format(env_name) | |
wrapper = task(name=task_name) | |
rand = '%d' % (time.time() * 100000) | |
namespace['task_%s_%s' % (task_name, rand)] = wrapper(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment