2022-06-17 16:39:33 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-12-30 16:40:11 +01:00
|
|
|
|
|
|
|
from pathlib import Path
|
2023-02-28 20:43:04 +01:00
|
|
|
|
2022-06-18 20:35:23 +02:00
|
|
|
from slpkg.configs import Configs
|
2023-03-14 10:59:44 +01:00
|
|
|
from slpkg.queries import SBoQueries
|
2023-02-28 20:43:04 +01:00
|
|
|
from slpkg.utilities import Utilities
|
2023-03-20 17:21:36 +01:00
|
|
|
from slpkg.repositories import Repositories
|
2022-06-17 18:36:07 +02:00
|
|
|
from slpkg.models.models import session as Session
|
2023-03-18 20:48:10 +01:00
|
|
|
from slpkg.models.models import SBoTable, PonceTable, BinariesTable
|
2022-06-17 16:39:33 +02:00
|
|
|
|
|
|
|
|
2023-01-16 23:47:01 +01:00
|
|
|
class CreateData(Configs):
|
2022-12-07 16:36:00 +01: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):
|
2023-01-16 23:47:01 +01:00
|
|
|
super(Configs, self).__init__()
|
2023-03-01 17:03:35 +01:00
|
|
|
|
2022-12-07 16:36:00 +01:00
|
|
|
self.session = Session
|
2023-02-28 20:43:04 +01:00
|
|
|
self.utils = Utilities()
|
|
|
|
self.query = SBoQueries('')
|
2023-03-20 17:21:36 +01:00
|
|
|
self.repositories = Repositories()
|
|
|
|
self.repos: dict = self.repositories.configs()
|
2022-06-17 16:39:33 +02:00
|
|
|
|
2023-03-05 18:52:13 +01:00
|
|
|
def install_sbo_table(self) -> None:
|
2023-02-28 23:11:20 +01:00
|
|
|
""" Install the data for SBo repository. """
|
2022-06-17 16:39:33 +02:00
|
|
|
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
|
|
|
]
|
2023-03-05 16:49:15 +01:00
|
|
|
sbo_table = SBoTable
|
2023-03-20 17:21:36 +01:00
|
|
|
path = Path(self.sbo_repo_path, self.repos['SBO_REPO_TXT'])
|
2023-03-05 16:49:15 +01:00
|
|
|
|
2023-03-20 17:21:36 +01:00
|
|
|
if self.repos['PONCE_REPO']:
|
2023-03-05 16:49:15 +01:00
|
|
|
sbo_table = PonceTable
|
2023-03-20 17:21:36 +01:00
|
|
|
path = Path(self.ponce_repo_path, self.repos['PONCE_REPO_TXT'])
|
2023-03-05 16:49:15 +01:00
|
|
|
|
2023-03-14 10:59:44 +01:00
|
|
|
sbo_file: list = self.utils.read_file(path)
|
2022-06-17 16:39:33 +02:00
|
|
|
|
2023-02-28 22:54:56 +01:00
|
|
|
cache: list = [] # init cache
|
2022-06-17 16:39:33 +02:00
|
|
|
|
2023-03-14 09:58:09 +01:00
|
|
|
print('Creating the database... ', end='', flush=True)
|
2022-06-17 16:39:33 +02:00
|
|
|
|
|
|
|
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:
|
2023-03-05 16:49:15 +01:00
|
|
|
data: str = sbo_table(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])
|
2022-06-17 16:39:33 +02:00
|
|
|
self.session.add(data)
|
|
|
|
|
2023-02-28 22:54:56 +01:00
|
|
|
cache: list = [] # reset cache after 11 lines
|
2022-06-17 16:39:33 +02:00
|
|
|
|
|
|
|
print('Done')
|
|
|
|
|
|
|
|
self.session.commit()
|
2023-03-18 20:48:10 +01:00
|
|
|
|
2023-03-20 17:21:36 +01:00
|
|
|
def install_gnome_data(self) -> None:
|
2023-03-18 20:48:10 +01:00
|
|
|
""" Install the data for SBo repository. """
|
2023-03-19 22:42:26 +01:00
|
|
|
repo: str = 'gnome'
|
|
|
|
pkg_tag = [
|
2023-03-18 20:48:10 +01:00
|
|
|
'PACKAGE NAME:',
|
|
|
|
'PACKAGE MIRROR:',
|
|
|
|
'PACKAGE LOCATION:',
|
|
|
|
'PACKAGE SIZE (compressed):',
|
|
|
|
'PACKAGE SIZE (uncompressed):',
|
2023-03-19 22:42:26 +01:00
|
|
|
'PACKAGE DESCRIPTION:',
|
2023-03-18 20:48:10 +01:00
|
|
|
]
|
2023-03-20 17:21:36 +01:00
|
|
|
path = Path(self.lib_path, 'repositories', repo, self.repos['GNOME_REPO_PKG_TXT'])
|
2023-03-18 20:48:10 +01:00
|
|
|
|
|
|
|
pkg_txt: list = self.utils.read_file(path)
|
|
|
|
|
|
|
|
cache: list = [] # init cache
|
|
|
|
|
|
|
|
print('Creating the database... ', end='', flush=True)
|
|
|
|
|
|
|
|
for i, line in enumerate(pkg_txt, 1):
|
|
|
|
|
2023-03-19 22:42:26 +01:00
|
|
|
if line.startswith(pkg_tag[0]):
|
|
|
|
package_name = line.replace(pkg_tag[0], '').strip()
|
|
|
|
name: str = self.utils.split_binary_pkg(package_name)[0]
|
|
|
|
version: str = self.utils.split_binary_pkg(package_name)[1]
|
|
|
|
cache.append(name)
|
|
|
|
cache.append(version)
|
|
|
|
cache.append(package_name)
|
|
|
|
|
|
|
|
if line.startswith(pkg_tag[1]):
|
|
|
|
package_mirror = line.replace(pkg_tag[1], '').strip()
|
2023-03-20 11:59:32 +01:00
|
|
|
if not package_mirror.endswith('/'):
|
|
|
|
package_mirror: str = f'{package_mirror}/'
|
2023-03-19 22:42:26 +01:00
|
|
|
cache.append(package_mirror)
|
|
|
|
|
|
|
|
if line.startswith(pkg_tag[2]):
|
|
|
|
package_location = line.replace(pkg_tag[2], '').strip()
|
2023-03-20 11:59:32 +01:00
|
|
|
cache.append(package_location[1:]) # Do not install (.) dot
|
2023-03-19 22:42:26 +01:00
|
|
|
|
|
|
|
if line.startswith(pkg_tag[3]):
|
|
|
|
package_size_comp = line.replace(pkg_tag[3], '').strip()
|
|
|
|
cache.append(package_size_comp)
|
|
|
|
|
|
|
|
if line.startswith(pkg_tag[4]):
|
|
|
|
package_size_uncomp = line.replace(pkg_tag[4], '').strip()
|
|
|
|
cache.append(package_size_uncomp)
|
|
|
|
|
|
|
|
if line.startswith(pkg_tag[5]):
|
|
|
|
package_description = line.replace(pkg_tag[5], '').strip()
|
|
|
|
cache.append(package_description)
|
|
|
|
|
|
|
|
if len(cache) == 8:
|
|
|
|
data: str = BinariesTable(
|
|
|
|
repo=repo,
|
|
|
|
name=cache[0],
|
|
|
|
version=cache[1],
|
|
|
|
package=cache[2],
|
|
|
|
mirror=cache[3],
|
|
|
|
location=cache[4],
|
|
|
|
size_comp=cache[5],
|
|
|
|
size_uncomp=cache[6],
|
|
|
|
description=cache[7],
|
|
|
|
)
|
2023-03-18 20:48:10 +01:00
|
|
|
|
2023-03-19 22:42:26 +01:00
|
|
|
self.session.add(data)
|
2023-03-18 21:10:27 +01:00
|
|
|
|
2023-03-19 22:42:26 +01:00
|
|
|
cache: list = []
|
2023-03-18 21:10:27 +01:00
|
|
|
|
2023-03-19 22:42:26 +01:00
|
|
|
print('Done')
|
2023-03-18 21:10:27 +01:00
|
|
|
|
2023-03-19 22:42:26 +01:00
|
|
|
self.session.commit()
|