Mercurial > repos > guerler > dbkit
comparison dbkit_create.py @ 3:03e124ff7e26 draft
"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
author | guerler |
---|---|
date | Wed, 16 Dec 2020 13:11:35 +0000 |
parents | 81c7d4668a7e |
children |
comparison
equal
deleted
inserted
replaced
2:81c7d4668a7e | 3:03e124ff7e26 |
---|---|
1 #! /usr/bin/env python3 | 1 #! /usr/bin/env python3 |
2 import argparse | 2 import argparse |
3 from os import system | 3 from os import remove |
4 from os.path import isfile, getsize | 4 from os.path import isfile, getsize |
5 import wget | |
6 | |
7 from dbkit_package.DBKit import writeEntry | |
5 | 8 |
6 | 9 |
7 def getIdentifiers(args): | 10 def getIdentifiers(args): |
8 entries = set() | 11 entries = set() |
9 with open(args.list) as file: | 12 with open(args.list) as file: |
26 entries = getIdentifiers(args) | 29 entries = getIdentifiers(args) |
27 logFile = open(args.log, "w") | 30 logFile = open(args.log, "w") |
28 logFile.write("Found %s entries.\n" % len(entries)) | 31 logFile.write("Found %s entries.\n" % len(entries)) |
29 outputIndex = args.index | 32 outputIndex = args.index |
30 outputDatabase = args.database | 33 outputDatabase = args.database |
31 system("rm -f %s" % outputDatabase) | 34 if isfile(outputDatabase): |
32 indexFile = open(outputIndex, 'w') | 35 remove(outputDatabase) |
33 start = 0 | |
34 for entryId in entries: | 36 for entryId in entries: |
35 logFile.write("Loading %s.\n" % entryId) | 37 logFile.write("Loading %s.\n" % entryId) |
36 if args.url: | 38 if args.url: |
37 fileName = "temp.dat" | 39 fileName = wget.download("%s%s" % (args.url, entryId)) |
38 system("wget -q -O %s %s%s" % (fileName, args.url, entryId)) | |
39 else: | 40 else: |
40 pathName = args.path.rstrip("/") | 41 pathName = args.path.rstrip("/") |
41 fileName = "%s/%s" % (pathName, entryId) | 42 fileName = "%s/%s" % (pathName, entryId) |
42 if isfile(fileName): | 43 if isfile(fileName): |
43 size = getsize(fileName) | 44 entrySize = getsize(fileName) |
44 if size == 0: | 45 if entrySize == 0: |
45 logFile.write("Entry `%s` not found.\n" % entryId) | 46 logFile.write("Entry `%s` not found.\n" % entryId) |
46 else: | 47 else: |
47 indexFile.write("%s\t%d\t%d\n" % (entryId, start, size)) | 48 writeEntry(entryId, fileName, outputIndex, outputDatabase) |
48 start = start + size | |
49 system("cat %s >> %s" % (fileName, outputDatabase)) | |
50 else: | 49 else: |
51 logFile.write("Content not found: %s.\n" % fileName) | 50 logFile.write("Content not found: %s.\n" % fileName) |
52 logFile.flush() | 51 logFile.flush() |
53 logFile.close() | 52 logFile.close() |
54 | 53 |