From b3826ad1d74f5f415008674dd5b385a4b659539f Mon Sep 17 00:00:00 2001 From: Rampoina Date: Tue, 15 Feb 2022 22:35:35 +0100 Subject: [PATCH] Add appstream tool to add games to the database from an appstream.gz collection --- Dockerfile | 5 +++ utils/appstream.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++ utils/lists.py | 72 +++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 utils/appstream.py create mode 100644 utils/lists.py diff --git a/Dockerfile b/Dockerfile index 512fc49..b6a7ee5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,13 @@ RUN mkdir /var/cdb RUN chown -R cdb:cdb /var/cdb COPY requirements.lock.txt requirements.lock.txt +RUN apt update +RUN apt install -y vim +RUN apt install -y libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0 +RUN apt install -y libappstream-glib-dev RUN pip install -r requirements.lock.txt RUN pip install gunicorn +RUN pip3 install pycairo PyGObject COPY utils utils COPY config.cfg config.cfg diff --git a/utils/appstream.py b/utils/appstream.py new file mode 100644 index 0000000..9cea1ad --- /dev/null +++ b/utils/appstream.py @@ -0,0 +1,93 @@ +import gi +import os +import sys +import inspect +from gi.repository import Gio +gi.require_version('AppStreamGlib', '1.0') +from gi.repository import AppStreamGlib +from lists import alwaysAccept, alwaysDeny, badLicenses, badCategories, nonFreeAssets, nonFreeNetworkServices +import itertools +import argparse + +#Workaround to get the urls because app.get_urls() doesn't work :| +def get_urls(app): + kinds = [AppStreamGlib.UrlKind(kind) for kind in range(11)] + urls = [(app.get_url_item(kind),kind.value_nick) for kind in kinds] + return list(filter(lambda a: a[0] is not None, urls)) + +def acceptedGame(app): + #return 'Game' in app.get_categories() + if app.get_id() in alwaysAccept: + return True + if app.get_id() in alwaysDeny: + return False + + return app.get_project_license() and \ + not [x for x in badLicenses if x in app.get_project_license()] and \ + 'Game' in app.get_categories() and \ + not [x for x in badCategories if x in app.get_categories()] + +def getScreenshot(app): + return [images.get_source() for images in app.get_screenshots] + +currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +parentdir = os.path.dirname(currentdir) +sys.path.insert(0,parentdir) + +from app.models import * +from app.utils import make_flask_login_password + +parser = argparse.ArgumentParser(description='Generate HTML files from an Appimage and mako templates.') +parser.add_argument("-p", '--appstream_path', help='specify the path of the appstream file') +parser.add_argument("-i", '--icons_path', help='specify the path of the icons') +parser.add_argument("-m", '--template_path', help='specify the path of the template') +args = parser.parse_args() + +store = AppStreamGlib.Store() +file = Gio.File.new_for_path(args.appstream_path) +AppStreamGlib.Store.from_file(store, file, args.icons_path, None) +apps = list(filter(acceptedGame, store.get_apps())) +session=db.session +licenses = { x.name : x for x in License.query.all() } +tags = { x.name : x for x in Tag.query.all() } +admin_user = User.query.filter_by(username="appstream").first() +#print("Users: ", users) +#admin_user = User("appstream") +#admin_user.is_active = True +#admin_user.password = make_flask_login_password("appstream") +#admin_user.github_username = "appstream" +#admin_user.forums_username = "appstream" +#admin_user.rank = UserRank.ADMIN +#session.add(admin_user) + + +for app in apps: + screenshots = getScreenshots(app) + urls = get_urls(app) + filename = app.get_name().replace(':', '').replace('/','') + ".html" + print("APPLICATION: ",app.get_name()) + game1 = Package() + game1.state = PackageState.APPROVED + game1.name = app.get_id() + game1.title = app.get_name() + game1.type = PackageType.GAME + game1.license = licenses["MIT"] + #game1.license = licenses[app.get_project_license()] + game1.media_license = licenses["MIT"] + game1.author = admin_user + game1.tags.append(tags["pvp"]) + game1.tags.append(tags["survival"]) + game1.tags.append(tags["multiplayer"]) + for url,t in urls: + if t == "bugtracker": + game1.issueTracker = url + elif t == "homepage": + game1.repo = url + + game1.forums = 12835 + game1.short_desc = app.get_comment() + game1.desc = app.get_description() + session.add(game1) + +session.commit() + diff --git a/utils/lists.py b/utils/lists.py new file mode 100644 index 0000000..d90b090 --- /dev/null +++ b/utils/lists.py @@ -0,0 +1,72 @@ +badLicenses = [ + 'LicenseRef-proprietary', + 'LicenseRef-Proprietary', + 'proprietary', + 'Proprietary', + 'CC-BY-NC-SA-3.0', + 'CC-BY-NC-ND-3.0' +] + +badCategories = [ + 'Emulator', + 'PackageManager', + 'System', + 'Utility' +] + +nonFreeAssets = [ + 'jp.yvt.OpenSpades', + 'net.openra.OpenRA', + 'org.openmw.OpenMW', + 'org.zdoom.GZDoom', + 'io.github.ezQuake', + 'com.etlegacy.ETLegacy', + 'com.github.iortcw.iortcw', + 'org.yamagi.YamagiQ2', + 'org.dhewm3.Dhewm3', + 'com.github.bvschaik.julius', + 'io.openrct2.OpenRCT2', + 'com.github.skullernet.q2pro', + 'org.raceintospace.Raceintospace', + 'org.srb2.SRB2', + 'org.srb2.SRB2Kart', + 'io.sourceforge.clonekeenplus', + 'io.github.fabiangreffrath.Doom', + 'net.dengine.Doomsday', + 'com.github.keriew.augustus', + 'io.github.yairm210.unciv', + 'com.corsixth.corsixth' +] + +nonFreeNetworkServices = [ + 'io.github.yairm210.unciv' +] + +alwaysAccept = [ + 'org.freecol.FreeCol', + 'org.freeciv.Freeciv', + 'io.github.EndlessSky.endless-sky', + 'org.frozen_bubble.frozen-bubble', + 'org.kde.ksudoku', +] + +alwaysDeny = [ + 'com.moonlight_stream.Moonlight', + 'org.gnome.Games', + 'org.ppsspp.PPSSPP', + 'org.scummvm.ScummVM', + 'org.pegasus_frontend.Pegasus', + 'com.gitlab.coringao.cavestory-nx', + 'org.sauerbraten.Sauerbraten', + 'net.runelite.RuneLite', + 'com.zandronum.Zandronum', + 'io.mrarm.mcpelauncher', + 'org.unitystation.StationHub', + 'org.firestormviewer.FirestormViewer', + 'com.eduke32.EDuke32', + 'io.github.hmlendea.geforcenow-electron', + 'io.gdevs.GDLauncher', + 'io.github.sharkwouter.Minigalaxy', + 'com.katawa_shoujo.KatawaShoujo', + 're.chiaki.Chiaki' +]