Mercurial > repos > guerler > springsuite
comparison spring_package/DBKit.py @ 39:172398348efd draft
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
author | guerler |
---|---|
date | Fri, 22 Jan 2021 15:50:27 +0000 |
parents | 0be0af9e695d |
children |
comparison
equal
deleted
inserted
replaced
38:80a4b98121b6 | 39:172398348efd |
---|---|
1 def createFile(identifier, databaseIndex, database, outputName): | 1 from os.path import isfile |
2 start = -1 | 2 |
3 size = 0 | 3 |
4 with open(databaseIndex) as file: | 4 class DBKit: |
5 for line in file: | 5 def __init__(self, indexFile, databaseFile): |
6 cols = line.split() | 6 if not isfile(indexFile): |
7 if identifier == cols[0]: | 7 raise Exception("Index file not found: %s." % indexFile) |
8 start = int(cols[1]) | 8 if not isfile(databaseFile): |
9 size = int(cols[2]) | 9 raise Exception("Database file not found: %s." % databaseFile) |
10 break | 10 self.databaseFile = databaseFile |
11 if start != -1 and size > 0: | 11 self.index = dict() |
12 with open(database) as file: | 12 with open(indexFile) as file: |
13 file.seek(start) | 13 for line in file: |
14 content = file.read(size) | 14 cols = line.split() |
15 outputFile = open(outputName, "w") | 15 try: |
16 outputFile.write(content) | 16 identifier = cols[0] |
17 outputFile.close() | 17 start = int(cols[1]) |
18 return True | 18 size = int(cols[2]) |
19 else: | 19 self.index[identifier] = [start, size] |
20 return False | 20 except Exception: |
21 raise Exception("Invalid DBKit Index file format: %s." % line) | |
22 | |
23 def createFile(self, identifier, outputName): | |
24 if identifier in self.index: | |
25 entry = self.index[identifier] | |
26 start = entry[0] | |
27 size = entry[1] | |
28 with open(self.databaseFile) as file: | |
29 file.seek(start) | |
30 content = file.read(size) | |
31 outputFile = open(outputName, "w") | |
32 outputFile.write(content) | |
33 outputFile.close() | |
34 return True | |
35 else: | |
36 return False |