Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ldcoolp/admin/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def main(self, depositor_name, source_stage, dest_stage):
self.log.info(f"Path does not exist! {dest_path}")
self.log.info("Creating...")
makedirs(dest_path)
chmod(dest_path, 0o777)
chmod(dest_path, 0o770)
shutil.move(source_path, dest_path)

# Remove source_path parent folder if empty
Expand Down
16 changes: 10 additions & 6 deletions ldcoolp/admin/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@
from os import chmod, walk


def curation(path, mode=0o777):
def curation(path, folder_mode=0o2770, file_mode=0o2660):
"""
Purpose:
Set permissions for all folders and files under the
parent location of [path]

:param path: Parent location path
:param mode: Mode. Default is rwx with '0o777'
:param folder_mode: Mode for folders. Default is rwx with '0o770'
:param file_mode: Mode for files. Default is rw- with '660'
"""

if isdir(path) or isfile(path):
chmod(path, mode)
if isdir(path):
chmod(path, folder_mode)

if isfile(path):
chmod(path, file_mode)

for dir_path, dir_names, files in walk(path):
for dir_name in dir_names:
chmod(join(dir_path, dir_name), mode)
chmod(join(dir_path, dir_name), folder_mode)

for file in files:
chmod(join(dir_path, file), mode)
chmod(join(dir_path, file), file_mode)
4 changes: 3 additions & 1 deletion ldcoolp/curation/inspection/readme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os.path import exists, join, dirname, basename, getctime
from os import walk, stat, symlink
from os import walk, stat, symlink, chmod
from datetime import datetime
import shutil
from glob import glob
Expand Down Expand Up @@ -277,7 +277,9 @@ def save_template(self):

self.log.info(f"Source file name: {src_file}")
shutil.copy(src_file, dest_file)
chmod(dest_file, 0o2660)
shutil.copy(funders_macro_file_src, funders_macro_file_dest)
chmod(funders_macro_file_dest, 0o2660)
else:
self.log.info(f"{dest_file} exists. Not overwriting template!")

Expand Down
7 changes: 5 additions & 2 deletions ldcoolp/curation/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from os.path import join, exists
from os import makedirs, chmod
from pathlib import Path

# Logging
from redata.commons.logger import log_stdout
Expand Down Expand Up @@ -110,8 +111,10 @@ def make_folders(self):
full_data_path = join(self.root_directory, sub_dir)
if not exists(full_data_path):
self.log.info(f"Creating folder : {full_data_path}")
makedirs(full_data_path)
chmod(full_data_path, 0o777)
makedirs(full_data_path, mode=0o2770, exist_ok=True)
Path(full_data_path).parent.chmod(0o2770)
Path(full_data_path).parent.parent.chmod(0o2770)


def write_curation_metadata(self):
"""Write metadata from Figshare curation response"""
Expand Down
3 changes: 3 additions & 0 deletions ldcoolp/curation/metadata.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from os import chmod
from typing import Union

import os
Expand Down Expand Up @@ -53,6 +54,7 @@ def save_metadata(json_response: Union[list, dict],
if overwrite:
log.info("Overwriting!")
write_json(json_out_file, json_response, log)
chmod(json_out_file, 0o2660)

# Write CSV file
if save_csv:
Expand All @@ -66,6 +68,7 @@ def save_metadata(json_response: Union[list, dict],
if overwrite:
log.info("Overwriting!")
df.to_csv(csv_out_file, index=False)
chmod(csv_out_file, 0o2660)

log.debug("finished.")

Expand Down
2 changes: 1 addition & 1 deletion ldcoolp/curation/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def review_report(depositor_name='', curation_dict=config_default_dict['curation
out_path = join(staging_directory, depositor_name, folder_ual_rdm)
if not exists(out_path):
log.info(f"Creating folder : {out_path}")
makedirs(out_path, mode=0o777, exist_ok=True)
makedirs(out_path, mode=0o2770, exist_ok=True)
else:
log.warn(f"!!!! Folder exists, not creating : {out_path}")

Expand Down
6 changes: 3 additions & 3 deletions ldcoolp/curation/retrieve.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil
from os.path import exists

from os import chmod
import requests
from requests import HTTPError

Expand Down Expand Up @@ -126,6 +126,7 @@ def download_files(article_id, fs, root_directory=None, data_directory=None,
checksum_flag = check_md5(filename,
file_dict['supplied_md5'])
if checksum_flag:
chmod(filename, 0o2440)
break
else:
log.info("Not performing checksum on linked-only record")
Expand All @@ -138,5 +139,4 @@ def download_files(article_id, fs, root_directory=None, data_directory=None,
log.info("File exists! Not overwriting!")

# Change permissions on folders and files
# permissions.curation(dir_path)
permissions.curation(dir_path, mode=0o555) # read and execute only
permissions.curation(dir_path, folder_mode=0o2550, file_mode=0o2440) # read and execute only
Loading