Implemented git add and commit for second metadata review step, and create it function to checkout branches.
This commit is contained in:
@ -8,6 +8,7 @@ import yaml
|
||||
import shutil
|
||||
import src.g5505_utils as utils
|
||||
import src.hdf5_vis as hdf5_vis
|
||||
import input_files.config_file as config_file
|
||||
|
||||
import numpy as np
|
||||
|
||||
@ -30,6 +31,16 @@ def get_review_status(filename_path):
|
||||
workflow_steps.append(line)
|
||||
return workflow_steps[-1]
|
||||
|
||||
def checkout_review_branch(repo_obj,initials):
|
||||
# Create a new branch
|
||||
branch_name = 'metadata-review-by-'+initials
|
||||
head_commit = repo_obj.head.peel()# Get the commit hash associated with HEAD
|
||||
|
||||
if not branch_name in repo_obj.branches:
|
||||
branch = repo_obj.create_branch(branch_name, head_commit)
|
||||
else:
|
||||
branch = repo_obj.branches[branch_name]
|
||||
repo_obj.checkout(branch)
|
||||
|
||||
def first_initialize_metadata_review(filename_path,initials):
|
||||
|
||||
@ -54,39 +65,41 @@ def first_initialize_metadata_review(filename_path,initials):
|
||||
|
||||
# Initialize metadata review workflow
|
||||
print("Create branch metadata-review-by-"+initials+"\n")
|
||||
|
||||
|
||||
# Check if review file already exists and then check if it is still untracked
|
||||
if not os.path.exists(os.path.join("review/",filename+YAML_EXT)):
|
||||
review_filename_path = utils.make_file_copy(os.path.join(filename_path_tail,filename+YAML_EXT), 'review')
|
||||
else:
|
||||
raise Warning("the file " + os.path.join("review/",filename+YAML_EXT)+ " already exists. Delete this file to reinitialize the metadata review process.")
|
||||
review_filename_path = os.path.join("review/",filename+YAML_EXT)
|
||||
#else:
|
||||
# raise Warning("the file " + os.path.join("review/",filename+YAML_EXT)+ " already exists. Delete this file to reinitialize the metadata review process.")
|
||||
|
||||
|
||||
review_filename_tail, ext = os.path.splitext(review_filename_path)
|
||||
|
||||
with open(os.path.join(review_filename_tail+"-review_status"+".txt"),'w') as f:
|
||||
f.write('under review')
|
||||
|
||||
|
||||
# Create a new branch
|
||||
branch_name = 'metadata-review-by-'+initials
|
||||
head_commit = repo_obj.head.peel()# Get the commit hash associated with HEAD
|
||||
|
||||
if not branch_name in repo_obj.branches:
|
||||
new_branch = repo_obj.create_branch(branch_name, head_commit)
|
||||
repo_obj.checkout(new_branch)
|
||||
checkout_review_branch(repo_obj,initials)
|
||||
|
||||
status_dict = repo_obj.status()
|
||||
for key in status_dict:
|
||||
for filepath, file_status in status_dict.items():
|
||||
# Identify keys associated to review files and stage them
|
||||
if 'review/'+filename in key:
|
||||
if 'review/'+filename in filepath:
|
||||
# Stage changes
|
||||
repo_obj.index.add(key)
|
||||
repo_obj.create_commit(message="Initialized metadata review process.")
|
||||
repo_obj.index.add(filepath)
|
||||
|
||||
author = config_file.author #default_signature
|
||||
committer = config_file.committer
|
||||
message = "Initialized metadata review process."
|
||||
tree = repo_obj.index.write_tree()
|
||||
oid = repo_obj.create_commit('HEAD', author, committer, message, tree, [repo_obj.head.peel().oid])
|
||||
|
||||
#print("Add and commit"+"\n")
|
||||
|
||||
|
||||
|
||||
def second_submit_metadata_review(filename_path):
|
||||
def second_submit_metadata_review(filename_path, initials):
|
||||
"""
|
||||
Once you're done reviewing the yaml representation of hdf5 file in review folder.
|
||||
Change the review status to complete and save (add and commit) modified .yalm and .txt files in the project by
|
||||
@ -103,8 +116,36 @@ def second_submit_metadata_review(filename_path):
|
||||
filename, ext = os.path.splitext(filename_path_head)
|
||||
# TODO:
|
||||
with open(os.path.join("review/",filename+"-review_status"+TXT_EXT),'a') as f:
|
||||
f.write('\nsubmitted')
|
||||
#return True
|
||||
f.write('\nsubmitted')
|
||||
|
||||
# Create a new branch
|
||||
branch_name = 'metadata-review-by-'+initials
|
||||
head_commit = repo_obj.head.peel()# Get the commit hash associated with HEAD
|
||||
|
||||
if not branch_name in repo_obj.branches:
|
||||
branch = repo_obj.create_branch(branch_name, head_commit)
|
||||
else:
|
||||
branch = repo_obj.branches[branch_name]
|
||||
|
||||
repo_obj.checkout(branch)
|
||||
|
||||
status_dict = repo_obj.status()
|
||||
for filepath, file_status in status_dict.items():
|
||||
# Identify keys associated to review files and stage them
|
||||
if ('review/'+filename in filepath) and (file_status == pygit.GIT_STATUS_WT_MODIFIED):
|
||||
# Stage changes
|
||||
repo_obj.index.add(filepath)
|
||||
|
||||
author = config_file.author #default_signature
|
||||
committer = config_file.committer
|
||||
message = "Submitted metadata review."
|
||||
tree = repo_obj.index.write_tree()
|
||||
oid = repo_obj.create_commit('HEAD', author, committer, message, tree, [repo_obj.head.peel().oid])
|
||||
|
||||
|
||||
def third_complete_metadata_review():
|
||||
|
||||
return
|
||||
|
||||
def third_update_hdf5_file_with_review(input_hdf5_file, yaml_file):
|
||||
|
||||
|
Reference in New Issue
Block a user