Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
633b3592
Commit
633b3592
authored
4 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
moved collect_datamodel program from a different repository
parent
31c9d0f5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!22
Release 0.3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/collect_datamodel.py
+110
-0
110 additions, 0 deletions
src/caosadvancedtools/collect_datamodel.py
with
110 additions
and
0 deletions
src/caosadvancedtools/collect_datamodel.py
0 → 100644
+
110
−
0
View file @
633b3592
#!/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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment