diff --git a/s4/clarity/lims.py b/s4/clarity/lims.py index f4fb65e..3113807 100644 --- a/s4/clarity/lims.py +++ b/s4/clarity/lims.py @@ -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 @@ -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 diff --git a/s4/clarity/scripts/stepepp.py b/s4/clarity/scripts/stepepp.py index 0a99bfd..15d2da1 100644 --- a/s4/clarity/scripts/stepepp.py +++ b/s4/clarity/scripts/stepepp.py @@ -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)