fix: multiple storages with folder column

pull/74/head
msramalho 2023-05-09 12:14:07 +01:00
rodzic ae3e607705
commit 9c25b33f1c
4 zmienionych plików z 11 dodań i 5 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ from googleapiclient.errors import HttpError
# You can run this code to get a new token and verify it belongs to the correct user
# This token will be refresh automatically by the auto-archiver
# Code below from https://developers.google.com/drive/api/quickstart/python
# Example invocation: py scripts/create_update_gdrive_oauth_token.py -c secrets/credentials.json -t secrets/gd-token.json
SCOPES = ['https://www.googleapis.com/auth/drive']

Wyświetl plik

@ -19,7 +19,7 @@ class Media:
urls: List[str] = field(default_factory=list)
properties: dict = field(default_factory=dict)
_mimetype: str = None # eg: image/jpeg
_stored: bool = field(default=False, repr=False, metadata=config(exclude=lambda _: True)) # always exclude
_stored: bool = field(default=False, repr=False, metadata=config(exclude=lambda _: True)) # always exclude
def store(self: Media, override_storages: List = None, url: str = "url-not-available"):
# stores the media into the provided/available storages [Storage]
@ -42,7 +42,7 @@ class Media:
s.store(prop_media, url)
def is_stored(self) -> bool:
return len(self.urls) > 0
return len(self.urls) > 0 and len(self.urls) == len(ArchivingContext.get("storages"))
def set(self, key: str, value: Any) -> Media:
self.properties[key] = value

Wyświetl plik

@ -64,8 +64,13 @@ class GsheetsFeeder(Gsheets, Feeder):
# All checks done - archival process starts here
m = Metadata().set_url(url)
ArchivingContext.set("gsheet", {"row": row, "worksheet": gw}, keep_on_reset=True)
if self.use_sheet_names_in_stored_paths:
ArchivingContext.set("folder", os.path.join(slugify(self.sheet), slugify(wks.title)), True)
folder = slugify(gw.get_cell(row, 'folder').strip())
if len(folder):
if self.use_sheet_names_in_stored_paths:
ArchivingContext.set("folder", os.path.join(folder, slugify(self.sheet), slugify(wks.title)), True)
else:
ArchivingContext.set("folder", folder, True)
yield m
logger.success(f'Finished worksheet {wks.title}')

Wyświetl plik

@ -43,7 +43,7 @@ class Storage(Step):
def store(self, media: Media, url: str) -> None:
if media.is_stored():
logger.debug(f"{self.key} already stored, skipping")
logger.debug(f"{media.key} already stored, skipping")
return
self.set_key(media, url)
self.upload(media)