Created
October 4, 2017 08:02
-
-
Save namnh68/f57cbbbcc6a0f8523185793aaba3b8f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
import os | |
import yaml | |
import shutil | |
import sys | |
HEADER_FILE = '/home/stack/infra-openstack/openstack-zuul-jobs' | |
CURRENT_PATH = os.getcwd() | |
def read_yaml(name_file): | |
with open(name_file, 'r') as f: | |
content_dict = yaml.safe_load(f) | |
return content_dict | |
def copy_file(srs, des): | |
if not os.path.exists(os.path.dirname(des)): | |
try: | |
os.makedirs(os.path.dirname(des)) | |
except OSError as exc: | |
raise exc | |
# Copy file: | |
shutil.copyfile(srs, des) | |
def auto_move(contents): | |
""" | |
:param contents: This content that is loaded from .zuul.yaml | |
""" | |
for job in contents: | |
run = job.get('job').get('run') + '.yaml' | |
path_run_src = HEADER_FILE + '/' + run | |
path_run_des = CURRENT_PATH + '/' + run | |
path_run_des_rename = path_run_des.replace('dsvm', 'devstack') | |
# Start moving | |
copy_file(path_run_src, path_run_des_rename) | |
post = job.get('job').get('post-run') + '.yaml' | |
path_post_src = HEADER_FILE + '/' + post | |
path_post_des = CURRENT_PATH + '/' + post | |
path_post_des_rename = path_post_des.replace('dsvm', 'devstack') | |
# Start moving | |
copy_file(path_post_src, path_post_des_rename) | |
def main(): | |
input_file = CURRENT_PATH + '/' + sys.argv[1] | |
content_dict = read_yaml(input_file) | |
auto_move(content_dict) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment