Fix 20_to_21 to not rely on current library code. Copy algorithm.
This commit is contained in:
parent
f2d5853b29
commit
b8e64056fb
1 changed files with 12 additions and 10 deletions
|
@ -1,8 +1,9 @@
|
||||||
import time
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from voussoirkit import gentools
|
||||||
from voussoirkit import vlogging
|
from voussoirkit import vlogging
|
||||||
|
|
||||||
import etiquette
|
import etiquette
|
||||||
|
@ -810,18 +811,19 @@ def upgrade_20_to_21(photodb):
|
||||||
new_thumbnail.parent.makedirs(exist_ok=True)
|
new_thumbnail.parent.makedirs(exist_ok=True)
|
||||||
shutil.move(old_thumbnail.absolute_path, new_thumbnail.absolute_path)
|
shutil.move(old_thumbnail.absolute_path, new_thumbnail.absolute_path)
|
||||||
|
|
||||||
photos = photodb.get_photos()
|
rows = photodb.select('SELECT id, thumbnail FROM photos where thumbnail IS NOT NULL')
|
||||||
import shutil
|
for row in rows:
|
||||||
for photo in photos:
|
photo_id = row['id']
|
||||||
if photo.thumbnail is None:
|
chunked_id = [''.join(chunk) for chunk in gentools.chunk_generator(str(photo_id), 3)]
|
||||||
continue
|
folder = chunked_id[:-1]
|
||||||
old_thumbnail = photo.thumbnail
|
folder = os.sep.join(folder)
|
||||||
new_thumbnail = photo.make_thumbnail_filepath()
|
folder = photodb.thumbnail_directory.join(folder)
|
||||||
|
old_thumbnail = photodb.thumbnail_directory.join(row['thumbnail'])
|
||||||
|
new_thumbnail = folder.with_child(f'{photo_id}.jpg')
|
||||||
print(old_thumbnail, new_thumbnail)
|
print(old_thumbnail, new_thumbnail)
|
||||||
photodb.on_commit_queue.append({'action': movethumbnail, 'args': (old_thumbnail, new_thumbnail)})
|
photodb.on_commit_queue.append({'action': movethumbnail, 'args': (old_thumbnail, new_thumbnail)})
|
||||||
store_as = new_thumbnail.relative_to(photodb.thumbnail_directory)
|
store_as = new_thumbnail.relative_to(photodb.thumbnail_directory)
|
||||||
photodb.update(table=etiquette.objects.Photo, pairs={'id': photo.id, 'thumbnail': store_as}, where_key='id')
|
photodb.update(table=etiquette.objects.Photo, pairs={'id': photo_id, 'thumbnail': store_as}, where_key='id')
|
||||||
photo.thumbnail = new_thumbnail
|
|
||||||
|
|
||||||
def upgrade_21_to_22(photodb):
|
def upgrade_21_to_22(photodb):
|
||||||
m = Migrator(photodb)
|
m = Migrator(photodb)
|
||||||
|
|
Loading…
Reference in a new issue