-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
184 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from os import path | ||
|
||
__version__ = "0.14.1" | ||
__version__ = "0.15.1" | ||
|
||
co_path = path.dirname(__file__) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/usr/bin/env python | ||
|
||
from os.path import dirname, exists, join | ||
from os import mkdir, stat | ||
|
||
import argparse | ||
|
||
from datetime import date | ||
|
||
from ldcoolp.admin.move import MoveClass | ||
from ldcoolp.curation.depositor_name import DepositorName | ||
from ldcoolp.curation.api.figshare import FigshareInstituteAdmin | ||
from ldcoolp.logger import LogClass, get_user_hostname | ||
from ldcoolp.admin import permissions | ||
|
||
# Version and branch info | ||
from ldcoolp import __version__ | ||
from ldcoolp.git_info import get_active_branch_name, get_latest_commit | ||
from ldcoolp import __file__ as library_path | ||
|
||
# Config loader | ||
from ldcoolp.config import dict_load | ||
|
||
today = date.today() | ||
|
||
library_root_path = dirname(dirname(library_path)) # Retrieve parent directory to ldcoolp | ||
|
||
|
||
if __name__ == '__main__': | ||
# Parse command-line arguments | ||
parser = argparse.ArgumentParser(description='Command-line driver for data curation moves.') | ||
parser.add_argument('--config', required=True, help='path to configuration file') | ||
parser.add_argument('--article_id', required=True, help='Figshare article ID') | ||
parser.add_argument('--direction', required=True, help='Direction to move. Either "next", "back" or "publish"') | ||
args = parser.parse_args() | ||
|
||
if not exists(args.config): | ||
raise FileNotFoundError(f"WARNING!!! Config file not found: {args.config}") | ||
|
||
if args.direction not in ['next', 'back', 'publish']: | ||
raise ValueError(f"WARNING!!! --direction flag not properly set. Either next, back, or publish") | ||
|
||
branch_name = get_active_branch_name(library_root_path) | ||
git_commit, git_short_commit = get_latest_commit(library_root_path) | ||
|
||
# Load configuration | ||
config_dict = dict_load(args.config) | ||
|
||
curation_dict = config_dict['curation'] | ||
|
||
# Define logfile | ||
root_directory_main = curation_dict[curation_dict['log_parent_dir']] | ||
|
||
log_dir = join(root_directory_main, curation_dict['log_dir']) | ||
if not exists(log_dir): | ||
mkdir(log_dir) | ||
logfile_prefix = 'perform_move' | ||
logfile = f"{logfile_prefix}.{today.strftime('%Y-%m-%d')}.log" | ||
|
||
log = LogClass(log_dir, logfile).get_logger() | ||
|
||
log.info("****************************") | ||
|
||
log.debug(f"LD-Cool-P branch: {branch_name}") | ||
log.debug(f"LD-Cool-P version: {__version__} ({git_short_commit})") | ||
log.debug(f"LD-Cool-P commit hash: {git_commit}") | ||
|
||
# Retrieve username, hostname, IP | ||
sys_info = get_user_hostname() | ||
log.debug(f"username : {sys_info['user']}") | ||
log.debug(f"hostname : {sys_info['hostname']}") | ||
log.debug(f"IP Addr : {sys_info['ip']}") | ||
log.debug(f"Op. Sys. : {sys_info['os']}") | ||
|
||
# Separate comma-separated list of articles | ||
articles = args.article_id.split(',') | ||
num_articles = len(articles) | ||
|
||
log.info(f"Number of Deposits: {num_articles}") | ||
|
||
fs_admin = FigshareInstituteAdmin(figshare_dict=config_dict['figshare'], log=log) | ||
mc = MoveClass(curation_dict=curation_dict, log=log) | ||
|
||
# Loop over each article | ||
count = 0 | ||
for ii in range(len(articles)): | ||
dn = DepositorName(articles[ii], fs_admin, log=log) | ||
log.info(f"Performing move with --direction {args.direction}") | ||
if args.direction == 'next': | ||
mc.move_to_next(dn.folderName) | ||
if args.direction == 'back': | ||
mc.move_back(dn.folderName) | ||
if args.direction == 'publish': | ||
mc.move_to_publish(dn.folderName) | ||
|
||
count += 1 | ||
|
||
log.info(f"Completed: {articles[ii]} ...") | ||
log.info(f"Completed: {count} / {num_articles}") | ||
|
||
# Change permission to mode=666 (rw for all) | ||
status = stat(join(log_dir, logfile)) | ||
if oct(status.st_mode)[-3:] == '666': | ||
log.debug("Permissions set for logfile") | ||
else: | ||
log.debug("Changing permissions on logfile...") | ||
permissions.curation(join(log_dir, logfile), mode=0o666) | ||
|
||
log.info("****************************") | ||
log.info("Exit 0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters