Пример #1
0
    def add_to_database(self,
                        filename,
                        dl_url=None,
                        curse_id=None,
                        curse_file_id=None):
        """
        Add this mod to the database
        :param filename: string, absolute path to the filename
        :param dl_url: string, URL the mod was downloaded from, if it was acquired via direct DL
        :return: None
        """
        self.logger.debug("Adding self to database...")
        # init the mod
        m = Mod(filename,
                self.name,
                self.modid,
                self.version,
                self.mc_version,
                self.update_url,
                self.description,
                self.credits,
                dl_url,
                self.dependencies,
                curse_id=curse_id,
                curse_file_id=curse_file_id,
                authors=self.authors)

        # add the Mod to the database
        db_session.add(m)
        self.logger.debug("Added to database successfully")
Пример #2
0
    def _add_mod_author(self, m, author):
        """
        Adds a mod author
        :param m: Mod
        :param author: String
        :return: None
        """
        self.logger.debug("Adding a new Author: {}".format(author))
        x = ModAuthor(author)
        db_session.add(x)
        db_session.commit()

        m.authors.append(x)
        self.logger.debug("Successfully added Author")
Пример #3
0
    def _add_mod_dependency(self, m, modid):
        """
        Adds a mod dependency
        :param m: Mod
        :param modid: String
        :return: None
        """
        self.logger.debug("Looking up DepMod for modid: {}".format(modid))
        x = DepMod.query.get(modid)
        if x is None:
            self.logger.debug("DepMod doesn't yet exist, creating one")
            x = DepMod(modid)
            db_session.add(x)
            db_session.commit()
            self.logger.debug("Added to database successfully")

        m.dependencies.append(x)
        self.logger.debug("Successfully added dependency")
Пример #4
0
def add_collection(args):
    """
    Add a collection to the database
    :param args:
    :return: None
    """
    lookup = Collection.query.filter(
        Collection.name == args.get("name")).first()
    print(lookup)
    if lookup:
        #return '/collection/{}'.format(lookup.id)  # a collection by that name already exists
        return "/collection/{}".format(lookup.id)
    else:
        coll = Collection(args.get("name"), args.get("mcversion"),
                          args.get("version_id"))
        db_session.add(coll)
        db_session.commit()

        return '/collection/{}'.format(coll.id)
Пример #5
0
def add(name, mcversion, version_id):
    """
    Adds a new collection (if it doesn't exist already) to the DB, Minecraft, & the FileSystem
    :param name: string, user-friendly name of the Collection
    :param mcversion: string, general Minecraft Version for the collection. e.g. 1.7.10
    :param version_id: string, exact name of a specific version of minecraft. e.g. 1.7.10-Forge10.13.4.1558-1.7.10
    :return: int, id of the newly created Collection
    """
    logger.info("Adding collection: {}, {}, {}".format(name, mcversion,
                                                       version_id))
    if not name_exists(
            name):  # if a Collection by this name doesn't yet exist:
        # 1. Add it to the database
        logger.info("Adding to database")
        c = Collection(name, mcversion, version_id)
        db_session.add(c)
        db_session.commit()
        logger.info("Committed to database")

        # 2. Creates it's directory and filesystem
        logger.info("Creating filesystem...")
        coll_loc = _create_collection_filesystem(
            join_path(config["application_root"], "collections"), c.mc_id)
        logger.info("Filesystem created")

        # 3. Add it to Minecraft as a Profile
        logger.info("Adding Minecraft Profile")
        prof = mc_interface.Profile(c.mc_id, name, version_id, coll_loc)
        prof.commit()
        logger.info("New Profile committed")

        print(
            mc_interface.Profile(c.mc_id, name, version_id,
                                 coll_loc).dictify())

        return c.id
    else:
        logger.error(
            "A Collection with the name: {} already exists".format(name))
        raise exceptions.CollectionExistsError(
            str(Collection.query.filter(Collection.name == name).first().id))
Пример #6
0
"""
Creates the moddata.sqlite database
"""

from simple_mod_installer.database import init_db, db_session
from simple_mod_installer.database.models import *

# create the database
init_db()

# create collection
c = Collection("test", "1.7.10", "Minecraft 1.7.10")
db_session.add(c)
db_session.commit()