mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-17 07:48:18 +01:00
Updated read data
This commit is contained in:
parent
ebccc377cb
commit
8f04a671bb
1 changed files with 22 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from slpkg.configs import Configs
|
||||
|
@ -25,16 +26,10 @@ class LoadData(Configs):
|
|||
for repo, item in self.repos.repositories.items():
|
||||
if item['enable']: # Check if the repository is enabled
|
||||
json_data_file: Path = Path(f'{self.repos.repositories_path}/{repo}', self.repos.json_file)
|
||||
data[repo] = self.utils.read_json_file(json_data_file)
|
||||
data[repo] = self.read_data_file(json_data_file)
|
||||
else:
|
||||
json_data_file: Path = Path(f'{self.repos.repositories_path}/{repository}', self.repos.json_file)
|
||||
|
||||
if not json_data_file.is_file():
|
||||
print("\nNeed to update the database first, please run:\n")
|
||||
print(f"{'':>2} $ slpkg update\n")
|
||||
raise SystemExit(1)
|
||||
|
||||
data: dict = self.utils.read_json_file(json_data_file)
|
||||
data: dict = self.read_data_file(json_data_file)
|
||||
|
||||
blacklist: tuple = self.black.packages()
|
||||
if blacklist:
|
||||
|
@ -46,6 +41,25 @@ class LoadData(Configs):
|
|||
print(f'{self.bgreen}{self.ascii.done}{self.endc}')
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def read_data_file(file: Path) -> dict:
|
||||
"""
|
||||
Read JSON data from the file.
|
||||
Args:
|
||||
file: Path file for reading.
|
||||
Returns:
|
||||
Dictionary with data.
|
||||
"""
|
||||
json_data: dict = {}
|
||||
try:
|
||||
json_data: dict = json.loads(file.read_text(encoding='utf-8'))
|
||||
except FileNotFoundError:
|
||||
print(f'\n\nFile {file} not found!')
|
||||
print('\nNeed to update the database first, please run:\n')
|
||||
print(f"{'':>2} $ slpkg update\n")
|
||||
raise SystemExit(1)
|
||||
return json_data
|
||||
|
||||
def _remove_blacklist_from_all_repos(self, data: dict) -> dict:
|
||||
# Remove blacklist packages from keys.
|
||||
for name, repo in data.items():
|
||||
|
|
Loading…
Reference in a new issue