Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fix bug: --retry-download with albums fails
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Feb 24, 2019
1 parent fa23925 commit d68c16d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions gphotos/GoogleAlbumsRow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class GoogleAlbumsRow(DbRow):
SyncFiles table
"""
table = "Albums"
cols_def = {'AlbumId': str, 'AlbumName': str, 'Size': int,
cols_def = {'RemoteId': str, 'AlbumName': str, 'Size': int,
'StartDate': datetime,
'EndDate': datetime, 'SyncDate': datetime}

# todo - overloading GoogleAlbumsRow as a Database Row does not really work
def to_media(self) -> DatabaseMedia:
db_media = DatabaseMedia(
_id=self.AlbumId,
_id=self.RemoteId,
_filename=self.AlbumName,
_size=self.Size,
_create_date=self.StartDate)
Expand All @@ -42,7 +42,7 @@ def from_media(cls, album: GoogleAlbumMedia) -> G:
@classmethod
def from_parm(cls, album_id, filename, size, start, end) -> G:
new_row = cls.make(
AlbumId=album_id,
RemoteId=album_id,
AlbumName=filename,
Size=size,
StartDate=start,
Expand Down
2 changes: 1 addition & 1 deletion gphotos/GoogleAlbumsSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def index_album_media(self):
gar = GoogleAlbumsRow.from_parm(
album.id, album.filename, album.size,
first_date, last_date)
self._db.put_row(gar)
self._db.put_row(gar, update=indexed_album)

next_page = results.get('nextPageToken')
if next_page:
Expand Down
6 changes: 3 additions & 3 deletions gphotos/LocalData.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def downloaded_count(self, downloaded: bool = True) -> int:

# functions for managing Albums ###########################################
def get_album(self, album_id: str) -> DatabaseMedia:
query = "SELECT {0} FROM Albums WHERE AlbumId = ?;".format(
query = "SELECT {0} FROM Albums WHERE RemoteId = ?;".format(
GoogleAlbumsRow.columns)
self.cur.execute(query, (album_id,))
res = self.cur.fetchone()
Expand All @@ -283,8 +283,8 @@ def get_album_files(self, album_id: str = '%'
"SELECT SyncFiles.Path, SyncFiles.Filename, Albums.AlbumName, "
"Albums.EndDate FROM AlbumFiles "
"INNER JOIN SyncFiles ON AlbumFiles.DriveRec=SyncFiles.RemoteId "
"INNER JOIN Albums ON AlbumFiles.AlbumRec=Albums.AlbumId "
"WHERE Albums.AlbumId LIKE ?;",
"INNER JOIN Albums ON AlbumFiles.AlbumRec=Albums.RemoteId "
"WHERE Albums.RemoteId LIKE ?;",
(album_id,))
results = self.cur.fetchall()
# fetchall does not need to use cur2
Expand Down
10 changes: 5 additions & 5 deletions gphotos/sql/gphotos_create.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
drop table if exists Albums;
create table Albums
(
AlbumId TEXT
RemoteId TEXT
primary key,
AlbumName TEXT,
Size INT,
Expand All @@ -11,12 +11,12 @@ create table Albums
SyncDate INT
)
;
DROP INDEX IF EXISTS Albums_AlbumId_uindex;
DROP INDEX IF EXISTS Albums_RemoteId_uindex;
DROP INDEX IF EXISTS Albums_StartDate_index;
DROP INDEX IF EXISTS Albums_AlbumName_index;

create unique index Albums_AlbumId_uindex
on Albums (AlbumId)
create unique index Albums_RemoteId_uindex
on Albums (RemoteId)
;
create index Albums_AlbumName_index
on Albums (AlbumName)
Expand Down Expand Up @@ -108,7 +108,7 @@ create table AlbumFiles
primary key,
AlbumRec INT,
DriveRec INT,
foreign key (AlbumRec) references Albums (AlbumId)
foreign key (AlbumRec) references Albums (RemoteId)
on delete cascade,
foreign key (DriveRec) references SyncFiles (Id)
on update cascade on delete cascade)
Expand Down
5 changes: 3 additions & 2 deletions test/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ def test_system_skip_video(self):

def test_system_retry_download(self):
s = ts.SetupDbAndCredentials()
# note we do index albums because there was a bug on retrying
# downloads with albums enabled
args = ['--start-date', '2017-01-01', '--end-date', '2018-01-01',
'--skip-video',
'--skip-albums']
'--skip-video']
s.test_setup('test_system_retry_download', args=args, trash_db=True,
trash_files=True)
s.gp.start(s.parsed_args)
Expand Down

0 comments on commit d68c16d

Please sign in to comment.