mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 18:44:23 +00:00
Update SAS migration script
This commit is contained in:
parent
47cb5e60ce
commit
7969e9ba5f
27
migrate.py
27
migrate.py
@ -1029,8 +1029,9 @@ def migrate_sas():
|
||||
album_link = {}
|
||||
picture_link = {}
|
||||
FILE_ROOT = "/data/sas/"
|
||||
SithFile.objects.filter(id__gt=18886).delete()
|
||||
SithFile.objects.filter(id__gte=18892).delete()
|
||||
print("Album/Pictures deleted")
|
||||
reset_index('core', 'sas')
|
||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||
cur.execute("""
|
||||
SELECT *
|
||||
@ -1058,10 +1059,20 @@ def migrate_sas():
|
||||
except: pass
|
||||
print("Album migrated at %s" % datetime.datetime.now())
|
||||
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||
with open("albums.link", "w") as f:
|
||||
f.write(str(album_link))
|
||||
cur.close()
|
||||
finished = False
|
||||
chunk = 0
|
||||
while not finished:
|
||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||
cur.execute("""
|
||||
SELECT *
|
||||
FROM sas_photos
|
||||
""")
|
||||
ORDER BY 'id_photo'
|
||||
LIMIT %s, 1000
|
||||
""", (chunk*1000, ))
|
||||
has_result = False
|
||||
for r in cur:
|
||||
try:
|
||||
user = User.objects.filter(id=r['id_utilisateur']).first() or root
|
||||
@ -1075,10 +1086,10 @@ def migrate_sas():
|
||||
file_name += "/" + str(r['id_photo']) + ".jpg"
|
||||
|
||||
file = File(open(file_name, "rb"))
|
||||
file.name = str(r['id_photo']) + ".jpg"
|
||||
file.name = (str(r['id_photo']) + ".jpg").encode('utf-8')
|
||||
|
||||
p = Picture(
|
||||
name=to_unicode(str(r['id_photo'])) + ".jpg",
|
||||
name=(to_unicode(str(r['id_photo'])) + ".jpg").encode('utf-8'),
|
||||
owner=user,
|
||||
is_moderated=True,
|
||||
is_folder=False,
|
||||
@ -1094,6 +1105,7 @@ def migrate_sas():
|
||||
if f.name == "date":
|
||||
f.auto_now = False
|
||||
p.generate_thumbnails()
|
||||
p.save()
|
||||
db2 = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
|
||||
cur2 = db2.cursor(MySQLdb.cursors.SSDictCursor)
|
||||
cur2.execute("""
|
||||
@ -1108,11 +1120,14 @@ def migrate_sas():
|
||||
PeoplePictureRelation(user=u, picture=p).save()
|
||||
except:
|
||||
print("Fail to associate user %d to picture %d" % (r2['id_utilisateur'], p.id))
|
||||
picture_link[str(r['id_photo'])] = p.id
|
||||
has_result = True
|
||||
except Exception as e:
|
||||
pass
|
||||
print("FAIL to migrate Picture: %s" % (repr(e)))
|
||||
cur.close()
|
||||
print("Chunk %d migrated at %s" % (chunk, str(datetime.datetime.now())))
|
||||
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||
chunk += 1
|
||||
finished = not has_result
|
||||
print("SAS migrated at %s" % datetime.datetime.now())
|
||||
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user