]> git.lizzy.rs Git - cheatdb.git/blobdiff - setup.py
Fix unexpected crash on bad Github URL
[cheatdb.git] / setup.py
index 3f4925d94ca4f641e8b15407f5f91c72bcf565d7..4fd5ff162571416e4254adc13e6a0b9b5ba7370f 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,56 +1,70 @@
+# Content DB
+# Copyright (C) 2018  rubenwardy
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+
 import os, sys, datetime
 
 if not "FLASK_CONFIG" in os.environ:
        os.environ["FLASK_CONFIG"] = "../config.cfg"
 
 delete_db = len(sys.argv) >= 2 and sys.argv[1].strip() == "-d"
+create_db = not (len(sys.argv) >= 2 and sys.argv[1].strip() == "-o")
+test_data = len(sys.argv) >= 2 and sys.argv[1].strip() == "-t" or not create_db
 
-if delete_db and os.path.isfile("db.sqlite"):
-       os.remove("db.sqlite")
-
-if not os.path.isfile("db.sqlite"):
-       from app.models import *
-
-       print("Creating database tables...")
-       db.create_all()
-       print("Filling database...")
-
-       ruben = User("rubenwardy")
-       ruben.github_username = "rubenwardy"
-       ruben.rank = UserRank.ADMIN
-       db.session.add(ruben)
+from app.models import *
+from app.utils import make_flask_user_password
 
+def defineDummyData(licenses, tags, ruben):
        ez = User("Shara")
        ez.github_username = "Ezhh"
+       ez.forums_username = "Shara"
        ez.rank = UserRank.EDITOR
        db.session.add(ez)
 
+       not1 = Notification(ruben, ez, "Awards approved", "/packages/rubenwardy/awards/")
+       db.session.add(not1)
+
        jeija = User("Jeija")
        jeija.github_username = "Jeija"
+       jeija.forums_username = "Jeija"
        db.session.add(jeija)
 
-       sam = User("fillthisinlater")
-       sam.github_username = "fillthisinlater"
-       sam.rank = UserRank.EDITOR
-       db.session.add(sam)
-
-       tags = {}
-       for tag in ["Inventory", "Mapgen", "Building", \
-                       "Mobs and NPCs", "Tools", "Player effects", \
-                       "Environment", "Transport", "Maintenance", "Plants and farming", \
-                       "PvP", "PvE", "Survival", "Creative", "Puzzle", "Multiplayer", "Singleplayer"]:
-               row = Tag(tag)
-               tags[row.name] = row
-               db.session.add(row)
-
 
+       mod = Package()
+       mod.approved = True
+       mod.name = "alpha"
+       mod.title = "Alpha Test"
+       mod.license = licenses["MIT"]
+       mod.type = PackageType.MOD
+       mod.author = ruben
+       mod.tags.append(tags["mapgen"])
+       mod.tags.append(tags["environment"])
+       mod.repo = "https://github.com/ezhh/other_worlds"
+       mod.issueTracker = "https://github.com/ezhh/other_worlds/issues"
+       mod.forums = 16015
+       mod.short_desc = "The content library should not be used yet as it is still in alpha"
+       mod.desc = "This is the long desc"
+       db.session.add(mod)
 
-       licenses = {}
-       for license in ["LGPLv2.1", "LGPLv3", "GPLv2.1", "GPLv3", "AGPLv2.1", "AGPLv3",
-                                       "MIT", "Apache", "BSD", "ZLib", "CC0", "CC-BY-SA", "CC-BY", "CC-BY-NC-SA"]:
-               row = License(license)
-               licenses[row.name] = row
-               db.session.add(row)
+       rel = PackageRelease()
+       rel.package = mod
+       rel.title = "v1.0.0"
+       rel.url = "https://github.com/ezhh/handholds/archive/master.zip"
+       rel.approved = True
+       db.session.add(rel)
 
        mod1 = Package()
        mod1.approved = True
@@ -63,7 +77,7 @@ if not os.path.isfile("db.sqlite"):
        mod1.repo = "https://github.com/rubenwardy/awards"
        mod1.issueTracker = "https://github.com/rubenwardy/awards/issues"
        mod1.forums = 4870
-       mod1.shortDesc = "Adds achievements and an API to register new ones."
+       mod1.short_desc = "Adds achievements and an API to register new ones."
        mod1.desc = """
 Majority of awards are back ported from Calinou's old fork in Carbone, under same license.
 
@@ -98,7 +112,7 @@ awards.register_achievement("award_mesefind",{
        mod2.repo = "https://github.com/minetest-mods/mesecons/"
        mod2.issueTracker = "https://github.com/minetest-mods/mesecons/issues"
        mod2.forums = 628
-       mod2.shortDesc = "Mesecons adds everything digital, from all kinds of sensors, switches, solar panels, detectors, pistons, lamps, sound blocks to advanced digital circuitry like logic gates and programmable blocks."
+       mod2.short_desc = "Mesecons adds everything digital, from all kinds of sensors, switches, solar panels, detectors, pistons, lamps, sound blocks to advanced digital circuitry like logic gates and programmable blocks."
        mod2.desc = """
     ########################################################################
     ##  __    __   _____   _____   _____   _____   _____   _   _   _____  ##
@@ -188,7 +202,7 @@ No warranty is provided, express or implied, for any part of the project.
        mod = Package()
        mod.approved = True
        mod.name = "handholds"
-       mod.title = "Mountain Climbing"
+       mod.title = "Handholds"
        mod.license = licenses["MIT"]
        mod.type = PackageType.MOD
        mod.author = ez
@@ -196,7 +210,7 @@ No warranty is provided, express or implied, for any part of the project.
        mod.repo = "https://github.com/ezhh/handholds"
        mod.issueTracker = "https://github.com/ezhh/handholds/issues"
        mod.forums = 17069
-       mod.shortDesc = "Adds hand holds and climbing thingies"
+       mod.short_desc = "Adds hand holds and climbing thingies"
        mod.desc = "This is the long desc"
        db.session.add(mod)
 
@@ -219,7 +233,7 @@ No warranty is provided, express or implied, for any part of the project.
        mod.repo = "https://github.com/ezhh/other_worlds"
        mod.issueTracker = "https://github.com/ezhh/other_worlds/issues"
        mod.forums = 16015
-       mod.shortDesc = "Adds space with asteroids and comets"
+       mod.short_desc = "Adds space with asteroids and comets"
        mod.desc = "This is the long desc"
        db.session.add(mod)
 
@@ -234,8 +248,9 @@ No warranty is provided, express or implied, for any part of the project.
        mod.repo = "https://github.com/rubenwardy/food/"
        mod.issueTracker = "https://github.com/rubenwardy/food/issues/"
        mod.forums = 2960
-       mod.shortDesc = "Adds lots of food and an API to manage ingredients"
+       mod.short_desc = "Adds lots of food and an API to manage ingredients"
        mod.desc = "This is the long desc"
+       food = mod
        db.session.add(mod)
 
        mod = Package()
@@ -249,8 +264,9 @@ No warranty is provided, express or implied, for any part of the project.
        mod.repo = "https://github.com/rubenwardy/food_sweet/"
        mod.issueTracker = "https://github.com/rubenwardy/food_sweet/issues/"
        mod.forums = 9039
-       mod.shortDesc = "Adds sweet food"
+       mod.short_desc = "Adds sweet food"
        mod.desc = "This is the long desc"
+       food_sweet = mod
        db.session.add(mod)
 
        game1 = Package()
@@ -266,7 +282,7 @@ No warranty is provided, express or implied, for any part of the project.
        game1.repo = "https://github.com/rubenwardy/capturetheflag"
        game1.issueTracker = "https://github.com/rubenwardy/capturetheflag/issues"
        game1.forums = 12835
-       game1.shortDesc = "Two teams battle to snatch and return the enemy's flag, before the enemy takes their own!"
+       game1.short_desc = "Two teams battle to snatch and return the enemy's flag, before the enemy takes their own!"
        game1.desc = """
 As seen on the Capture the Flag server (minetest.rubenwardy.com:30000)
 
@@ -275,7 +291,91 @@ Uses the CTF PvP Engine.
 
        db.session.add(game1)
 
+       rel = PackageRelease()
+       rel.package = game1
+       rel.title = "v1.0.0"
+       rel.url = "https://github.com/rubenwardy/capturetheflag/archive/master.zip"
+       rel.approved = True
+       db.session.add(rel)
+
+
+       mod = Package()
+       mod.approved = True
+       mod.name = "pixelbox"
+       mod.title = "PixelBOX Reloaded"
+       mod.license = licenses["CC0"]
+       mod.type = PackageType.TXP
+       mod.author = ruben
+       mod.forums = 14132
+       mod.short_desc = "This is an update of the original PixelBOX texture pack by the brillant artist Gambit"
+       mod.desc = "This is the long desc"
+       db.session.add(mod)
+
+       rel = PackageRelease()
+       rel.package = mod
+       rel.title = "v1.0.0"
+       rel.url = "http://mamadou3.free.fr/Minetest/PixelBOX.zip"
+       rel.approved = True
+       db.session.add(rel)
 
        db.session.commit()
-else:
-       print("Database already exists")
+
+       metas = {}
+       for package in Package.query.filter_by(type=PackageType.MOD).all():
+               meta = None
+               try:
+                       meta = metas[package.name]
+               except KeyError:
+                       meta = MetaPackage(package.name)
+                       db.session.add(meta)
+                       metas[package.name] = meta
+               package.provides.append(meta)
+
+       dep = Dependency(food_sweet, meta=metas["food"])
+       db.session.add(dep)
+
+
+if delete_db and os.path.isfile("db.sqlite"):
+       os.remove("db.sqlite")
+
+
+if create_db:
+       print("Creating database tables...")
+       db.create_all()
+
+print("Filling database...")
+
+ruben = User("rubenwardy")
+ruben.active = True
+ruben.password = make_flask_user_password("tuckfrump")
+ruben.github_username = "rubenwardy"
+ruben.forums_username = "rubenwardy"
+ruben.rank = UserRank.ADMIN
+db.session.add(ruben)
+
+tags = {}
+for tag in ["Inventory", "Mapgen", "Building", \
+               "Mobs and NPCs", "Tools", "Player effects", \
+               "Environment", "Transport", "Maintenance", "Plants and farming", \
+               "PvP", "PvE", "Survival", "Creative", "Puzzle", "Multiplayer", "Singleplayer"]:
+       row = Tag(tag)
+       tags[row.name] = row
+       db.session.add(row)
+
+licenses = {}
+for license in ["GPLv2.1", "GPLv3", "LGPLv2.1", "LGPLv3", "AGPLv2.1", "AGPLv3",
+                               "Apache", "BSD 3-Clause", "BSD 2-Clause", "CC0", "CC-BY-SA",
+                               "CC-BY", "MIT", "ZLib", "Other (Free)"]:
+       row = License(license)
+       licenses[row.name] = row
+       db.session.add(row)
+
+for license in ["CC-BY-NC-SA", "Other (Non-free)"]:
+       row = License(license, False)
+       licenses[row.name] = row
+       db.session.add(row)
+
+if test_data:
+       defineDummyData(licenses, tags, ruben)
+
+db.session.commit()