Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
RadioObservatory
LOFAR
Commits
f543e472
Commit
f543e472
authored
7 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
Task #8721: some documentation for most important methods.
parent
39de9228
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
LTA/ltastorageoverview/lib/scraper.py
+2
-0
2 additions, 0 deletions
LTA/ltastorageoverview/lib/scraper.py
LTA/ltastorageoverview/lib/store.py
+36
-0
36 additions, 0 deletions
LTA/ltastorageoverview/lib/store.py
with
38 additions
and
0 deletions
LTA/ltastorageoverview/lib/scraper.py
+
2
−
0
View file @
f543e472
...
...
@@ -58,6 +58,7 @@ class FileInfo:
return
self
.
filename
+
"
"
+
humanreadablesize
(
self
.
size
)
+
"
"
+
str
(
self
.
created_at
)
class
SrmlsException
(
Exception
):
'''
Exception which is raised when an srmls command failes
'''
def
__init__
(
self
,
command
,
exitcode
,
stdout
,
stderr
):
self
.
command
=
command
self
.
exitcode
=
exitcode
...
...
@@ -69,6 +70,7 @@ class SrmlsException(Exception):
(
self
.
command
,
self
.
exitcode
,
self
.
stdout
,
self
.
stderr
)
class
ParseException
(
Exception
):
'''
Exception which is raised when parsing srmls results fails
'''
def
__init__
(
self
,
message
):
self
.
message
=
message
...
...
This diff is collapsed.
Click to expand it.
LTA/ltastorageoverview/lib/store.py
+
36
−
0
View file @
f543e472
...
...
@@ -34,11 +34,23 @@ logger = logging.getLogger(__name__)
class
EntryNotFoundException
(
Exception
):
pass
class
LTAStorageDb
(
PostgresDatabaseConnection
):
"""
LTAStorageDb is a python API to the ltaso postgres database.
"""
def
__init__
(
self
,
dbcreds
=
None
,
log_queries
=
True
):
"""
Create an instance of a LTAStorageDb
:param dbcredentials.DBCredentials dbcreds: the credential for logging in into the db
:param bool log_queries: do or don
'
t log all queries
"""
super
(
LTAStorageDb
,
self
).
__init__
(
dbcreds
=
dbcreds
,
log_queries
=
log_queries
)
def
insertSite
(
self
,
siteName
,
srmurl
):
"""
insert a site into the database
:param string siteName: the name of the site
:param string srmurls: the srm url to that site
:return int: the new id of the inserted site
"""
site
=
self
.
siteByName
(
siteName
)
if
site
:
...
...
@@ -49,6 +61,13 @@ class LTAStorageDb(PostgresDatabaseConnection):
return
site_id
def
insertRootDirectory
(
self
,
siteName
,
rootDirectory
):
"""
Insert a root directory for a site. Each site has at least one root directory (with no parent).
For all non-root directories, use insertSubDirectory
:param string siteName: the name of the site (should already be in the database)
:param string rootDirectory: the full path of the directory
:return integer: the new id of the inserted root directory
"""
site
=
self
.
siteByName
(
siteName
)
if
not
site
:
...
...
@@ -63,6 +82,12 @@ class LTAStorageDb(PostgresDatabaseConnection):
return
dir_id
def
insertSubDirectory
(
self
,
parent_dir_id
,
sub_directory_path
):
"""
Insert a sub directory which is a child of the directory with parent_dir_id
:param int parent_dir_id: the id of this subdirectories parent
:param string sub_directory_path: the full path of the subdirectory
:return integer: the new id of the inserted subdirectory
"""
result
=
self
.
executeQuery
(
'
insert into lta.directory (name, parent_dir_id) values (%s, %s) returning id;
'
,
(
sub_directory_path
,
parent_dir_id
),
fetch
=
FETCH_ONE
)
if
result
and
'
id
'
in
result
:
...
...
@@ -72,6 +97,12 @@ class LTAStorageDb(PostgresDatabaseConnection):
return
None
def
insertSubDirectories
(
self
,
subDirectoryPaths
,
parentDirId
,
directoryLastVisitTime
=
None
):
"""
Insert multiple sub directories which are all a child of the directory with parent_dir_id
:param int parent_dir_id: the id of this subdirectories parent
:param [string] subDirectoryPaths: a list of full paths of the subdirectories
:return [integer]: a list of new ids of the inserted subdirectories
"""
with
self
.
_connection
.
cursor
()
as
cursor
:
insert_values
=
'
,
'
.
join
(
cursor
.
mogrify
(
'
(%s, %s)
'
,
(
name
,
parentDirId
))
for
name
in
subDirectoryPaths
)
...
...
@@ -105,6 +136,11 @@ class LTAStorageDb(PostgresDatabaseConnection):
return
subDirIds
def
deleteDirectory
(
self
,
dir_id
,
commit
=
True
):
"""
delete the directory with id dir_id. Cascacades and also deletes all subdirs, files and stats under this directory.
:param int dir_id: the id of the directory to be deleted
:param bool commit: optional, commit directly when True
"""
self
.
executeQuery
(
'
DELETE FROM lta.directory where id = %s;
'
,
(
dir_id
,),
fetch
=
FETCH_NONE
)
if
commit
:
...
...
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