Skip to content

Commit

Permalink
Fixing a few errors caught by eagle-eyed Bill
Browse files Browse the repository at this point in the history
  • Loading branch information
ialarmedalien committed Jul 14, 2023
1 parent 1e94d70 commit c172f04
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
47 changes: 18 additions & 29 deletions src/biokbase/narrative/contents/kbasewsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
"""
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
3 changes: 0 additions & 3 deletions src/biokbase/narrative/jobs/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
44 changes: 29 additions & 15 deletions src/scripts/kb-log-tail
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()))

0 comments on commit c172f04

Please sign in to comment.