@@ -50,7 +50,9 @@ def _write_summary(self):
5050
5151 def _reset_locked_snapshots (self ):
5252 """Reset locked snapshots to unprocessed in the database."""
53- self .db .session .execute (update (waybackup_snapshots ).where (waybackup_snapshots .response == "LOCK" ).values (response = None ))
53+ self .db .session .execute (
54+ update (waybackup_snapshots ).where (waybackup_snapshots .response == "LOCK" ).values (response = None )
55+ )
5456 self .db .session .commit ()
5557
5658 def _finalize_db (self ):
@@ -140,11 +142,19 @@ def _insert_batch_safe(line_batch):
140142 waybackup_snapshots .url_origin ,
141143 waybackup_snapshots .url_archive ,
142144 )
143- .filter (tuple_ (waybackup_snapshots .timestamp , waybackup_snapshots .url_origin , waybackup_snapshots .url_archive ).in_ (keys ))
145+ .filter (
146+ tuple_ (
147+ waybackup_snapshots .timestamp , waybackup_snapshots .url_origin , waybackup_snapshots .url_archive
148+ ).in_ (keys )
149+ )
144150 .all ()
145151 )
146152 existing_rows = set (existing )
147- new_rows = [row for row in unique_batch if (row ["timestamp" ], row ["url_origin" ], row ["url_archive" ]) not in existing_rows ]
153+ new_rows = [
154+ row
155+ for row in unique_batch
156+ if (row ["timestamp" ], row ["url_origin" ], row ["url_archive" ]) not in existing_rows
157+ ]
148158 if new_rows :
149159 self .db .session .bulk_insert_mappings (waybackup_snapshots , new_rows )
150160 self .db .session .commit ()
@@ -200,17 +210,25 @@ def _index_snapshots(self):
200210 # index for filtering last snapshots
201211 if self ._mode_last :
202212 idx1 = Index (
203- "idx_waybackup_snapshots_url_origin_timestamp_desc" , waybackup_snapshots .url_origin , waybackup_snapshots .timestamp .desc ()
213+ "idx_waybackup_snapshots_url_origin_timestamp_desc" ,
214+ waybackup_snapshots .url_origin ,
215+ waybackup_snapshots .timestamp .desc (),
204216 )
205217 idx1 .create (self .db .session .bind , checkfirst = True )
206218 # index for filtering first snapshots
207219 if self ._mode_first :
208220 idx2 = Index (
209- "idx_waybackup_snapshots_url_origin_timestamp_asc" , waybackup_snapshots .url_origin , waybackup_snapshots .timestamp .asc ()
221+ "idx_waybackup_snapshots_url_origin_timestamp_asc" ,
222+ waybackup_snapshots .url_origin ,
223+ waybackup_snapshots .timestamp .asc (),
210224 )
211225 idx2 .create (self .db .session .bind , checkfirst = True )
212226 # index for skippable snapshots
213- idx3 = Index ("idx_waybackup_snapshots_timestamp_url_origin_response" , waybackup_snapshots .timestamp , waybackup_snapshots .url_origin )
227+ idx3 = Index (
228+ "idx_waybackup_snapshots_timestamp_url_origin_response" ,
229+ waybackup_snapshots .timestamp ,
230+ waybackup_snapshots .url_origin ,
231+ )
214232 idx3 .create (self .db .session .bind , checkfirst = True )
215233
216234 def _filter_snapshots (self ):
@@ -224,7 +242,9 @@ def _filter_snapshots(self):
224242 def _filter_mode ():
225243 self ._filter_mode = 0
226244 if self ._mode_last or self ._mode_first :
227- ordering = waybackup_snapshots .timestamp .desc () if self ._mode_last else waybackup_snapshots .timestamp .asc ()
245+ ordering = (
246+ waybackup_snapshots .timestamp .desc () if self ._mode_last else waybackup_snapshots .timestamp .asc ()
247+ )
228248 # assign row numbers per url_origin
229249 rownum = (
230250 func .row_number ()
@@ -266,7 +286,9 @@ def _enumerate_counter():
266286
267287 _filter_mode ()
268288 _enumerate_counter ()
269- self ._filter_response = self .db .session .query (waybackup_snapshots ).where (waybackup_snapshots .response .in_ (["404" , "301" ])).count ()
289+ self ._filter_response = (
290+ self .db .session .query (waybackup_snapshots ).where (waybackup_snapshots .response .in_ (["404" , "301" ])).count ()
291+ )
270292 self .db .session .commit ()
271293
272294 def _skip_set (self ):
@@ -280,7 +302,12 @@ def _skip_set(self):
280302 for row in f :
281303 self .db .session .execute (
282304 update (waybackup_snapshots )
283- .where (and_ (waybackup_snapshots .timestamp == row ["timestamp" ], waybackup_snapshots .url_origin == row ["url_origin" ]))
305+ .where (
306+ and_ (
307+ waybackup_snapshots .timestamp == row ["timestamp" ],
308+ waybackup_snapshots .url_origin == row ["url_origin" ],
309+ )
310+ )
284311 .values (
285312 url_archive = row ["url_archive" ],
286313 redirect_url = row ["redirect_url" ],
0 commit comments