From ba7738ca1c5ecbd8a2ec0cecb90aac671d4c5e78 Mon Sep 17 00:00:00 2001 From: Lee de Mora Date: Thu, 19 Oct 2023 15:17:27 +0100 Subject: [PATCH] improved comments --- bgcval2/download_from_mass.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/bgcval2/download_from_mass.py b/bgcval2/download_from_mass.py index 351fc657..756ccf55 100755 --- a/bgcval2/download_from_mass.py +++ b/bgcval2/download_from_mass.py @@ -408,16 +408,18 @@ def download_from_mass( paths = get_paths(config_user) outputFold = folder([paths.ModelFolder_pref, jobID,] ) - # make this folder group writeable. st = os.stat(outputFold) - - # Case one: - # I created this folder and I own it: + + # Check permissions on the output folder i_can_write_this = os.access(outputFold, os.W_OK) if i_can_write_this: + # I created this folder and I own it. + # make this folder group writeable. os.chmod(outputFold, st.st_mode | stat.S_IWGRP) else: - uname = getpwuid(os.stat(outputFold).st_uid).pw_name + # Someone else created it and they own it, + # so I can't change permissions. + uname = getpwuid(st.st_uid).pw_name print('WARNING: someone else (', uname, ') owns this directory, so you may not be able to download files.') print('WARNING: Ask them politely to run "chmod g+w ',outputFold,'"') @@ -494,13 +496,20 @@ def download_from_mass( shared_file_path = os.path.join(paths.shared_mass_scripts, os.path.basename(download_script_path)) print('writing file in shared path', shared_file_path) - # I created this file and I own it: + # check destination permissions: i_can_write_this = os.access(shared_file_path, os.W_OK) if i_can_write_this: + # I created this file and I own it: + # make local copy group writable: os.chmod(download_script_path, st.st_mode | stat.S_IWGRP) + + # copy local to shared folder: shutil.copy(download_script_path, shared_file_path) + + # make shared copy group writable: (possibly overkill) os.chmod(shared_file_path, st.st_mode | stat.S_IWGRP) else: + # I don't have permission to edit this file. Someone else does: uname = getpwuid(os.stat(shared_file_path).st_uid).pw_name print('WARNING: someone else (', shared_file_path, ') owns this directory, so you may not be able to download files.') print('WARNING: Ask them politely to run "chmod g+w ', shared_file_path,'"') @@ -621,15 +630,11 @@ def deleteBadLinksAndZeroSize(outputFold, jobID, debug=True): bashCommand1 = bashCommand1.replace('//', '/') bashCommand2 = bashCommand2.replace('//', '/') - #f debug: print("deleteBadLinksAndZeroSize:\t", bashCommand1) - process1 = subprocess.Popen(bashCommand1.split(), stdout=subprocess.PIPE) output1 = process1.communicate()[0] - #f debug: print("deleteBadLinksAndZeroSize:\t", bashCommand2) - process2 = subprocess.Popen(bashCommand2.split(), stdout=subprocess.PIPE) output2 = process2.communicate()[0]