Initial port to python3
[htsworkflow.git] / htsworkflow / util / conversion.py
index 9246468fc9cf8c49d142eb905851c9517742e8da..bc9df065c806a0dc564a49689b287d0e98762d59 100644 (file)
@@ -9,4 +9,36 @@ def unicode_or_none(value):
     if value is None:
         return None
     else:
-        return unicode(value)
+        return str(value)
+
+def parse_flowcell_id(flowcell_id):
+    """
+    Return flowcell id and any status encoded in the id
+
+    We stored the status information in the flowcell id name.
+    this was dumb, but database schemas are hard to update.
+    """
+    fields = flowcell_id.split()
+    fcid = None
+    status = None
+    if len(fields) > 0:
+        fcid = fields[0]
+    if len(fields) > 1:
+        status = fields[1]
+    return fcid, status
+
+def parse_slice(slice_text):
+    if slice_text is None or len(slice_text) == 0:
+        return slice(None)
+
+    slice_data = []
+    for element in slice_text.split(':'):
+        if len(element) == 0:
+            element = None
+        else:
+            element = int(element)
+        slice_data.append(element)
+
+    return slice(*slice_data)
+
+