Esempio n. 1
0
    def insert_to_db(self):
        """
        The insert_to_db function inserts the data into a database.
        It takes in the self object and uses it to insert data into a database.
        """

        db.db_insert_class_in_table(db.db_conn(), self, 'MainConfig')
Esempio n. 2
0
    def insert_to_db(self):
        """
        The insert_to_db function inserts a new row into the DBVersion table with the version
        number.


        Args:
            self: Access the variables in the class
        """

        sql = f"INSERT into DBversion (version) VALUES({self.version})"

        conn = db.db_conn()
        with conn:
            with closing(conn.cursor()) as cur:
                cur = conn.cursor()
                cur.execute(sql)
Esempio n. 3
0
    def insert_to_db(self):
        """
        The insert_to_db function inserts a new row into the DBVersion table with the version
        number.


        Args:
            self: Access the variables in the class
        """

        sql = (
            "INSERT into MainUpdateHistory (date, version, success, errorid) "
            f"VALUES ('{self.date}', '{self.version}', '{self.success}', '{self.errorid}')"
        )

        conn = db.db_conn()
        with conn:
            with closing(conn.cursor()) as cur:
                cur = conn.cursor()
                cur.execute(sql)
Esempio n. 4
0
    def print_me(self, single: bool = False, edit: bool = False):
        """
        Prints object to output
        """
        if not single:
            rows = db.db_select_values(db.db_conn(), 'DistroConfig', '*')

            distro_dict = {}

            for i, row in enumerate(rows, start=1):
                distroconfig = DistroConfig()
                if not edit:
                    print()
                    print(
                        f"[{c.fg.orange}{i}{c.end}] {c.fg.lt_blue}{row['distro']}{c.end}:"
                    )
                    print()

                for each in row.keys():
                    setattr(distroconfig, each, row[each])
                    if not edit:
                        if not each == "distro":
                            print(f"{c.fg.yellow}{each:<16}{c.end}: "
                                  f"{c.fg.lt_cyan}{row[each]}{c.end}")

                distro_dict[row['distro']] = distroconfig
            print()
            return distro_dict

        print()
        print(f"{c.fg.yellow}{self.distro}{c.end}")
        dc_dict: dict = self.__dict__
        if "distro" in dc_dict.keys():
            dc_dict.pop("distro")
        print()
        for i, key in enumerate(dc_dict, start=1):
            print(
                f"[{c.fg.orange}{i}{c.end}] {c.fg.lt_blue}{key :<16}{c.end}: "
                f"{c.fg.lt_cyan}{dc_dict[key]}{c.end}")
Esempio n. 5
0
 def pull_from_db(self):
     """
     Pulls object table from DB
     """
     db.db_return_class_object(db.db_conn(), 'MainConfig', 'id', 1, self)
Esempio n. 6
0
 def pull_distros(self):
     """
     pulls all distros from table and returns them
     """
     return db.db_select_values(db.db_conn(), 'DistroConfig', 'distro')
Esempio n. 7
0
 def pull_from_db(self, what):
     """
     Pulls object table from DB
     """
     db.db_return_class_object(db.db_conn(), 'DistroConfig', 'distro', what,
                               self)
Esempio n. 8
0
 def update_db(self):
     """
     Writes object to DB
     """
     db.db_update_class_in_table(db.db_conn(), self, 'DistroConfig',
                                 'distro', self.distro)
Esempio n. 9
0
 def update_db(self):
     """
     Writes object to DB
     """
     db.db_update_class_in_table(db.db_conn(), self, 'MainConfig', 'id', 1)
Esempio n. 10
0
 def pull_from_db(self):
     """
     Pulls object table from DB
     """
     db.db_return_class_object(db.db_conn(), 'ServerInfo', 'id', 1, self)
Esempio n. 11
0
 def insert_to_db(self):
     """
     Inserts object into table
     """
     db.db_insert_class_in_table(db.db_conn(), self, 'ServerInfo')
Esempio n. 12
0
 def update_db(self):
     """
     Writes object to DB
     """
     db.db_update_class_in_table(db.db_conn(), self, 'ServerInfo', 'id', 1)
Esempio n. 13
0
 def pull_from_db(self):
     """
     Pulls object table from DB
     """
     db.db_return_class_object(db.db_conn(), 'DBversion', 'id',
                               '(SELECT MAX(ID)  FROM TABLE)', self)
Esempio n. 14
0
 def insert_to_db(self):
     """
     Insert object into table
     """
     db.db_insert_class_in_table(db.db_conn(), self, 'SelfUpdate')
Esempio n. 15
0
 def pull_from_db(self):
     """
     Pulls object table from DB
     """
     db.db_return_class_object(db.db_conn(), 'MainUpdateHistory', 'id',
                               '(SELECT MAX(ID)  FROM TABLE)', self)
Esempio n. 16
0
def create_db(version_num):
    """
    The CreateDB function creates the database tables for the program.
    """

    try:
        conn = db_conn()
        with conn:
            with closing(conn.cursor()) as cur:

                cur.execute("DROP TABLE IF EXISTS MainConfig")
                cur.execute("DROP TABLE IF EXISTS MainUpdateHistory")
                cur.execute("DROP TABLE IF EXISTS SelfUpdate")
                cur.execute("DROP TABLE IF EXISTS SelfUpdateHistory")
                cur.execute("DROP TABLE IF EXISTS Dbversion")
                cur.execute("DROP TABLE IF EXISTS Errors")
                cur.execute("DROP TABLE IF EXISTS ServerInfo")
                cur.execute("DROP TABLE IF EXISTS DistroConfig")

                main_config_sql = """
                CREATE TABLE "MainConfig" (
                "id"	        INTEGER NOT NULL UNIQUE,
                "configran"	    INTEGER NOT NULL,
                "distro"	    TEXT NOT NULL,
                "startserver"	INTEGER NOT NULL,
                "stopserver"	INTEGER NOT NULL,
                "version"	    TEXT NOT NULL,
                "releasetype"	TEXT NOT NULL,
                "dateupdated"	TEXT,
                "embygithubapi" TEXT NOT NULL,
                PRIMARY KEY("id")
                );
                """

                main_update_history_sql = """
                CREATE TABLE "MainUpdateHistory" (
                "id"	    INTEGER NOT NULL UNIQUE,
                "date"	    TEXT,
                "version"	TEXT,
                "success"	INTEGER NOT NULL,
                "errorid"	TEXT,
                PRIMARY KEY("id" AUTOINCREMENT)
                );
                """

                self_update_sql = """
                CREATE TABLE "SelfUpdate" (
                "id"	        INTEGER NOT NULL UNIQUE,
                "dateupdated"	TEXT,
                "runupdate"	    INTEGER NOT NULL,
                "version"	    TEXT,
                "onlineversion"	TEXT,
                "releasetype"	TEXT NOT NULL,
                "selfgithubapi" TEXT NOT NULL,
                "downloadurl"   TEXT NOT NULL,
                "zipfile"       TEXT,
                PRIMARY KEY("id")
                );    
                """

                self_update_history_sql = """
                CREATE TABLE "SelfUpdateHistory" (
                "id"	    INTEGER NOT NULL UNIQUE,
                "date"	    TEXT,
                "version"	TEXT,
                "success"	INTEGER NOT NULL,
                "errorid"	INTEGER,
                PRIMARY KEY("id" AUTOINCREMENT)
                );
                """

                db_version_sql = """
                CREATE TABLE "DBversion" (
                "id"	        INTEGER NOT NULL UNIQUE,
                "version"	    TEXT NOT NULL UNIQUE,
                "dateupdated"	NOT NULL DEFAULT (datetime(CURRENT_TIMESTAMP, 'localtime')),
                "notes"    TEXT,
                PRIMARY KEY("id" AUTOINCREMENT)
                );
                """

                errors_sql = """
                CREATE TABLE "Errors" (
                "id"	      INTEGER NOT NULL UNIQUE,
                "date"	      TEXT,
                "message"	  TEXT,
                "mainorself"  TEXT,
                PRIMARY KEY("id" AUTOINCREMENT)
                );
                """

                server_info_sql = """
                CREATE TABLE "ServerInfo" (
                "id"	        INTEGER NOT NULL UNIQUE,
                "enablecheck"	INTEGER NOT NULL DEFAULT 1,
                "scheme"	    TEXT NOT NULL DEFAULT 'http://',
                "address"	    TEXT NOT NULL DEFAULT 'localhost',
                "port"	        TEXT NOT NULL DEFAULT 8096,
                "portused"	    INTEGER NOT NULL DEFAULT 1,
                "apipath"	    TEXT NOT NULL DEFAULT '/System/Info/Public',
                "fullurl"	    TEXT DEFAULT '',
                "version"	    TEXT DEFAULT '',
                "servername"	TEXT DEFAULT '',
                PRIMARY KEY("id")
                );
                """

                distro_config_sql = """
                CREATE TABLE "DistroConfig" (
                "distro"	     TEXT NOT NULL UNIQUE,
                "downloadurl"	 TEXT NOT NULL,
                "installcommand" TEXT NOT NULL,
                "installfile"    TEXT NOT NULL,
                PRIMARY KEY("distro")
                );
                """

                cur.execute(main_config_sql)
                cur.execute(main_update_history_sql)
                cur.execute(self_update_sql)
                cur.execute(self_update_history_sql)
                cur.execute(db_version_sql)
                cur.execute(errors_sql)
                cur.execute(server_info_sql)
                cur.execute(distro_config_sql)

                populate_db(version_num)
                create_distros()
                db_obj.DBversion(version=DBVERSION,
                                 notes="Initial DB creation").insert_to_db()

                print()
                print(f"Database version {DBVERSION} has been created!")

    except Error:
        exceptrace.execpt_trace("***create_db: An error was encountered creating the DB",
                                sys.exc_info())
        print()
        print("We were not able to create the database, exiting...")
        sys.exit()