Commit 2414eeb9 authored by Daniel Armbruster's avatar Daniel Armbruster Committed by thomas.forbriger
Browse files

implementation of csfile class proceeding

This is a legacy commit from before 2015-05-18.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.



SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4324
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 78a79f09
......@@ -36,29 +36,87 @@
import os
import re
import sys
import hashlib
class csFile:
def __init__(self, fname):
self.__fname = fname
self.__lines = []
__version__ = "V0.1"
__subversion__ = "Id: "
__license__ = "GPLv2"
__author__ = "Daniel Armbruster"
__copyright__ = "Copyright (c) 2011 by Daniel Armbruster"
def __init__(self, fname, dir, hashfunc=hashlib.sha256):
self.__fname = fname
self.__dir = dir
# -----------------------------------------------------------------------------
class CsFileError(Exception):
def __init__(self, msg):
self.msg = msg
def display(self):
sys.stderr.write("csFile (ERROR): " + self.msg + "\n")
# -----------------------------------------------------------------------------
class CsFile:
def __init__(self, filename, hashfunc=hashlib.sha256):
self.__filename = filename
self.__cslines = []
self.__hashfunc = hashfunc
def read(self):
if not os.path.isfile(self.__filename):
raise CsFileError("CSFILE is not a regular file.")
if 0 == os.stat(self.__filename).st_size:
raise CsFileError("CSFILE is an empty file.")
csfile = open(self.__filename)
try:
self.__cslines = [CsLine(line.split()) for line in csfile \
if len(line.rstrip()) and line[0] != '#']
finally:
csfile.close()
def __init__(self, fname, dir, regex, hashfunc=hashlib.sha256):
self.__fname = fname
self.__dir = dir
def write(self):
if 0 == len(self.__cslines):
raise CsFileError("CSFILE does not contain any lines.")
file = open(self.__filename, 'w')
for csline in self.__cslines:
file.write(str(csline) + '\n')
file.close()
def __getitem__(self, index):
return self.__lines[index]
def update(self, regex):
pass
def __setitem__(self, index, item):
self.__lines[index] = item
def checkLines(self):
if 0 == len(self.__cslines):
raise CsFileError("CSFILE does not contain any lines.")
for line in self.__cslines:
line.check()
def displayLines(self):
if 0 == len(self.__cslines):
raise CsFileError("CSFILE does not contain any lines.")
for line in self.__cslines:
sys.stdout.write(line)
def addLine(self, csline):
if isinstance(csline, CsLine):
self.__cslines.append(csline)
else:
raise CsFileError("Argument must be of type CsLine.")
class csLine:
def removeLine(self, index):
if 0 <= index and len(self.__cslines) >= index:
del self.__cslines[index]
else:
raise CsFileError("Index out of range.")
# -----------------------------------------------------------------------------
class CsLine:
def __init__(self, file, hashfunc = hashlib.sha256):
pass
# -----------------------------------------------------------------------------
if __name__ == '__main__':
pass
# ----- END OF csfile.py -----
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