Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62008684
studyInfo.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
Fri, May 10, 08:45
Size
3 KB
Mime Type
text/x-python
Expires
Sun, May 12, 08:45 (2 d)
Engine
blob
Format
Raw Data
Handle
17589953
Attached To
R3127 blackdynamite
studyInfo.py
View Options
#!/usr/bin/env python
from
__future__
import
print_function
################################################################
import
BlackDynamite
as
BD
import
psycopg2
################################################################
def
printDataBaseInfo
(
base
,
params
):
curs
=
base
.
connection
.
cursor
()
curs
.
execute
(
"select current_database()"
)
datname
=
curs
.
fetchone
()[
0
]
curs
.
execute
(
"""
select d.datname,
pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
from pg_catalog.pg_database d where (d.datname) = ('{0}')
"""
.
format
(
datname
))
datsize
=
curs
.
fetchone
()[
1
]
print
(
"Database:"
,
datname
,
datsize
)
def
printUserInfo
(
base
,
params
):
users
=
base
.
getUserList
()
print
(
'registered Users: {0}'
.
format
(
', '
.
join
(
users
)))
def
printStudyInfo
(
base
,
study
,
params
):
curs
=
base
.
connection
.
cursor
()
try
:
curs
.
execute
(
"""
select sz from (SELECT SUM(pg_total_relation_size(quote_ident(schemaname)
|| '.' || quote_ident(tablename)))::BIGINT
FROM pg_tables WHERE schemaname = '{0}') as sz
"""
.
format
(
study
))
schemasize
=
curs
.
fetchone
()[
0
]
curs
.
execute
(
"""
select pg_size_pretty(cast({0} as bigint))
"""
.
format
(
schemasize
))
schemasize
=
curs
.
fetchone
()[
0
]
except
psycopg2
.
ProgrammingError
:
schemasize
=
'-1'
curs
.
execute
(
"""
select count({0}.runs.id) from {0}.runs
"""
.
format
(
study
))
nruns
=
curs
.
fetchone
()[
0
]
curs
.
execute
(
"""
select count({0}.jobs.id) from {0}.jobs
"""
.
format
(
study
))
njobs
=
curs
.
fetchone
()[
0
]
owner
=
base
.
getStudyOwner
(
study
)
print
(
'{:10}:'
.
format
(
owner
),
'{:40}'
.
format
(
study
),
'#jobs:{:7} '
.
format
(
njobs
),
'#runs:{:7} '
.
format
(
nruns
),
'size:'
,
schemasize
)
if
params
[
'full'
]
is
False
:
return
#
# curs.execute("""
# SELECT distinct(schemaname,tablename) FROM pg_catalog.pg_tables
# where (tableowner, schemaname) = ('{0}', '{1}')
# """.format(datname,study))
# tables = [res[0][1:-1].split(',') for res in curs]
# # print (tables)
# for t in tables:
# curs.execute("""
# SELECT count(id) FROM {0}.{1}
# """.format(t[0], t[1]))
# cardinal = curs.fetchone()[0]
# print (t[0], t[1],': #',cardinal)
def
fetchInfo
(
base
,
params
):
printUserInfo
(
base
,
params
)
if
"study"
not
in
params
:
study_list
=
base
.
getSchemaList
(
filter_names
=
False
)
else
:
study_list
=
[
params
[
'study'
]]
printDataBaseInfo
(
base
,
params
)
for
s
in
study_list
:
printStudyInfo
(
base
,
s
,
params
)
def
main
(
argv
=
None
):
if
(
type
(
argv
)
==
str
):
argv
=
argv
.
split
()
parser
=
BD
.
BDParser
()
parser
.
register_params
(
group
=
"studyInfo.py"
,
params
=
{
"full"
:
bool
,
"study"
:
str
,
"grant"
:
str
,
"revoke"
:
str
},
help
=
{
"full"
:
"Say that you want details (can be costful)"
,
"study"
:
"specify a study to analyse"
,
"grant"
:
"specify an user to grant read permission"
,
"revoke"
:
"specify an user to revoke read permission"
})
params
=
parser
.
parseBDParameters
(
argv
=
argv
)
params
[
"should_not_check_study"
]
=
True
mybase
=
BD
.
Base
(
**
params
)
if
'study'
in
params
:
params
[
'study'
]
=
mybase
.
schema
if
'grant'
in
params
:
mybase
.
grantAccess
(
params
[
'study'
],
params
[
'grant'
])
if
'revoke'
in
params
:
mybase
.
revokeAccess
(
params
[
'study'
],
params
[
'revoke'
])
fetchInfo
(
mybase
,
params
)
if
__name__
==
'__main__'
:
main
()
Event Timeline
Log In to Comment