Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/archiver/storage.py
Show All 32 Lines | def archive_ls(self, cur=None): | ||||
""" Get all the archives registered on the server. | """ Get all the archives registered on the server. | ||||
Yields: | Yields: | ||||
a tuple (server_id, server_url) for each archive server. | a tuple (server_id, server_url) for each archive server. | ||||
""" | """ | ||||
yield from self.db.archive_ls(cur) | yield from self.db.archive_ls(cur) | ||||
@db_transaction_generator | @db_transaction_generator | ||||
def content_archive_get(self, content=None, cur=None): | def content_archive_get(self, content_id, cur=None): | ||||
""" Get the archival status of a content in a specific server. | """ Get the archival status of a content. | ||||
Retreive from the database the archival status of the given content | Retrieve from the database the archival status of the given content | ||||
in the given archive server. | |||||
Args: | Args: | ||||
content: the sha1 of the content. May be None for any id. | content_id: the sha1 of the content | ||||
archive: the database id of the server we're looking into | |||||
may be None for any server. | |||||
Yields: | Yields: | ||||
A tuple (content_id, server_id, archival status, mtime, tzinfo). | A tuple (content_id, present_copies, ongoing_copies), where | ||||
ongoing_copies is a dict mapping copy to mtime. | |||||
""" | """ | ||||
yield from self.db.content_archive_get(content, cur) | return self.db.content_archive_get(content_id, cur) | ||||
@db_transaction_generator | @db_transaction_generator | ||||
def content_archive_get_copies(self, previous_content=None, limit=1000, | def content_archive_get_copies(self, previous_content=None, limit=1000, | ||||
cur=None): | cur=None): | ||||
"""Get the list of copies for `limit` contents starting after | """Get the list of copies for `limit` contents starting after | ||||
`previous_content`. | `previous_content`. | ||||
Args: | Args: | ||||
previous_content: sha1 of the last content retrieved. May be None | previous_content: sha1 of the last content retrieved. May be None | ||||
to start at the beginning. | to start at the beginning. | ||||
limit: number of contents to retrieve. Can be None to retrieve all | limit: number of contents to retrieve. Can be None to retrieve all | ||||
objects (will be slow). | objects (will be slow). | ||||
Yields: | Yields: | ||||
A tuple (content_id, present_copies, ongoing_copies), where | A tuple (content_id, present_copies, ongoing_copies), where | ||||
ongoing_copies is a dict mapping copy to mtime. | ongoing_copies is a dict mapping copy to mtime. | ||||
""" | """ | ||||
yield from self.db.content_archive_get_copies(previous_content, limit, | yield from self.db.content_archive_get_copies(previous_content, limit, | ||||
cur) | cur) | ||||
@db_transaction | @db_transaction | ||||
def content_archive_update(self, content_id, archive_id, | def content_archive_update(self, content_id, archive_id, | ||||
new_status=None, cur=None): | new_status=None, cur=None): | ||||
""" Update the status of an archive content and set its mtime to | """ Update the status of an archive content and set its mtime to now | ||||
Change the mtime of an archived content for the given archive and set | Change the mtime of an archived content for the given archive and set | ||||
it's mtime to the current time. | it's mtime to the current time. | ||||
Args: | Args: | ||||
content_id (str): content sha1 | content_id (str): content sha1 | ||||
archive_id (str): name of the archive | archive_id (str): name of the archive | ||||
new_status (str): one of 'missing', 'present' or 'ongoing'. | new_status (str): one of 'missing', 'present' or 'ongoing'. | ||||
this status will replace the previous one. If not given, | this status will replace the previous one. If not given, | ||||
the function only change the mtime of the content for the | the function only change the mtime of the content for the | ||||
given archive. | given archive. | ||||
""" | """ | ||||
self.db.content_archive_update(content_id, archive_id, new_status, cur) | self.db.content_archive_update(content_id, archive_id, new_status, cur) |