Skip to content

Commit

Permalink
Merge branch 'hotfix/v0.15.1' #106
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochun committed Oct 12, 2020
2 parents 42eccb1 + a90e6b8 commit 1667470
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ You can confirm installation via `conda list`
(curation) $ conda list ldcoolp
```

You should see that the version is `0.14.1`.
You should see that the version is `0.15.1`.

### Configuration Settings

Expand Down Expand Up @@ -199,9 +199,11 @@ We use [SemVer](http://semver.org/) for versioning. For the versions available,
A list of released features and their issue number(s).
List is sorted from moderate to minor revisions for reach release.

v0.15.0:
v0.15.0 - v0.15.1:
* Implementation of Qualtrics README file #98
* Folder re-structuring for versioning #100
* `perform_move` script to perform move to next curation stage, backwards or
to publish #105

v0.14.0 - 0.14.1:
* Full stdout and file logging #83
Expand Down
2 changes: 1 addition & 1 deletion ldcoolp/__init__.py
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__)

Expand Down
76 changes: 68 additions & 8 deletions ldcoolp/admin/move.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os.path import join, dirname, exists
from os import makedirs, chmod
import shutil
from glob import glob

Expand Down Expand Up @@ -69,7 +70,7 @@ def get_source_stage(self, depositor_name, verbose=True):
self.log.debug(source_path)
raise ValueError(err)
if len(source_path) == 1:
source_stage = dirname(source_path[0].replace(join(self.root_directory_main, ''), ''))
source_stage = source_path[0].replace(join(self.root_directory_main, ''), '').split('/')[0]

return source_stage

Expand All @@ -87,12 +88,18 @@ def main(self, depositor_name, source_stage, dest_stage):

# Define paths:
source_path = join(self.root_directory_main, source_stage, depositor_name)
dest_path = join(self.root_directory_main, dest_stage, depositor_name)
# Strip out version folder convention for proper move with shutil.move
dest_path = dirname(join(self.root_directory_main, dest_stage, depositor_name))

# Move folder
if exists(source_path):
self.log.info(f"Moving: {depositor_name} from {source_stage} to ...")
self.log.info(f" ... {dest_stage} on {self.root_directory_main}")
if not exists(dest_path):
self.log.info(f"Path does not exist! {dest_path}")
self.log.info("Creating...")
makedirs(dest_path)
chmod(dest_path, 0o777)
shutil.move(source_path, dest_path)
else:
self.log.info(f"WARNING: Unable to find source_path for {depositor_name}")
Expand All @@ -110,13 +117,66 @@ def move_to_next(self, depositor_name, verbose=True):
# Get current path
source_stage = self.get_source_stage(depositor_name, verbose=verbose)

# Get destination path
dest_stage_i = [i+1 for i in range(len(self.stage_list)) if
self.stage_list[i] == source_stage][0]
dest_stage = self.stage_list[dest_stage_i]
if source_stage == self.stage_list[-1]:
self.log.warn(f"Cannot moved to next stage! Currently in {source_stage}")
else:
# Get destination path
dest_stage_i = [i+1 for i in range(len(self.stage_list)) if
self.stage_list[i] == source_stage][0]
dest_stage = self.stage_list[dest_stage_i]

# Move folder
self.main(depositor_name, source_stage, dest_stage)
# Move folder
self.main(depositor_name, source_stage, dest_stage)
except FileNotFoundError:
self.log.warn(f"Unable to find source_path for {depositor_name}")

def move_back(self, depositor_name, verbose=True):
"""
Purpose:
Perform move from one curation stage back to previous one
:param depositor_name: Exact name of the data curation folder with spaces
:param verbose: bool that warns source_path does not exist. Default: True
"""

try:
# Get current path
source_stage = self.get_source_stage(depositor_name, verbose=verbose)

if source_stage == self.stage_list[0]:
self.log.warn(f"Cannot moved to next stage! Currently in {source_stage}")
else:
# Get destination path
dest_stage_i = [i-1 for i in range(len(self.stage_list)) if
self.stage_list[i] == source_stage][0]
dest_stage = self.stage_list[dest_stage_i]

# Move folder
self.main(depositor_name, source_stage, dest_stage)
except FileNotFoundError:
self.log.warn(f"Unable to find source_path for {depositor_name}")

def move_to_publish(self, depositor_name, verbose=True):
"""
Purpose:
Perform move from one curation stage to published stage
:param depositor_name: Exact name of the data curation folder with spaces
:param verbose: bool that warns source_path does not exist. Default: True
"""

try:
# Get current path
source_stage = self.get_source_stage(depositor_name, verbose=verbose)

if source_stage == self.published_folder:
self.log.warn(f"Already in {source_stage} !!!")
else:
# Get destination path
dest_stage = self.published_folder

# Move folder
self.main(depositor_name, source_stage, dest_stage)
except FileNotFoundError:
self.log.warn(f"Unable to find source_path for {depositor_name}")

Expand Down
110 changes: 110 additions & 0 deletions ldcoolp/scripts/perform_move
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")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='ldcoolp',
version='v0.14.1',
version='v0.15.1',
packages=['ldcoolp'],
url='https://github.com/ualibraries/LD_Cool_P',
license='MIT License',
Expand Down

0 comments on commit 1667470

Please sign in to comment.