Move parse_flowcell_id out of frontend.samples.results
[htsworkflow.git] / htsworkflow / util / conversion.py
1 """
2 Miscellaneous, more refined type casting functions
3 """
4
5 def unicode_or_none(value):
6     """
7     Convert value to unicode if its not none.
8     """
9     if value is None:
10         return None
11     else:
12         return unicode(value)
13
14 def parse_flowcell_id(flowcell_id):
15     """
16     Return flowcell id and any status encoded in the id
17   
18     We stored the status information in the flowcell id name.
19     this was dumb, but database schemas are hard to update.
20     """
21     fields = flowcell_id.split()
22     fcid = None
23     status = None
24     if len(fields) > 0:
25         fcid = fields[0]
26     if len(fields) > 1:
27         status = fields[1]
28     return fcid, status
29