Commit bcf946a6 authored by thomas.forbriger's avatar thomas.forbriger

[WP] (csbusortdirlist): parse path name lines

parent 268d0b3c
......@@ -93,52 +93,136 @@ class Basetable():
Base class for table objects.
"""
def __init__(self, pathname):
"""
Constructor: initialize from path name
"""
self.collection='Unknown'
# ============================================================================
class SEEDlinktable(Basetable):
"""
Class to hold a seedlink data structure
"""
def __init__(self, pathname):
"""
Constructor: initialize from path name
"""
# ============================================================================
class UIPCtable(Basetable):
"""
Class to hold a UIPC data structure
"""
def __init__(self, pathname):
"""
Constructor: initialize from path name
"""
# ============================================================================
class DL1table(Basetable):
"""
Class to hold a DL1 data structure
"""
def __init__(self, pathname):
"""
Constructor: initialize from path name
"""
# ============================================================================
class HPMOtable(Basetable):
"""
Class to hold a HPMO data structure
"""
def __init__(self, pathname):
"""
Constructor: initialize from path name
"""
# ============================================================================
class Unknowntable(Basetable):
"""
Class to hold an unkown data structure
"""
def __init__(self, pathname):
"""
Constructor: initialize from path name
"""
# ============================================================================
class PathLine():
"""
Class to hold and parse a sinlge input line.
"""
# ----------------------------------------------------------------------------
def __init__(self, line):
"""
Constructor takes an input line string
"""
self.datatype='Unknown'
for substring in line.split():
if substring.find(CHECKSUMFILE) > 0:
self.pathname=substring
if substring.find('seedlink') > 0:
self.collection='Unknown'
self.year='Unknown'
self.channel='Unknown'
self.pathname=line
for s in line.split():
if s.find(CHECKSUMFILE) > 0:
self.pathname=s
if s.find('seedlink') > 0:
self.datatype='seedlink'
elif substring.find('DL1') > 0:
keys=s[s.index('seedlink'):].split('/')
if len(keys) > 2:
self.year=keys[1]
if len(keys) > 4:
self.collection=keys[2]+':'+keys[3]
if len(keys) > 5:
self.channel=keys[4]
elif s.find('DL1') > 0:
self.datatype='DL1'
elif substring.find('HPMO') > 0:
keys=s[s.index('DL1'):].split('/')
if len(keys) > 2:
self.collection=keys[1]+':'+keys[2]
if len(keys) > 4:
self.year=keys[3]
if len(keys) > 5:
self.channel=keys[4]
elif s.find('HPMO') > 0:
self.datatype='HPMO'
elif substring.find('UIPC') > 0:
keys=s[s.index('HPMO/'):].split('/')
if len(keys) > 2:
self.collection=keys[1]
if keys[1] == 'HPMO_SNIFF':
self.collection=keys[1]
if len(keys) > 4:
self.year=keys[3]
if len(keys) > 5:
self.channel=keys[4][4:6]
elif s.find('UIPC') > 0:
self.datatype='UIPC'
keys=s[s.index('UIPC'):].split('/')
if len(keys) > 2:
self.year=keys[1][0:4]
if len(keys) > 3:
self.collection=keys[2]
if len(keys) > 4:
self.channel=keys[3]
else:
self.channel='std'
# ----------------------------------------------------------------------------
def report(self):
"""
Report contents to stdout
"""
print('type: %s collection: %s year: %s channel: %s' %
(self.datatype, self.collection, self.year, self.channel))
print(' %s' % self.pathname)
# ============================================================================
# processing functions
......@@ -150,24 +234,33 @@ def readlist(filename):
debugout("entered function readlist")
verbose('read file %s' % filename)
tables=dict()
for line in open(filename, 'r'):
inputline=line.rstrip('\n')
pathline=PathLine(inputline)
pathline.report()
if pathline.datatype == 'seedlink':
debugout("seedlink")
debugout(pathline.pathname)
table=SEEDlinktable(pathline.pathname)
elif pathline.datatype == 'DL1':
debugout("DL1")
debugout(pathline.pathname)
table=DL1table(pathline.pathname)
elif pathline.datatype == 'HPMO':
debugout("HPMO")
debugout(pathline.pathname)
table=HPMOtable(pathline.pathname)
elif pathline.datatype == 'UIPC':
debugout("UIPC")
debugout(pathline.pathname)
table=UIPCtable(pathline.pathname)
else:
verbose("input line of unknown data type:")
verbose(line)
table=Unknowntable(pathline.pathname)
# tables[table.collection]=table
debugout("finished function readlist")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment