Appstream import fixes
This commit is contained in:
parent
71ca47846d
commit
6f926a321c
|
@ -1,4 +1,5 @@
|
||||||
import gi
|
import gi
|
||||||
|
import PIL
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -54,6 +55,19 @@ session=db.session
|
||||||
licenses = { x.name : x for x in License.query.all() }
|
licenses = { x.name : x for x in License.query.all() }
|
||||||
tags = { x.name : x for x in Tag.query.all() }
|
tags = { x.name : x for x in Tag.query.all() }
|
||||||
admin_user = User.query.filter_by(username="appstream").first()
|
admin_user = User.query.filter_by(username="appstream").first()
|
||||||
|
|
||||||
|
|
||||||
|
for ss in PackageScreenshot.query.all():
|
||||||
|
if ss.package.cover_image == ss:
|
||||||
|
ss.package.cover_image = None
|
||||||
|
session.commit()
|
||||||
|
session.delete(ss)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
for game in Package.query.all():
|
||||||
|
session.delete(game)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
if not admin_user:
|
if not admin_user:
|
||||||
admin_user = User("appstream")
|
admin_user = User("appstream")
|
||||||
admin_user.is_active = True
|
admin_user.is_active = True
|
||||||
|
@ -71,10 +85,16 @@ for app in apps:
|
||||||
print("APPLICATION: ",app.get_name())
|
print("APPLICATION: ",app.get_name())
|
||||||
game1 = Package()
|
game1 = Package()
|
||||||
game1.state = PackageState.APPROVED
|
game1.state = PackageState.APPROVED
|
||||||
game1.name = app.get_id().replace('.','_')
|
game1.name = app.get_id().replace('.','_').replace('-','_')
|
||||||
game1.title = app.get_name()
|
game1.title = app.get_name()
|
||||||
game1.type = PackageType.GAME
|
game1.type = PackageType.GAME
|
||||||
game1.license = licenses["MIT"]
|
license = "Uknown" if app.get_project_license() is None else app.get_project_license().split("AND")[0].split("and")[0]
|
||||||
|
if license not in licenses:
|
||||||
|
row = License(license)
|
||||||
|
licenses[row.name] = row
|
||||||
|
session.add(row)
|
||||||
|
session.commit()
|
||||||
|
game1.license = licenses[license]
|
||||||
#game1.license = licenses[app.get_project_license()]
|
#game1.license = licenses[app.get_project_license()]
|
||||||
game1.media_license = licenses["MIT"]
|
game1.media_license = licenses["MIT"]
|
||||||
game1.author = admin_user
|
game1.author = admin_user
|
||||||
|
@ -92,25 +112,42 @@ for app in apps:
|
||||||
game1.desc = app.get_description()
|
game1.desc = app.get_description()
|
||||||
session.add(game1)
|
session.add(game1)
|
||||||
|
|
||||||
for i,screenshot in enumerate(screenshots):
|
for screenshot in screenshots:
|
||||||
ss = PackageScreenshot()
|
counter = 1
|
||||||
ss.package = game1
|
|
||||||
ss.title = "Untitled"
|
|
||||||
url = screenshot.get_url()
|
url = screenshot.get_url()
|
||||||
r = requests.get(url)
|
try:
|
||||||
filename = randomString(10) + "." + "png"
|
r = requests.get(url,timeout=10)
|
||||||
filepath = os.path.join("/var/cdb/uploads", filename)
|
r.raise_for_status()
|
||||||
with open(filepath,"wb") as f:
|
filename = randomString(10) + "." + "png"
|
||||||
f.write(r.content)
|
filepath = os.path.join("/var/cdb/uploads", filename)
|
||||||
|
print("Screenshot url: ", url)
|
||||||
|
with open(filepath,"wb") as f:
|
||||||
|
f.write(r.content)
|
||||||
|
|
||||||
ss.url = "uploads/" + filename
|
width, height = get_image_size(filepath)
|
||||||
ss.approved = True
|
|
||||||
ss.order = i
|
if (width is not None) and (height is not None):
|
||||||
ss.width, ss.height = get_image_size(filepath)
|
ss = PackageScreenshot()
|
||||||
session.add(ss)
|
ss.package = game1
|
||||||
session.commit()
|
ss.title = "Untitled"
|
||||||
game1.cover_image = ss
|
ss.url = "/uploads/" + filename
|
||||||
session.commit()
|
ss.width = width
|
||||||
|
ss.height = height
|
||||||
|
ss.approved = True
|
||||||
|
ss.order = counter
|
||||||
|
session.add(ss)
|
||||||
|
session.commit()
|
||||||
|
game1.cover_image = ss
|
||||||
|
session.commit()
|
||||||
|
counter += 1
|
||||||
|
except requests.exceptions.HTTPError as err:
|
||||||
|
print("HTTP error downloading the screenshot ", err)
|
||||||
|
except requests.exceptions.ConnectionError as err:
|
||||||
|
print("HTTP error downloading the screenshot ", err)
|
||||||
|
except requests.exceptions.ReadTimeout as err:
|
||||||
|
print("Screenshot timeout ", err)
|
||||||
|
except PIL.UnidentifiedImageError as err:
|
||||||
|
print("Corrupt image ", err)
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue