Skip to content
Snippets Groups Projects
Commit 633b3592 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

moved collect_datamodel program from a different repository

parent 31c9d0f5
No related branches found
No related tags found
1 merge request!22Release 0.3
#!/usr/bin/env python3
# encoding: utf-8
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
import argparse
import os
import caosdb as db
def get_dm():
rts = set([r.name for r in db.execute_query("SELECT name FROM RECORDTYPE")])
if None in rts:
rts.remove(None)
ps = set([r.name for r in db.execute_query("SELECT name FROM PROPERTY")])
if None in ps:
ps.remove(None)
return rts, ps
def get_parser():
p = argparse.ArgumentParser()
p.add_argument("-s", "--store", help="directory where the datamodel shall "
"be stored")
p.add_argument("-c", "--compare", help="directory where the datamodel that"
" shall be compared is stored")
return p
def store(directory):
rts, ps = get_dm()
os.makedirs(directory, exist_ok=True)
with open(os.path.join(directory, "recordtypes.txt"), "w") as fi:
fi.write(",".join(rts))
with open(os.path.join(directory, "properties.txt"), "w") as fi:
fi.write(",".join(ps))
def load_dm(directory):
with open(os.path.join(directory, "recordtypes.txt"), "r") as fi:
text = fi.read()
rts = [el.strip() for el in text.split(",")]
with open(os.path.join(directory, "properties.txt"), "r") as fi:
text = fi.read()
ps = [el.strip() for el in text.split(",")]
return rts, ps
def lower(li):
return [el.lower() for el in li]
def compare(directory):
rts, ps = get_dm()
stored_rts, stored_ps = load_dm(directory)
print("Comparing...")
for r in rts:
if r.lower() not in lower(stored_rts):
print("{} is missing in the stored recordtypes".format(r))
for p in ps:
if p.lower() not in lower(stored_ps):
print("{} is missing in the stored properties".format(p))
for r in stored_rts:
if r.lower() not in lower(rts):
print("{} is missing in the existing recordtypes".format(r))
for p in stored_ps:
if p.lower() not in lower(ps):
print("{} is missing in the existing properties".format(p))
if __name__ == "__main__":
p = get_parser()
args = p.parse_args()
if args.store:
store(args.store)
if args.compare:
compare(args.compare)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment