diff --git a/slpkg/models/models.py b/slpkg/models/models.py index 696114f2..92747d94 100644 --- a/slpkg/models/models.py +++ b/slpkg/models/models.py @@ -34,64 +34,68 @@ class Database: self.table_name = table_name self.text_file = text_file self.db = _meta_.db - self.con = sqlite3.connect(f'{self.lib_path}database/{self.db}') + self.con = sqlite3.connect(f"{self.lib_path}database/{self.db}") self.cur = self.con.cursor() def table_exists(self): + """Checking if the table exists + """ self.cur.execute("""SELECT count(name) FROM sqlite_master WHERE type='table' - AND name='{}'""".format(self.table_name)) + AND name="{}""".format(self.table_name)) return self.cur.fetchone()[0] def create_sbo_table(self): - self.cur.execute('''CREATE TABLE IF NOT EXISTS {} + self.cur.execute("""CREATE TABLE IF NOT EXISTS {} (name text, location text, files text, version text, download text, download64 text, md5sum text, md5sum64 text, requires text, short_desc text) - '''.format(self.table_name)) + """.format(self.table_name)) self.con.commit() def insert_sbo_table(self): + """Grabbing data line by line and inserting them into the database + """ self.sbo = [ - 'SLACKBUILD NAME:', - 'SLACKBUILD LOCATION:', - 'SLACKBUILD FILES:', - 'SLACKBUILD VERSION:', - 'SLACKBUILD DOWNLOAD:', - 'SLACKBUILD DOWNLOAD_x86_64:', - 'SLACKBUILD MD5SUM:', - 'SLACKBUILD MD5SUM_x86_64:', - 'SLACKBUILD REQUIRES:', - 'SLACKBUILD SHORT DESCRIPTION:' + "SLACKBUILD NAME:", + "SLACKBUILD LOCATION:", + "SLACKBUILD FILES:", + "SLACKBUILD VERSION:", + "SLACKBUILD DOWNLOAD:", + "SLACKBUILD DOWNLOAD_x86_64:", + "SLACKBUILD MD5SUM:", + "SLACKBUILD MD5SUM_x86_64:", + "SLACKBUILD REQUIRES:", + "SLACKBUILD SHORT DESCRIPTION:" ] sbo_file = self.open_file(f"{self.lib_path}sbo_repo/SLACKBUILDS.TXT") bar = Bar("Database sbo creating", max=len(sbo_file), - suffix='%(percent)d%% - %(eta)ds') + suffix="%(percent)d%% - %(eta)ds") for i, line in enumerate(sbo_file, 1): if line.startswith(self.sbo[0]): - name = line.replace(self.sbo[0], '').strip() + name = line.replace(self.sbo[0], "").strip() if line.startswith(self.sbo[1]): - location = line.replace(self.sbo[1], '').strip() + location = line.replace(self.sbo[1], "").strip() if line.startswith(self.sbo[2]): - files = line.replace(self.sbo[2], '').strip() + files = line.replace(self.sbo[2], "").strip() if line.startswith(self.sbo[3]): - version = line.replace(self.sbo[3], '').strip() + version = line.replace(self.sbo[3], "").strip() if line.startswith(self.sbo[4]): - download = line.replace(self.sbo[4], '').strip() + download = line.replace(self.sbo[4], "").strip() if line.startswith(self.sbo[5]): - download64 = line.replace(self.sbo[5], '').strip() + download64 = line.replace(self.sbo[5], "").strip() if line.startswith(self.sbo[6]): - md5sum = line.replace(self.sbo[6], '').strip() + md5sum = line.replace(self.sbo[6], "").strip() if line.startswith(self.sbo[7]): - md5sum64 = line.replace(self.sbo[7], '').strip() + md5sum64 = line.replace(self.sbo[7], "").strip() if line.startswith(self.sbo[8]): - requires = line.replace(self.sbo[8], '').strip() + requires = line.replace(self.sbo[8], "").strip() if line.startswith(self.sbo[9]): - short_desc = line.replace(self.sbo[9], '').strip() + short_desc = line.replace(self.sbo[9], "").strip() if i % 11 == 0: values = [(name, location, files, version, download, @@ -106,5 +110,5 @@ class Database: self.con.close() def open_file(self, file): - with open(file, 'r', encoding='utf-8') as f: + with open(file, "r", encoding="utf-8") as f: return f.readlines()