Mercurial > repos > guerler > dbkit
annotate dbkit_extract.py @ 5:184b00847620 draft default tip
"planemo upload commit 49504c53e0cdd7b98908b064fad4c0b8baeaa317"
author | guerler |
---|---|
date | Thu, 11 Mar 2021 19:31:37 +0000 |
parents | 03e124ff7e26 |
children |
rev | line source |
---|---|
2
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
1 #! /usr/bin/env python3 |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
2 import argparse |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
3 |
3
03e124ff7e26
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
2
diff
changeset
|
4 from dbkit_package.DBKit import DBKit, writeEntry |
2
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
5 |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
6 |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
7 def main(args): |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
8 logFile = open(args.log, "w") |
3
03e124ff7e26
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
2
diff
changeset
|
9 outputIndex = args.outputindex |
03e124ff7e26
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
2
diff
changeset
|
10 outputDatabase = args.outputdatabase |
2
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
11 entries = list() |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
12 with open(args.list, "r") as f: |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
13 for line in f: |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
14 name = line.split()[0] |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
15 entries.append(name) |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
16 logFile.write("Detected %s entries.\n" % len(entries)) |
3
03e124ff7e26
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
2
diff
changeset
|
17 fileName = "temp.dat" |
2
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
18 count = 0 |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
19 dbkit = DBKit(args.index, args.database) |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
20 for entry in sorted(entries): |
3
03e124ff7e26
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
2
diff
changeset
|
21 success = dbkit.createFile(entry, fileName) |
2
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
22 if success: |
3
03e124ff7e26
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
2
diff
changeset
|
23 writeEntry(entry, fileName, outputIndex, outputDatabase) |
2
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
24 count = count + 1 |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
25 else: |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
26 logFile.write("Entry %s not found.\n" % entry) |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
27 logFile.write("Extracted %s entries.\n" % count) |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
28 logFile.close() |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
29 |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
30 |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
31 if __name__ == "__main__": |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
32 parser = argparse.ArgumentParser(description='DBKit - Merge database pair.') |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
33 parser.add_argument('-l', '--list', help='List of entries to be extracted', required=True) |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
34 parser.add_argument('-i', '--index', help='Database Index file (ffindex)', required=True) |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
35 parser.add_argument('-d', '--database', help='Database Data file (ffdata)', required=True) |
3
03e124ff7e26
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
2
diff
changeset
|
36 parser.add_argument('-oi', '--outputindex', help='Output Index file', required=True) |
03e124ff7e26
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
2
diff
changeset
|
37 parser.add_argument('-od', '--outputdatabase', help='Output Data file', required=True) |
2
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
38 parser.add_argument('-g', '--log', help='Log file', required=True) |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
39 args = parser.parse_args() |
81c7d4668a7e
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
guerler
parents:
diff
changeset
|
40 main(args) |