Skip to content

Commit

Permalink
Fix EPP log message duplication and missing log entries in Clarity 6+…
Browse files Browse the repository at this point in the history
… when combining Python automations with LLTK/LITKs (#51)

* Fix EPP log message duplication and missing log entries in Clarity 6+ when combining Python automations with LLTK/LITKs

* Fix current_minor_version failure on Python 2
  • Loading branch information
smallsco authored Jul 19, 2024
1 parent ee002de commit 2fef234
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
31 changes: 31 additions & 0 deletions s4/clarity/lims.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import logging
import re
import time

try:
import urllib.parse as urlparse # Python 3
except ImportError:
import urlparse # Python 2

from xml.etree import cElementTree as ETree

import requests
Expand Down Expand Up @@ -247,6 +253,31 @@ def properties(self):
properties = root.findall("property")
return dict( (property.get("name"), property.get("value")) for property in properties )

@lazy_property
def versions(self):
"""
:type: list[dict]
"""
root = self.request("get", self.root_uri + "/..")
versions = root.findall("version")
return list({
"uri": version.get("uri"),
"major": version.get("major"),
"minor": version.get("minor")
} for version in versions)

@lazy_property
def current_minor_version(self):
"""
:type: str
"""
path = urlparse.urlparse(self.root_uri).path
current_major_version = [x for x in path.split("/") if x][-1]
root = self.request("get", self.root_uri + "/..")
xpath = "version[@major='%s']" % current_major_version
version = root.findall(xpath)[0]
return version.get("minor")

def raw_request(self, method, uri, **kwargs):
"""
:type method: str
Expand Down
17 changes: 15 additions & 2 deletions s4/clarity/scripts/stepepp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,24 @@ def open_log_output_stream(self):
Use step's logfile.
"""
if self.options.logfile:

# Log files that are shared by Python and LLTK/LITKs on a step must
# use the same file name in order to prevent bugs. In Clarity 5 and
# earlier, the file name used by LLTK/LITKs is simply the limsid of
# the ResultFile. But in Clarity 6 and later it has "LogFile"
# appended to the name, and so we need to check the active Clarity
# version and adjust our behaviour accordingly.

filename = self.options.logfile
revision = int(self.lims.current_minor_version[1:])
if revision >= 31: # Clarity 6.0 has an API minor version of 31
filename = "%s-LogFile" % filename

if self.options.log_type == 'html':
filename = "%s.html" % self.options.logfile
filename = "%s.html" % filename
content_type = 'text/html'
elif self.options.log_type == 'text':
filename = "%s.log" % self.options.logfile
filename = "%s.log" % filename
content_type = 'text/plain'
else:
raise Exception("Unrecognized log type %s", self.options.log_type)
Expand Down

0 comments on commit 2fef234

Please sign in to comment.