Skip to content
Snippets Groups Projects
Unverified Commit e6383e2e authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

ENH: make rerun an argument

parent 0709f919
No related branches found
No related tags found
No related merge requests found
......@@ -118,7 +118,7 @@ def main(rec_id):
xml = etree.tounicode(cont.to_xml(
local_serialization=True), pretty_print=True)
with open("test.txt", "w") as fi:
with open("caosdb_data.xml", "w") as fi:
fi.write(xml)
......
......@@ -33,9 +33,6 @@ from tempfile import NamedTemporaryFile
import caosdb as db
from caosmodels.data_model import DataModel
from lxml import etree
RERUN = False
def create_dummy_file(text="Please ask the administrator for this file."):
......@@ -47,7 +44,7 @@ def create_dummy_file(text="Please ask the administrator for this file."):
return tmpfile.name
def main(filename):
def main(filename, rerun=False):
cont = db.Container()
with open(filename) as fi:
cont = cont.from_xml(fi.read())
......@@ -78,7 +75,7 @@ def main(filename):
new_files = []
print(files)
if not RERUN:
if not rerun:
for fi in files:
new = db.File(file=fi.file, path=fi.path, name=fi.name, id=fi.id,
description=fi.description)
......@@ -110,7 +107,7 @@ def main(filename):
# insert files
if not RERUN:
if not rerun:
for i, el in enumerate(files):
print(el)
r = el.insert(unique=False)
......@@ -137,6 +134,9 @@ def main(filename):
def defineParser():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", help='file to be imported')
parser.add_argument("--rerun", help='if this script is run at least a'
' second time and files are already inserted',
action="store_true")
return parser
......@@ -145,4 +145,4 @@ if __name__ == "__main__":
parser = defineParser()
args = parser.parse_args()
main(args.file)
main(args.file, args.rerun)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment