Improved code quality

This commit is contained in:
Dimitris Zlatanidis 2024-04-28 18:13:53 +03:00
parent 13f53e5fec
commit 1b6806bf57

View file

@ -1,19 +1,29 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from pathlib import Path
from slpkg.configs import Configs
from slpkg.views.asciibox import AsciiBox
class SBoGenerate(Configs):
""" Generating the SLACKBUILDS.TXT file. """
"""
Generating the SLACKBUILDS.TXT file.
"""
def __init__(self):
super(Configs, self).__init__()
self.ascii = AsciiBox()
def slackbuild_file(self, repo_path: Path, repo_slackbuild_txt: str) -> None:
def slackbuild_file(self, repo_path: Path, repo_slackbuild_txt: str) -> None: # pylint: disable=[R0914]
""" Creates a SLACKBUILDS.TXT file.
Args:
repo_path (Path): Path to file.
repo_slackbuild_txt (str): Name of file to create.
"""
print(f'Generating the {repo_slackbuild_txt} file... ', end='', flush=True)
# slackbuild.info variables
@ -30,7 +40,7 @@ class SBoGenerate(Configs):
10: 'EMAIL='
}
with open(Path(repo_path, repo_slackbuild_txt), 'w') as sbo:
with open(Path(repo_path, repo_slackbuild_txt), 'w', encoding='utf-8') as sbo:
for path in repo_path.glob('**/*'):
if path.name.endswith('.info'):
sbo_path = Path('/'.join(str(path).split('/')[:-1]))
@ -59,8 +69,8 @@ class SBoGenerate(Configs):
' '.join([var.replace('\\', '').strip() for var in self.read_info_file(
path, info_var[7], info_var[8])])[len(info_var[7]):].replace('"', ''))
requires: str = (' '.join([var for var in self.read_info_file(
path, info_var[8], info_var[9])])[len(info_var[8]):].replace('"', ''))
requires: str = (' '.join(list(self.read_info_file(
path, info_var[8], info_var[9])))[len(info_var[8]):].replace('"', ''))
short_description: str = self.read_short_description(sbo_path, name)
@ -80,10 +90,18 @@ class SBoGenerate(Configs):
@staticmethod
def read_short_description(path: Path, name: str) -> str:
""" Returns the short description. """
""" Returns the short description.
Args:
path (Path): Path to file.
name (str): Slackbuild name.
Returns:
str: Description
"""
slack_desc: Path = Path(path, 'slack-desc')
if slack_desc.is_file():
with open(slack_desc, 'r') as f:
with open(slack_desc, 'r', encoding='utf-8') as f:
slack = f.readlines()
for line in slack:
@ -94,9 +112,18 @@ class SBoGenerate(Configs):
@staticmethod
def read_info_file(info_file: Path, start: str, stop: str) -> list:
""" Reads the .info file and return the line between to variables. """
"""Reads the .info file and return the line between to variables.
Args:
info_file (Path): Slackbuild file name.
start (str): Variable name to start.
stop (str): Variable name to stop.
Returns:
list: Results in list.
"""
begin = end = 0
with open(info_file, 'r') as f:
with open(info_file, 'r', encoding='utf-8') as f:
info = f.read().splitlines()
for index, line in enumerate(info):