Mercurial > repos > guerler > dbkit
diff 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 |
line wrap: on
line diff
--- a/dbkit_create.py Wed Dec 16 12:02:48 2020 +0000 +++ b/dbkit_create.py Wed Dec 16 13:11:35 2020 +0000 @@ -1,7 +1,10 @@ #! /usr/bin/env python3 import argparse -from os import system +from os import remove from os.path import isfile, getsize +import wget + +from dbkit_package.DBKit import writeEntry def getIdentifiers(args): @@ -28,25 +31,21 @@ logFile.write("Found %s entries.\n" % len(entries)) outputIndex = args.index outputDatabase = args.database - system("rm -f %s" % outputDatabase) - indexFile = open(outputIndex, 'w') - start = 0 + if isfile(outputDatabase): + remove(outputDatabase) for entryId in entries: logFile.write("Loading %s.\n" % entryId) if args.url: - fileName = "temp.dat" - system("wget -q -O %s %s%s" % (fileName, args.url, entryId)) + fileName = wget.download("%s%s" % (args.url, entryId)) else: pathName = args.path.rstrip("/") fileName = "%s/%s" % (pathName, entryId) if isfile(fileName): - size = getsize(fileName) - if size == 0: + entrySize = getsize(fileName) + if entrySize == 0: logFile.write("Entry `%s` not found.\n" % entryId) else: - indexFile.write("%s\t%d\t%d\n" % (entryId, start, size)) - start = start + size - system("cat %s >> %s" % (fileName, outputDatabase)) + writeEntry(entryId, fileName, outputIndex, outputDatabase) else: logFile.write("Content not found: %s.\n" % fileName) logFile.flush()