Skip to content

Commit

Permalink
improved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ledm committed Oct 19, 2023
1 parent bb1b36e commit ba7738c
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions bgcval2/download_from_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,'"')

Expand Down Expand Up @@ -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,'"')
Expand Down Expand Up @@ -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]

Expand Down

0 comments on commit ba7738c

Please sign in to comment.