1313
1414class Upload :
1515 """
16- This class contains the logic behind this program
17- It consist mainly in filesystem operations
18- It relies on:
19- - LycheeDAO for dtabases operations
20- - LycheePhoto to store (and compute) photos propreties
16+ High-level logic for uploading images to the remote server. The class is responsible for initiating SSH and
17+ database connections, checking whether albums exist and creating if needed and uploading photos to appropriate
18+ albums.
2119 """
2220
2321 def __init__ (self ):
@@ -30,18 +28,12 @@ def __init__(self):
3028 raise Exception ("Lychee configuration file not found. Please check the path to Lychee installation" )
3129
3230
33- def albumExists (self , album ):
34- """
35- Takes an album properties list as input. At least the relpath sould be specified (relative albumpath)
36- Returns an albumid or None if album does not exists
37- """
3831
3932 def createAlbum (self , album_name ):
4033 """
41- Creates an album
42- Inputs:
43- - album: an album properties list. at least path should be specified (relative albumpath)
44- Returns an albumid or None if album does not exists
34+ Create a new album
35+ :param album_name: The name of an album to create
36+ :return: Album id. None if the album cannot be created
4537 """
4638 album_id = None
4739 if album_name != "" :
@@ -52,10 +44,11 @@ def createAlbum(self, album_name):
5244
5345 def uploadPhoto (self , photo ):
5446 """
55- add a file to an album, the albumid must be previously stored in the LycheePhoto parameter
56- Parameters:
57- - photo: a valid LycheePhoto object
58- Returns True if everything went ok
47+ Upload a photo to the remote server and add it to the album it belongs to in the database. If database update
48+ fails for some reason, photos are deleted from the server.
49+
50+ :param photo: a valid LycheePhoto object
51+ :return: True if everything went ok
5952 """
6053 album_name = os .path .dirname (photo .srcfullpath ).split (os .sep )[- 1 ]
6154 file_name = os .path .basename (photo .srcfullpath )
@@ -91,10 +84,7 @@ def uploadPhoto(self, photo):
9184 def deleteFiles (self , filelist ):
9285 """
9386 Delete files in the Lychee file tree (uploads/big and uploads/thumbnails)
94- Give it the file name and it will delete relatives files and thumbnails
95- Parameters:
96- - filelist: a list of filenames
97- Returns nothing
87+ :param filelist: a list of filenames to delte
9888 """
9989
10090 for url in filelist :
@@ -111,22 +101,28 @@ def deleteFiles(self, filelist):
111101
112102
113103 def upload (self , albums ):
104+ """
105+ Upload photos stored in the provided dictionary, create albums. Accept a dictionary of album names and image
106+ paths as input parameter and convert each image path into a LycheePhoto object, which is passed to the
107+ uploadPhoto funciton.
108+ :param albums: a dictionary with albums and path names
109+ """
114110 print ("Uploading photos..." )
115111
116112 createdalbums , discoveredphotos , importedphotos = 0 , 0 , 0
117113
118- for album , files in albums .items ():
114+ for album_name , files in albums .items ():
119115 album_date = None
120- if album == "{unsorted}" :
116+ if album_name == "{unsorted}" :
121117 album_id = 0
122118 else :
123- album_id = self .dao .albumExists (album )
119+ album_id = self .dao .albumExists (album_name )
124120
125121 if album_id is None : # create album
126- album_id = self .createAlbum (album )
122+ album_id = self .createAlbum (album_name )
127123 createdalbums += 1
128124 elif conf .replace : # drop album photos
129- filelist = self .dao .eraseAlbum (album )
125+ filelist = self .dao .eraseAlbum (album_id )
130126 self .deleteFiles (filelist )
131127
132128 for full_path in files :
@@ -141,7 +137,7 @@ def upload(self, albums):
141137 importedphotos += 1
142138 else :
143139 file_name = os .path .basename (photo .srcfullpath )
144- logger .info ("Photo {}/{} already exists" .format (album , file_name ))
140+ logger .info ("Photo {}/{} already exists" .format (album_name , file_name ))
145141
146142 if album_id : # set correct album date
147143 self .dao .updateAlbumDate (album_id , album_date )
0 commit comments