Skip to content

Commit

Permalink
Add persistent path to scripts #56
Browse files Browse the repository at this point in the history
Use f-strings for log filenames
  • Loading branch information
astrochun committed Sep 28, 2020
1 parent 284cfec commit 7fa8005
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions scripts/add_grouper_groups
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ if __name__ == '__main__':
# Parse command-line arguments
parser = argparse.ArgumentParser(description='Command-line driver to add a Grouper group.')
parser.add_argument('--config', required=True, help='path to configuration file')
parser.add_argument('--persistent_path', required=True, help='full parent path for logs')
parser.add_argument('--grouper_host', help='Grouper host')
parser.add_argument('--grouper_base_path', help='base path for Grouper API')
parser.add_argument('--grouper_user', help='user name for Grouper login')
Expand Down Expand Up @@ -137,11 +138,11 @@ if __name__ == '__main__':
config.read(args.config)

# Define logfile
log_dir = config.get('global', 'log_dir')
log_dir = path.join(args.persistent_path, config.get('global', 'log_dir'))

if not path.exists(log_dir):
mkdir(log_dir)
logfile_prefix = config.get('global', 'logfile_prefix')
logfile = f"add_groups.{today.strftime('%Y-%m-%d')}.log"
logfile = f"add_grouper_groups.{today.strftime('%Y-%m-%d')}.log"

log = LogClass(log_dir, logfile).get_logger()

Expand Down
4 changes: 3 additions & 1 deletion scripts/get_org_code_numbers
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ library_root_path = path.dirname(path.dirname(library_path)) # Retrieve parent
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Command-line driver for Organization Code summary information.')
parser.add_argument('--config', required=True, help='path to configuration file')
parser.add_argument('--persistent_path', required=True, help='full parent path for logs')
parser.add_argument('--ldap_host', help='LDAP host')
parser.add_argument('--ldap_base_dn', help='base DN for LDAP bind and query')
parser.add_argument('--ldap_user', help='user name for LDAP login')
Expand Down Expand Up @@ -57,7 +58,8 @@ if __name__ == '__main__':
config.read(args.config)

# Define logfile
log_dir = config.get('global', 'log_dir')
log_dir = path.join(args.persistent_path, config.get('global', 'log_dir'))

if not path.exists(log_dir):
mkdir(log_dir)
logfile = "org_code_numbers.{}.log".format(today.strftime("%Y-%m-%d"))
Expand Down
2 changes: 1 addition & 1 deletion scripts/script_run
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ if __name__ == '__main__':
if not path.exists(log_dir):
mkdir(log_dir)
logfile_prefix = config.get('global', 'logfile_prefix')
logfile = "{}.{}.log".format(logfile_prefix, today.strftime("%Y-%m-%d"))
logfile = f'{logfile_prefix}.{today.strftime("%Y-%m-%d")}.log'

log = LogClass(log_dir, logfile).get_logger()

Expand Down

0 comments on commit 7fa8005

Please sign in to comment.