Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F72572806
saveBDStudy.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jul 15, 21:36
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Jul 17, 21:36 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
19061267
Attached To
R3127 blackdynamite
saveBDStudy.py
View Options
#!/usr/bin/env python3
import
BlackDynamite
as
BD
import
os
import
sys
import
subprocess
def
saveSchema
(
params
):
if
(
"out_file"
not
in
params
):
out_file
=
os
.
path
.
join
(
"./"
,
params
[
"study"
]
+
".db"
)
else
:
out_file
=
params
[
"out_file"
]
r
,
ext
=
os
.
path
.
splitext
(
out_file
)
if
(
not
ext
==
".gz"
):
out_file
+=
".gz"
print
(
"Saving study "
+
params
[
"study"
]
+
" to file "
+
out_file
)
command
=
(
"pg_dump --host "
+
params
[
"host"
]
+
" --schema="
+
params
[
"study"
]
+
" -C -f "
+
out_file
+
" --compress=9"
)
if
params
[
"verbose"
]
is
True
:
command
+=
" --verbose"
command
=
command
.
strip
()
.
split
(
" "
)
ret
=
subprocess
.
call
(
command
)
if
not
ret
==
0
:
sys
.
exit
(
"pg_dump error"
)
def
main
(
argv
=
None
):
if
isinstance
(
argv
,
str
):
argv
=
argv
.
split
()
parser
=
BD
.
BDParser
()
parser
.
register_params
(
group
=
"saveBDStudy.py"
,
params
=
{
"out_file"
:
str
,
"verbose"
:
bool
,
"study"
:
str
},
help
=
{
"out_file"
:
"Specify the filename where to save the study"
,
"verbose"
:
"Activate the verbose mode of pg_dump"
,
"study"
:
"specify the study to backup.
\
If none provided all studies are backed up"
})
params
=
parser
.
parseBDParameters
(
argv
=
argv
)
params
[
"should_not_check_study"
]
=
True
mybase
=
BD
.
Base
(
**
params
)
if
(
"study"
in
params
):
saveSchema
(
params
)
else
:
if
"out_file"
in
params
:
del
params
[
"out_file"
]
sch_list
=
mybase
.
getSchemaList
()
for
s
in
sch_list
:
params
[
"study"
]
=
s
saveSchema
(
params
)
if
__name__
==
'__main__'
:
main
()
Event Timeline
Log In to Comment