From d68dc9807084926abf3ad1537ed2a104ba782acc Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Thu, 4 Apr 2024 14:20:13 +0200 Subject: [PATCH] Implemented some safeguards that enable only commits of untracked metadata review files --- src/metadata_review_lib.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/metadata_review_lib.py b/src/metadata_review_lib.py index cd85a37..45f8deb 100644 --- a/src/metadata_review_lib.py +++ b/src/metadata_review_lib.py @@ -95,23 +95,30 @@ def first_initialize_metadata_review(hdf5_file_path, reviewer_attrs): if not os.path.exists(review_yaml_file_path): review_yaml_file_path = utils.make_file_copy(os.path.join(hdf5_file_path_tail,filename+YAML_EXT), 'review') - review_yaml_file_path_tail, ext = os.path.splitext(review_yaml_file_path) + review_yaml_file_path_tail, ext = os.path.splitext(review_yaml_file_path) - with open(os.path.join(review_yaml_file_path_tail+"-review_status"+".txt"),'w') as f: - f.write('under review') + #if not os.path.exists(os.path.join(review_yaml_file_path_tail+"-review_status"+".txt")): + with open(os.path.join(review_yaml_file_path_tail+"-review_status"+".txt"),'w') as f: + f.write('under review') - # Stage review files and commit them to local repository + # Stage untracked review files and commit them to local repository status = subprocess.run(status_command,capture_output=True,text=True,check=True) - untracked_files_for_review = [] + untracked_files = [] for line in status.stdout.splitlines(): - if 'review/' in line.decode('utf8'): - untracked_files_for_review.append(line) + #tmp = line.decode("utf-8") + #modified_files.append(tmp.split()[1]) + if 'review/' in line and not 'modified' in line: # untracked files + untracked_files.append(line.strip()) - result = subprocess.run(add_command(untracked_files_for_review),capture_output=True,check=True) - message = 'Initialized metadata review.' - commit_output = subprocess.run(commit_command(message),capture_output=True,check=True) + if untracked_files: + result = subprocess.run(add_command(untracked_files),capture_output=True,check=True) + message = 'Initialized metadata review.' + commit_output = subprocess.run(commit_command(message),capture_output=True,check=True) - print(commit_output.stdout) + for line in commit_output.stdout.splitlines(): + print(line.decode('utf-8')) + else: + print('This action will not have any effect because metadata review process has been already initialized.')