From c172f04d0463ad6696f133d21ed14b84779ea97e Mon Sep 17 00:00:00 2001 From: ialarmedalien Date: Fri, 14 Jul 2023 06:57:23 -0700 Subject: [PATCH] Fixing a few errors caught by eagle-eyed Bill --- .../narrative/contents/kbasewsmanager.py | 47 +++++++------------ src/biokbase/narrative/jobs/job.py | 3 -- src/scripts/kb-log-tail | 44 +++++++++++------ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/biokbase/narrative/contents/kbasewsmanager.py b/src/biokbase/narrative/contents/kbasewsmanager.py index 94e40ba0f3..752e11459d 100644 --- a/src/biokbase/narrative/contents/kbasewsmanager.py +++ b/src/biokbase/narrative/contents/kbasewsmanager.py @@ -16,18 +16,12 @@ """ import itertools import json - -# System import os import re -# IPython -# from IPython import nbformat import nbformat from nbformat import ValidationError, validate from notebook.services.contents.manager import ContentsManager - -# Third-party from tornado.web import HTTPError from traitlets.traitlets import List, Unicode @@ -39,16 +33,9 @@ from biokbase.narrative.services.user import UserService from .kbasecheckpoints import KBaseCheckpoints - -# Local -# Local from .manager_util import base_model from .narrativeio import KBaseWSManagerMixin -# ----------------------------------------------------------------------------- -# Classes -# ----------------------------------------------------------------------------- - class KBaseWSManager(KBaseWSManagerMixin, ContentsManager): """ @@ -139,9 +126,9 @@ def get_userid(self): """Return the current user id (if logged in), or None""" return util.kbase_env.user - def _clean_id(self, id): + def _clean_id(self, dirty_id): """Clean any whitespace out of the given id""" - return self.wsid_regex.sub("", id.replace(" ", "_")) + return self.wsid_regex.sub("", dirty_id.replace(" ", "_")) ##### # API part 1: methods that must be implemented in subclasses. @@ -152,8 +139,7 @@ def dir_exists(self, path): that dir, so it's real.""" if not path: return True - else: - return False + return False def is_hidden(self, path): """We can only see what gets returned from Workspace lookup, @@ -179,13 +165,12 @@ def file_exists(self, path): path ), ) - else: - raise HTTPError( - err.http_code, - "An error occurred while trying to find the Narrative with id {}".format( - path - ), - ) + raise HTTPError( + err.http_code, + "An error occurred while trying to find the Narrative with id {}".format( + path + ), + ) def exists(self, path): """Looks up whether a directory or file path (i.e. narrative) @@ -217,7 +202,11 @@ def _parse_path(self, path): raise HTTPError(404, "Invalid Narrative path {}".format(path)) try: return NarrativeRef( - dict(wsid=m.group("wsid"), objid=m.group("objid"), ver=m.group("ver")) + { + "wsid": m.group("wsid"), + "objid": m.group("objid"), + "ver": m.group("ver"), + } ) except RuntimeError as e: raise HTTPError(500, str(e)) @@ -300,7 +289,7 @@ def save(self, model, path): nb = result[0] self.validate_notebook_model(model) - validation_message = model.get("message", None) + validation_message = model.get("message") model = self.get(path, content=False) if validation_message: @@ -409,7 +398,7 @@ def validate_notebook_model(self, model): ) return model - def new_untitled(self, path="", type="", ext=""): + def new_untitled(self, path="", model_type="", ext=""): """Create a new untitled file or directory in path path must be a directory @@ -423,8 +412,8 @@ def new_untitled(self, path="", type="", ext=""): raise HTTPError(404, "No such directory: %s" % path) model = {} - if type: - model["type"] = type + if model_type: + model["type"] = model_type if ext == ".ipynb": model.setdefault("type", "notebook") diff --git a/src/biokbase/narrative/jobs/job.py b/src/biokbase/narrative/jobs/job.py index 810c5ddb3c..0aacc5e06e 100644 --- a/src/biokbase/narrative/jobs/job.py +++ b/src/biokbase/narrative/jobs/job.py @@ -243,9 +243,6 @@ def __setattr__(self, name, value): raise AttributeError( "Job attributes must be updated using the `update_state` method" ) - raise AttributeError( - "Job attributes must be updated using the `update_state` method" - ) object.__setattr__(self, name, value) diff --git a/src/scripts/kb-log-tail b/src/scripts/kb-log-tail index 2b20beff82..9f4a6719a3 100755 --- a/src/scripts/kb-log-tail +++ b/src/scripts/kb-log-tail @@ -10,26 +10,25 @@ import sys import pymongo import yaml -# -from bson import json_util - -# from bson import json_util logging.basicConfig() _log = logging.getLogger("kb-log-tail") + def error(msg): _log.error(msg) - + + def print_rec(rec): print(json.dumps(rec, indent=2, default=json_util.default)) + def main(args): conf = args.conf try: info = yaml.load(open(conf)) - for key in 'db_host', 'db_port', 'db', 'user', 'password': + for key in "db_host", "db_port", "db", "user", "password": if not key in info: error("Configuration file is missing value for '{}'".format(key)) return -1 @@ -43,15 +42,21 @@ def main(args): try: db = pymongo.MongoClient(info["db_host"], info["db_port"])[info["db"]] except pymongo.errors.PyMongoError as err: - error("Cannot connect to MongoDB '{}' at {}:{}".format( - info["db"], info["db_host"], info["db_port"])) + error( + "Cannot connect to MongoDB '{}' at {}:{}".format( + info["db"], info["db_host"], info["db_port"] + ) + ) if not db.authenticate(info["user"], info["password"]): - error("Could not authenticate to MongoDB '{}' at {}:{}".format( - info["db"], info["db_host"], info["db_port"])) + error( + "Could not authenticate to MongoDB '{}' at {}:{}".format( + info["db"], info["db_host"], info["db_port"] + ) + ) c = db[info["collection"]] recs = c.find({}, sort=[("created", -1)], limit=args.num) first = True - separator = '-' * 40 + separator = "-" * 40 for rec in recs: if not first: print(separator) @@ -61,14 +66,23 @@ def main(args): print("No records found") return 0 + def parse_args(): conf = os.environ.get("KBASE_PROXY_CONFIG", "narrative-log-proxy.conf") p = argparse.ArgumentParser(description=__doc__.strip()) - p.add_argument("-c", "--conf", dest='conf', default=conf, - help="Configuration file (default=%(default)s)") - p.add_argument("num", nargs='?', default=1, type=int, help="Number of records (default=1)") + p.add_argument( + "-c", + "--conf", + dest="conf", + default=conf, + help="Configuration file (default=%(default)s)", + ) + p.add_argument( + "num", nargs="?", default=1, type=int, help="Number of records (default=1)" + ) args = p.parse_args() return args -if __name__ == '__main__': + +if __name__ == "__main__": sys.exit(main(parse_args()))