Skip to content
Snippets Groups Projects
Commit 6f73fbe1 authored by Karim Ahmed's avatar Karim Ahmed
Browse files

no copying if no push

parent 6f8e7d7b
No related branches found
No related tags found
1 merge request!185Feat/git push flag
......@@ -73,7 +73,7 @@ if __name__ == "__main__":
args = vars(arg_parser.parse_args())
conf_file = args["config_file"]
with open(conf_file, "r") as f:
cfg = yaml.load(f.read())
cfg = yaml.load(f.read(), Loader=yaml.FullLoader)
logfile = args["log_file"]
fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
......
......@@ -35,11 +35,11 @@ def manual_run(request, cfg):
arg_parser = argparse.ArgumentParser(description='Manual Launch')
arg_parser.add_argument('--instrument', default=['all'], nargs='+',
help='select the requested instruments. '
'Default=None. "all" can be used for selecting'
'Default=\"all\", which can be used for selecting'
' all instruments')
arg_parser.add_argument('--gitpush', dest='Push to git', action='store_true',
help='required for pushing the generated figures '
'to the DC git repository')
'to the DC git repository. Default=bool(False)')
arg_parser.set_defaults(gitpush=False)
arg_parser.add_argument('--config-file', type=str,
default='./report_conf.yaml',
......@@ -56,7 +56,7 @@ if __name__ == "__main__":
args = vars(arg_parser.parse_args())
conf_file = args["config_file"]
with open(conf_file, "r") as f:
cfg = yaml.load(f.read())
cfg = yaml.load(f.read(), Loader=yaml.FullLoader)
logfile = args["log_file"]
fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
......
......@@ -156,7 +156,7 @@ async def server_runner(conf_file):
be accessed through ReadTheDocs.
"""
with open(conf_file, "r") as f:
config = yaml.load(f.read())
config = yaml.load(f.read(), Loader=yaml.FullLoader)
# perform git-dir checks and pull the project for updates.
init_config_repo(config['GLOBAL']['git'])
......@@ -263,57 +263,60 @@ async def server_runner(conf_file):
logging.error('Jobs have timed-out!')
logging.error('{}/temp has not been deleted.'.format(
os.path.dirname(os.path.abspath(__file__))))
# Avoid copying files if no git-push is planned
# to avoid causing local git repository errors.
if git_push:
# Copy all plots
for det_name, det_conf in instrument.items():
# Copy all plots
for det_name, det_conf in instrument.items():
out_folder = det_conf['out-folder'].format(
instrument=instr_name,
detector=det_name)
out_folder = det_conf['out-folder'].format(
instrument=instr_name,
detector=det_name)
figures = glob.glob("{}/*png".format(out_folder))
figures = glob.glob("{}/*png".format(out_folder))
det_new_files = {}
det_new_files = {}
for f in figures:
const = f.split('/')[-1].split('_')[0]
fpath = '{}/{}/{}/{}'.format(fig_local, instr_name,
det_name, const)
for f in figures:
const = f.split('/')[-1].split('_')[0]
fpath = '{}/{}/{}/{}'.format(fig_local, instr_name,
det_name, const)
os.makedirs(fpath, exist_ok=True)
det_new_files[f] = fpath
os.makedirs(fpath, exist_ok=True)
det_new_files[f] = fpath
# Set concurrency limitation.
# 50 have been chosen by trial
# Note: This is not the max limitation.
sem = asyncio.Semaphore(50)
all_new_files.append(
'{}/{}'.format(fpath, f.split('/')[-1]))
# Set concurrency limitation.
# 50 have been chosen by trial
# Note: This is not the max limitation.
sem = asyncio.Semaphore(50)
all_new_files.append(
'{}/{}'.format(fpath, f.split('/')[-1]))
await asyncio.gather(*[copy_files(k, v, sem)
for k, v in det_new_files.items()])
await asyncio.gather(*[copy_files(k, v, sem)
for k, v in det_new_files.items()])
logging.info('{} figures of {} are copied into {}'.format(
len(figures), det_name, fig_local))
logging.info('{} figures of {} are copied into {}'.format(
len(figures), det_name, fig_local))
# Remove sensitive information from the config file.
del cfg['GLOBAL']
# Write the requested cfg.yaml before pushing all figures.
with open('{}/report_conf.yaml'.format(
fig_local), 'w') as outfile:
yaml.dump(cfg, outfile, default_flow_style=False)
if git_push:
# Remove sensitive information from the config file.
del cfg['GLOBAL']
# Write the requested cfg.yaml before pushing all figures.
with open('{}/report_conf.yaml'.format(
fig_local), 'w') as outfile:
yaml.dump(cfg, outfile, default_flow_style=False)
all_new_files.append('{}/report_conf.yaml'.format(fig_local))
all_new_files.append('{}/report_conf.yaml'.format(fig_local))
if git_push:
asyncio.ensure_future(push_figures(local_repo, all_new_files))
# TODO:delete out-folder
#try:
# asyncio.ensure_future(del_folder(out_folder))
#except:
#logging.error(str(e))
logging.info('All done')
# TODO:delete out-folder
#try:
# asyncio.ensure_future(del_folder(out_folder))
#except:
#logging.error(str(e))
logging.info('Generating requested plots is finished!')
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment