Commit 268d0b3c authored by thomas.forbriger's avatar thomas.forbriger

[WP] (csbusortdirlist): scan lines in file

parent 112a5af4
......@@ -16,7 +16,7 @@ This program takes a directory list like created by csbulistcsfiles.sh and
creates a sorted table which should support a completeness check.
"""
# ----------------------------------------------------------------------------
__version__ = "csbusortdirlist 2016-06-10"
__version__ = "2016-06-10"
__author__ = "Thomas Forbriger"
# ----------------------------------------------------------------------------
import sys
......@@ -24,7 +24,24 @@ import os
import string
import getopt
# ----------------------------------------------------------------------------
# exit status for any specific error
ERR_ERROR=100
# DEBUG output - global variable
DEBUG=False
# verbose output - global variable
VERBOSE=False
# name of checksum files
CHECKSUMFILE='checksumfile.cs'
# ============================================================================
# elementary functions
# --------------------
def usage():
"""
print usage information
......@@ -42,7 +59,8 @@ def help():
print(
"""
This program takes a directory list like created by csbulistcsfiles.sh and
creates a sorted table which should support a completeness check.
creates a sorted table which should support a completeness check. Pathnames
are expected to contain the string 'checksumfile.cs'.
listfile list of subdirectory path names
tablefile name of file to write table to
......@@ -52,19 +70,122 @@ creates a sorted table which should support a completeness check.
""")
print('Call "pydoc csbusortdirlist" to learn more')
# ----------------------------------------------------------------------------
def debugout(m):
"""
print debugging message
"""
if DEBUG:
print("DEBUG: "+ m)
# ----------------------------------------------------------------------------
def verbose(m):
"""
print verbose message
"""
if VERBOSE:
print(m)
# ============================================================================
class Basetable():
"""
Base class for table objects.
"""
# ============================================================================
class SEEDlinktable(Basetable):
"""
Class to hold a seedlink data structure
"""
# ============================================================================
class UIPCtable(Basetable):
"""
Class to hold a UIPC data structure
"""
# ============================================================================
class DL1table(Basetable):
"""
Class to hold a DL1 data structure
"""
# ============================================================================
class HPMOtable(Basetable):
"""
Class to hold a HPMO data structure
"""
# ============================================================================
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.datatype='seedlink'
elif substring.find('DL1') > 0:
self.datatype='DL1'
elif substring.find('HPMO') > 0:
self.datatype='HPMO'
elif substring.find('UIPC') > 0:
self.datatype='UIPC'
# ============================================================================
# processing functions
# --------------------
def readlist(filename):
"""
Read a list of subdirectory path names and return a table object
"""
debugout("entered function readlist")
verbose('read file %s' % filename)
for line in open(filename, 'r'):
inputline=line.rstrip('\n')
pathline=PathLine(inputline)
if pathline.datatype == 'seedlink':
debugout("seedlink")
debugout(pathline.pathname)
elif pathline.datatype == 'DL1':
debugout("DL1")
debugout(pathline.pathname)
elif pathline.datatype == 'HPMO':
debugout("HPMO")
debugout(pathline.pathname)
elif pathline.datatype == 'UIPC':
debugout("UIPC")
debugout(pathline.pathname)
else:
verbose("input line of unknown data type:")
verbose(line)
debugout("finished function readlist")
# ============================================================================
def main(argv=None):
"""
Then main function
"""
argv = sys.argv
(opts, args)=getopt.gnu_getopt(sys.argv[1:], 'voDh', ('help'))
verbose=False
overwrite=False
for opt in opts:
if (opt[0]=='-v'):
verbose=True
global VERBOSE
VERBOSE=True
elif (opt[0]=='-D'):
global DEBUG
DEBUG=True
......@@ -77,12 +198,14 @@ def main(argv=None):
usage()
exit(0)
if len(args) < 1:
if len(args) < 2:
usage()
exit(0)
inputfilename=args[0]
outputfilename=args[1]
tabledata=readlist(inputfilename)
# check for existing file
# if an exception is raised here, this is just fine: we do not want to
......@@ -91,8 +214,7 @@ def main(argv=None):
try:
output=open(outputfilename, 'r')
except IOError:
if verbose:
print('create new file %s' % outputfilename)
verbose('create new file %s' % outputfilename)
else:
print('ERROR: output file %s exists' % outputfilename)
exit(ERR_ERROR)
......
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