comparison dbkit_package/DBKit.py @ 2:81c7d4668a7e draft

"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
author guerler
date Wed, 16 Dec 2020 12:02:48 +0000
parents
children 03e124ff7e26
comparison
equal deleted inserted replaced
1:987e55ea29b8 2:81c7d4668a7e
1 class DBKit:
2 def __init__(self, indexFile, databaseFile):
3 self.databaseFile = databaseFile
4 self.index = dict()
5 with open(indexFile) as file:
6 for line in file:
7 cols = line.split()
8 try:
9 identifier = cols[0]
10 start = int(cols[1])
11 size = int(cols[2])
12 self.index[identifier] = [start, size]
13 except Exception:
14 raise Exception("Invalid DBKit Index file format: %s." % line)
15
16 def createFile(self, identifier, outputName):
17 if identifier in self.index:
18 entry = self.index[identifier]
19 start = entry[0]
20 size = entry[1]
21 with open(self.databaseFile) as file:
22 file.seek(start)
23 content = file.read(size)
24 outputFile = open(outputName, "w")
25 outputFile.write(content)
26 outputFile.close()
27 return True
28 else:
29 return False
30
31 def getIndex(self):
32 return self.index