Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Jul 31, 2017
1 parent 0b98871 commit 5afbd4a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
13 changes: 8 additions & 5 deletions almar/almar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from .job import Job
from .sru import SruClient

raven_client = None

log = logging.getLogger()
log.setLevel(logging.INFO)
logging.getLogger('requests').setLevel(logging.WARNING)
Expand Down Expand Up @@ -169,6 +171,7 @@ def job_args(config=None, args=None):
'list_options': list_options,
}


def get_config_file():
possible_file_locations = ['./almar.yml', './lokar.yml', os.path.expanduser('~/.almar.yml')]

Expand All @@ -178,6 +181,7 @@ def get_config_file():


def main(config=None, args=None):
global raven_client
filename = get_config_file()
if filename is None:
log.error('Could not find "almar.yml" configuration file. See https://github.com/scriptotek/almar for help.')
Expand All @@ -194,8 +198,8 @@ def main(config=None, args=None):
log.info('Running as %s', username)
try:
if config.get('sentry') is not None:
raven = Client(config['sentry']['dsn'])
raven.context.merge({'user': {
raven_client = Client(config['sentry']['dsn'])
raven_client.context.merge({'user': {
'username': username
}})

Expand All @@ -212,7 +216,6 @@ def main(config=None, args=None):
file_handler.setLevel(logging.INFO)
log.addHandler(file_handler)


def get_env(config, args):
if args.env is None:
log.error('No environment specified and no default environment found in configuration file')
Expand Down Expand Up @@ -240,8 +243,8 @@ def get_env(config, args):
log.info('Job complete')

except Exception: # # pylint: disable=broad-except
if config.get('sentry') is not None:
raven.captureException()
if raven_client is not None:
raven_client.captureException()
log.exception('Uncaught exception:')


Expand Down
2 changes: 1 addition & 1 deletion almar/job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding=utf-8
from __future__ import unicode_literals, print_function

import io
import logging
from copy import copy
from datetime import datetime
Expand All @@ -17,6 +16,7 @@
log = logging.getLogger(__name__)
formatter = logging.Formatter('[%(asctime)s %(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%I:%S')


class Job(object):
def __init__(self, action, source_concept, target_concepts=None, sru=None, alma=None,
list_options=None):
Expand Down
5 changes: 2 additions & 3 deletions almar/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding=utf-8
from __future__ import unicode_literals, print_function
from collections import OrderedDict
import logging
from collections import OrderedDict

Expand All @@ -15,11 +14,11 @@
log = logging.getLogger(__name__)


def pick(options, alpha_options=[]):
def pick(options, alpha_options=None):
valid = OrderedDict()
for i, option in enumerate(options):
valid[str(i + 1)] = option
for option in alpha_options:
for option in alpha_options or []:
valid[option[0].upper()] = option

print()
Expand Down

0 comments on commit 5afbd4a

Please sign in to comment.