Skip to content

Commit

Permalink
Merge branch 'hotfix/v0.15.2' #108
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochun committed Oct 13, 2020
2 parents 1667470 + e6eb46d commit cc410ae
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 15 deletions.
5 changes: 3 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.15.1`.
You should see that the version is `0.15.2`.

### Configuration Settings

Expand Down Expand Up @@ -199,11 +199,12 @@ 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.1:
v0.15.0 - v0.15.2:
* 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
* `get_user_details` script to retrieve user information from Figshare API #107

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.15.1"
__version__ = "0.15.2"

co_path = path.dirname(__file__)

Expand Down
35 changes: 24 additions & 11 deletions ldcoolp/curation/api/figshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def get_groups(self):
groups_df = pd.DataFrame(groups)
return groups_df

def get_account_list(self):
def get_account_list(self, ignore_admin=False):
"""Retrieve accounts within institutional instance"""
url = self.endpoint("accounts")

Expand All @@ -183,6 +183,15 @@ def get_account_list(self):

accounts_df = pd.DataFrame(accounts)
accounts_df = accounts_df.drop(columns='institution_id')

if ignore_admin:
self.log.info("Excluding administrative and test accounts")

drop_index = list(accounts_df[accounts_df['email'] ==
'[email protected]'].index)
drop_index += list(accounts_df[accounts_df['email'].str.contains('[email protected]')].index)

accounts_df = accounts_df.drop(drop_index).reset_index(drop=True)
return accounts_df

def get_account_group_roles(self, account_id):
Expand All @@ -192,14 +201,15 @@ def get_account_group_roles(self, account_id):
roles = issue_request('GET', url, self.headers)
return roles

def get_account_details(self):
def get_account_details(self, flag=True, ignore_admin=False):
"""
Retrieve account details. This includes number of articles, projects,
collections, group association, and administrative and reviewer flags
"""

# Retrieve accounts
accounts_df = self.get_account_list()
accounts_df = self.get_account_list(ignore_admin=ignore_admin)

n_accounts = accounts_df.shape[0]

# Retrieve groups
Expand All @@ -209,8 +219,9 @@ def get_account_details(self):
num_projects = np.zeros(n_accounts, dtype=np.int)
num_collections = np.zeros(n_accounts, dtype=np.int)

admin_flag = [''] * n_accounts
reviewer_flag = [''] * n_accounts
if flag:
admin_flag = [''] * n_accounts
reviewer_flag = [''] * n_accounts
group_assoc = ['N/A'] * n_accounts

# Determine group roles for each account
Expand All @@ -237,19 +248,21 @@ def get_account_details(self):

for key in roles.keys():
for t_dict in roles[key]:
if t_dict['id'] == 2:
admin_flag[n] = 'X'
if t_dict['id'] == 49:
reviewer_flag[n] = 'X'
if t_dict['id'] == 11:
group_assoc[n] = key
if flag:
if t_dict['id'] == 2:
admin_flag[n] = 'X'
if t_dict['id'] == 49:
reviewer_flag[n] = 'X'

accounts_df['Articles'] = num_articles
accounts_df['Projects'] = num_projects
accounts_df['Collections'] = num_collections

accounts_df['Admin'] = admin_flag
accounts_df['Reviewer'] = reviewer_flag
if flag:
accounts_df['Admin'] = admin_flag
accounts_df['Reviewer'] = reviewer_flag

for group_id, group_name in zip(groups_df['id'], groups_df['name']):
self.log.info(f"{group_id} - {group_name}")
Expand Down
110 changes: 110 additions & 0 deletions ldcoolp/scripts/get_user_details
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, datetime
import pytz

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()

tz_AZ = pytz.timezone('US/Arizona')
now = datetime.now(tz_AZ)

library_root_path = dirname(dirname(library_path)) # Retrieve parent directory to ldcoolp


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Command-line driver for LD-Cool-P prerequisite set-up.')
parser.add_argument('--config', required=True, help='path to configuration file')
parser.add_argument('--write_file', action='store_true', help='Write CSV file containing results')
parser.add_argument('--path', help='Full path to write CSV file')
parser.add_argument('--simple', action='store_true',
help='Generate a basic list without detailed information')
args = parser.parse_args()

if not exists(args.config):
raise FileNotFoundError(f"WARNING!!! Config file not found: {args.config}")

if args.write_file:
if not exists(args.path):
raise FileNotFoundError(f"WARNING!!! Path not found: {args.path}")

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 = 'get_user_details'
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']}")

fs_admin = FigshareInstituteAdmin(figshare_dict=config_dict['figshare'],
log=log)

if not args.simple:
accounts_df = fs_admin.get_account_details(flag=False, ignore_admin=True)

log.info(f"Number of users: {len(accounts_df)}")
if not args.write_file:
print(accounts_df)
else:
csv_outfile = join(args.path,
f"redata_user_details.{now.strftime('%Y-%m-%d_%H:%M')}.csv")

log.info(f"Writing file : {csv_outfile}")

accounts_df.to_csv(csv_outfile, index=False)
else:
accounts_df = fs_admin.get_account_list(ignore_admin=True)

log.info(f"Number of users: {len(accounts_df)}")
print(accounts_df)

# 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.15.1',
version='v0.15.2',
packages=['ldcoolp'],
url='https://github.com/ualibraries/LD_Cool_P',
license='MIT License',
Expand Down

0 comments on commit cc410ae

Please sign in to comment.