2022-06-17 16:39:33 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
2022-06-18 20:35:23 +02:00
|
|
|
from slpkg.configs import Configs
|
2022-06-17 18:36:07 +02:00
|
|
|
from slpkg.models.models import SBoTable
|
|
|
|
from slpkg.models.models import session as Session
|
2022-06-17 16:39:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CreateData:
|
2022-06-19 18:26:30 +02:00
|
|
|
''' Reads the SLACKBUILDS.TXT file and inserts them into the database. '''
|
2022-06-17 16:39:33 +02:00
|
|
|
|
2022-12-02 21:06:18 +01:00
|
|
|
def __init__(self):
|
2022-12-06 15:31:58 +01:00
|
|
|
self.configs: str = Configs
|
2022-12-02 21:06:18 +01:00
|
|
|
self.session: str = Session
|
2022-06-17 16:39:33 +02:00
|
|
|
|
|
|
|
def insert_sbo_table(self):
|
|
|
|
sbo_tags = [
|
2022-10-18 21:13:30 +02:00
|
|
|
'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:'
|
2022-06-17 16:39:33 +02:00
|
|
|
]
|
|
|
|
|
2022-12-06 15:31:58 +01:00
|
|
|
sbo_file = self.read_file(
|
|
|
|
f'{self.configs.sbo_repo_path}/SLACKBUILDS.TXT')
|
2022-06-17 16:39:33 +02:00
|
|
|
|
|
|
|
cache = [] # init cache
|
|
|
|
|
|
|
|
print('Creating the database... ', end='', flush=True)
|
|
|
|
|
|
|
|
for i, line in enumerate(sbo_file, 1):
|
|
|
|
|
2022-06-20 19:43:56 +02:00
|
|
|
for tag in sbo_tags:
|
|
|
|
if line.startswith(tag):
|
2022-10-18 21:13:30 +02:00
|
|
|
line = line.replace(tag, '').strip()
|
2022-06-17 16:39:33 +02:00
|
|
|
cache.append(line)
|
|
|
|
|
|
|
|
if (i % 11) == 0:
|
|
|
|
data = SBoTable(name=cache[0], location=cache[1].split('/')[1],
|
|
|
|
files=cache[2], version=cache[3],
|
|
|
|
download=cache[4], download64=cache[5],
|
|
|
|
md5sum=cache[6], md5sum64=cache[7],
|
|
|
|
requires=cache[8], short_description=cache[9])
|
|
|
|
self.session.add(data)
|
|
|
|
|
|
|
|
cache = [] # reset cache after 11 lines
|
|
|
|
|
|
|
|
print('Done')
|
|
|
|
|
|
|
|
self.session.commit()
|
|
|
|
|
2022-06-18 19:10:47 +02:00
|
|
|
def read_file(self, file: str):
|
2022-10-18 21:13:30 +02:00
|
|
|
with open(file, 'r', encoding='utf-8') as f:
|
2022-06-17 16:39:33 +02:00
|
|
|
return f.readlines()
|