mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-22 19:27:56 +01:00
Updated style
This commit is contained in:
parent
df3da1ea84
commit
6cb10873fb
1 changed files with 30 additions and 26 deletions
|
@ -34,64 +34,68 @@ class Database:
|
||||||
self.table_name = table_name
|
self.table_name = table_name
|
||||||
self.text_file = text_file
|
self.text_file = text_file
|
||||||
self.db = _meta_.db
|
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()
|
self.cur = self.con.cursor()
|
||||||
|
|
||||||
def table_exists(self):
|
def table_exists(self):
|
||||||
|
"""Checking if the table exists
|
||||||
|
"""
|
||||||
self.cur.execute("""SELECT count(name)
|
self.cur.execute("""SELECT count(name)
|
||||||
FROM sqlite_master
|
FROM sqlite_master
|
||||||
WHERE type='table'
|
WHERE type='table'
|
||||||
AND name='{}'""".format(self.table_name))
|
AND name="{}""".format(self.table_name))
|
||||||
return self.cur.fetchone()[0]
|
return self.cur.fetchone()[0]
|
||||||
|
|
||||||
def create_sbo_table(self):
|
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,
|
(name text, location text, files text, version text,
|
||||||
download text, download64 text, md5sum text,
|
download text, download64 text, md5sum text,
|
||||||
md5sum64 text, requires text, short_desc text)
|
md5sum64 text, requires text, short_desc text)
|
||||||
'''.format(self.table_name))
|
""".format(self.table_name))
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
|
|
||||||
def insert_sbo_table(self):
|
def insert_sbo_table(self):
|
||||||
|
"""Grabbing data line by line and inserting them into the database
|
||||||
|
"""
|
||||||
self.sbo = [
|
self.sbo = [
|
||||||
'SLACKBUILD NAME:',
|
"SLACKBUILD NAME:",
|
||||||
'SLACKBUILD LOCATION:',
|
"SLACKBUILD LOCATION:",
|
||||||
'SLACKBUILD FILES:',
|
"SLACKBUILD FILES:",
|
||||||
'SLACKBUILD VERSION:',
|
"SLACKBUILD VERSION:",
|
||||||
'SLACKBUILD DOWNLOAD:',
|
"SLACKBUILD DOWNLOAD:",
|
||||||
'SLACKBUILD DOWNLOAD_x86_64:',
|
"SLACKBUILD DOWNLOAD_x86_64:",
|
||||||
'SLACKBUILD MD5SUM:',
|
"SLACKBUILD MD5SUM:",
|
||||||
'SLACKBUILD MD5SUM_x86_64:',
|
"SLACKBUILD MD5SUM_x86_64:",
|
||||||
'SLACKBUILD REQUIRES:',
|
"SLACKBUILD REQUIRES:",
|
||||||
'SLACKBUILD SHORT DESCRIPTION:'
|
"SLACKBUILD SHORT DESCRIPTION:"
|
||||||
]
|
]
|
||||||
|
|
||||||
sbo_file = self.open_file(f"{self.lib_path}sbo_repo/SLACKBUILDS.TXT")
|
sbo_file = self.open_file(f"{self.lib_path}sbo_repo/SLACKBUILDS.TXT")
|
||||||
|
|
||||||
bar = Bar("Database sbo creating", max=len(sbo_file),
|
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):
|
for i, line in enumerate(sbo_file, 1):
|
||||||
|
|
||||||
if line.startswith(self.sbo[0]):
|
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]):
|
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]):
|
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]):
|
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]):
|
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]):
|
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]):
|
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]):
|
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]):
|
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]):
|
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:
|
if i % 11 == 0:
|
||||||
values = [(name, location, files, version, download,
|
values = [(name, location, files, version, download,
|
||||||
|
@ -106,5 +110,5 @@ class Database:
|
||||||
self.con.close()
|
self.con.close()
|
||||||
|
|
||||||
def open_file(self, file):
|
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()
|
return f.readlines()
|
||||||
|
|
Loading…
Add table
Reference in a new issue