Skip to content

Commit

Permalink
Merge pull request #17 from deepin-espanol/update
Browse files Browse the repository at this point in the history
Update to 1.4.0~RC
  • Loading branch information
xoascf committed Aug 5, 2024
2 parents 112e41b + cfc4b6e commit 1d6aa33
Show file tree
Hide file tree
Showing 32 changed files with 3,363 additions and 1,390 deletions.
File renamed without changes.
13 changes: 0 additions & 13 deletions deepinesStore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
#!/usr/bin/env python3
from deepinesStore.store import run_gui
from deepinesStore.svg import threading_svg
from deepinesStore.core import get_dl, get_res, write, get_deepines_uri


def download_control():
ignore_index = get_dl(get_deepines_uri('/store/config/excluidos.txt'))
if ignore_index.status_code == 200:
write(ignore_index, to=get_res('excluidos', 'config', '.txt'))

deepines_index = get_dl(get_deepines_uri('/store/config/deepines.txt'))
if deepines_index.status_code == 200:
write(deepines_index, to=get_res('deepines', 'config', '.txt'))


def main():
threading_svg()
download_control()
run_gui()
8 changes: 4 additions & 4 deletions deepinesStore/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
G("Freddy", "@Akibaillusion"), G("jhalo", "@jhalo"),
G("Isaías Gätjens M", "@igatjens"), G("Jose Fenoll", "@fenoll"), G("Hugo Florentino", "@geekmidget"),
G("Eli", "@RealAct"), G("Diego", "@s_d1112"), G("Filho Arrais", "@filhoarrais"),
G("Alvaro Samudio", "@G4SP3R"), G("Omi", "@peteromio"), G("Opik", "@Prophaniti"), G("José Siapo", "@jsiapodev"),
G("Jorge Cabrera", "@seiyukaras"), G("N1coc4colA", "@n1coc4cola"), G("Oscar Ortiz", "@oscararg"), G("Jorge", "@jotakenobi"),
G("Tomás Warynyca", "@TomasWarynyca"), G("Edwinsiño C", "@Shokatsuo"),
G("Alvaro Samudio", "@G4SP3R"), G("José Siapo", "@jsiapodev"),
G("Oscar Ortiz", "@oscararg"), G("Edwinsiño C", "@Shokatsuo"),
]

class AboutDialog(QtWidgets.QDialog):
Expand Down Expand Up @@ -49,7 +48,8 @@ def __init__(self, parent=None):
self.description_lbl.setFont(font)
self.description_lbl.setAlignment(QtCore.Qt.AlignCenter)

list_ppl = CreditsListWidget()
list_ppl = CreditsListWidget(self)
list_ppl.setSpacing(2)
self.pplP = add_people_to_list(people, list_ppl)
fntLst = QtGui.QFont()
fntLst.setPointSize(11)
Expand Down
9 changes: 7 additions & 2 deletions deepinesStore/app_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ class AppState(Enum):
DEFAULT = 1
INSTALLED = 2
UNINSTALLED = 3
UNINSTALL = 4

class ProcessType(Enum):
INSTALL = 0
UNINSTALL = 1

class AppInfo:
def __init__(self, name: str, id: str, description: str, version = "0", category = "otros", type=AppType.DEB_PACKAGE, state=AppState.DEFAULT):
def __init__(self, name: str, id: str, description: str, version = None, category = "other", type=AppType.DEB_PACKAGE, state=AppState.DEFAULT, process=ProcessType.INSTALL):
self.name = name
self.id = id
self.description = description
self.version = version
self.category = category
self.state = state
self.type = type
self.type = type
self.process = process
18 changes: 17 additions & 1 deletion deepinesStore/cardg.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def setupUi(self, Frame):
font.setPointSize(11)
font.setItalic(False)
self.lbl_name_app.setFont(font)
self.lbl_name_app.setWordWrap(True)
self.lbl_name_app.setWordWrap(False)
self.lbl_name_app.setObjectName("lbl_name_app")
self.verticalLayout.addWidget(self.lbl_name_app)
self.lbl_name_app.resizeEvent = self.adjust_font_size
self.lbl_version = ClickableLabel(Frame)
font = QtGui.QFont()
font.setPointSize(9)
Expand All @@ -51,6 +52,21 @@ def setupUi(self, Frame):
self.retranslateUi(Frame)
QMetaObject.connectSlotsByName(Frame)

def adjust_font_size(self, event):
label = self.lbl_name_app
font = label.font()
font_metrics = QtGui.QFontMetrics(font)
text = label.text()
label_width = label.width()

# Reduce the font size until the text fits within the label's width
while font_metrics.width(text) > label_width and font.pointSize() > 1:
font.setPointSize(font.pointSize() - 1)
font_metrics = QtGui.QFontMetrics(font)

label.setFont(font)
super(ClickableLabel, label).resizeEvent(event)

def __tr(self, txt, disambiguation=None, n=-1):
from deepinesStore.core import tr
return tr(self, txt, disambiguation, n)
Expand Down
10 changes: 3 additions & 7 deletions deepinesStore/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from enum import Enum
from os import environ as env, name
import argparse
import json
Expand Down Expand Up @@ -94,9 +93,6 @@ def write(b, to):
default_env = env.copy()

if args.env:
new_env = json.loads(args.env)
default_env.update(new_env)

class ProcessType(Enum):
INSTALL = 0
UNINSTALL = 1
new_env = json.loads(args.env)
default_env.update(new_env)
env.update({k: v for k, v in default_env.items() if k != 'XDG_RUNTIME_DIR'})
5 changes: 2 additions & 3 deletions deepinesStore/demoted_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ def get_flatpak_info_cmd():
return p

try:
p = check_output(['flatpak', '--user', 'remote-ls', 'flathub', '--app', '--columns=application,version'], text=True, env=DEF.env, preexec_fn=set(DEF.uid, DEF.gid))
p = check_output(['flatpak', 'remote-ls', 'flathub', '--app', '--columns=application,version'], text=True, env=DEF.env, preexec_fn=set(DEF.uid, DEF.gid))
except CalledProcessError:
print("Couldn't get flatpak app info: Error running flatpak command!")
# FIXME: Notify the user, or automatize this!!
print("You may need to run the following to enable the flathub repository:")
print("flatpak --user remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo")
print("flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo")
return p

def browse(uri: str):
Expand Down
113 changes: 55 additions & 58 deletions deepinesStore/flatpak/get_apps_flatpak.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,69 @@
import deepinesStore.demoted_actions as actions
from deepinesStore.app_info import AppInfo, AppType
from deepinesStore.core import get_dl
from lxml import etree
import locale

# Categorias de app en flathub
# Flathub appstream.xml file location
appstream_file = "/var/lib/flatpak/appstream/flathub/x86_64/active/appstream.xml"

# Flathub app categories
categories = [
"AudioVideo", "Development", "Education", "Games", "Game", "Productivity",
"Graphics", "Network", "Office", "Science", "System", "Utility"
]

# Obtenemos las apps desde el api de flathub
def fetch_list_app_flatpak():
api_url = "https://flathub.org/api/v1/apps"
try:
request = get_dl(api_url, timeout=20)
app_list = list()
for app in request.json():
name = app['name']
description = app['summary']
category = "None"
state = 1
appID = app['flatpakAppId']
app_info = [name, description, 'None', category, state, appID]
app_list.append(app_info)

except Exception as e:
print("Error fetching apps:", e)
return []
return app_list
def get_preferred_text(element, tag, preferred_lang):
nsmap = {"xml": "http://www.w3.org/XML/1998/namespace"}
# Try to find the element with the full preferred xml:lang attribute
full_lang_xpath = f'{tag}[@xml:lang="{preferred_lang}"]'
full_lang_elem = element.find(full_lang_xpath, namespaces=nsmap)
if full_lang_elem is not None:
return full_lang_elem.text

# If not found, try to find the element with the base language (e.g., 'en' from 'en_US')
base_lang = preferred_lang.split('_')[0]
base_lang_xpath = f'{tag}[@xml:lang="{base_lang}"]'
base_lang_elem = element.find(base_lang_xpath, namespaces=nsmap)
if base_lang_elem is not None:
return base_lang_elem.text

# If neither is found, try to find the element without xml:lang attribute (default language)
default_lang_elem = element.find(tag)
if default_lang_elem is not None and 'xml:lang' not in default_lang_elem.attrib:
return default_lang_elem.text

# If none of the above is found, return None
return None

def app_list_flatpak() -> list[AppInfo]:
# Get the system language
system_lang = locale.getdefaultlocale()[0]

def fetch_apps_by_category(category):
try:
api_url = f"https://flathub.org/api/v1/apps/category/{category}"
request = get_dl(api_url, timeout=20)
return request.json() if request.status_code == 200 else []
except Exception as e:
print(f"Error fetching apps in category {category}:", e)
return []
# Parse the appstream file with lxml
tree = etree.parse(appstream_file)
root = tree.getroot()
app_list = []

def two_columns_split(output: str):
lines = output.split('\n')
result = {}
for line in lines:
columns = line.split(maxsplit=1)
if len(columns) == 2:
result[columns[0]] = columns[1].strip()
for component in root.findall('component'):
if component.get('type') in ['runtime', 'addon']:
continue

return result
app_id = component.find('id').text
app_name = get_preferred_text(component, 'name', system_lang)
app_summary = get_preferred_text(component, 'summary', system_lang)
app_version = None
releases = component.find('releases')
if releases is not None and releases.findall('release'):
app_version = releases.findall('release')[-1].get('version')

app_id_ver_dict = two_columns_split(actions.get_flatpak_info_cmd())
app_category = "other"
app_categories = component.find('categories')
if app_categories is not None:
for category in app_categories.findall('category'):
if category.text in categories:
app_category = category.text
break

def add_apps_dict_by_categories():
app_data = {}
for category in categories:
app_data[category] = fetch_apps_by_category(category)
return app_data
app_info = AppInfo(name=app_name, id=app_id, description=app_summary, version=app_version, category=app_category, type=AppType.FLATPAK_APP)
app_list.append(app_info)

def apps_flatpak_in_categories() -> list[AppInfo]:
app_data = add_apps_dict_by_categories()
fp_app_info = list()
already_added = list()
for category in categories:
for app in app_data[category]: # FIXME: This is not adding some "uncategorized" apps
app_id = app['flatpakAppId']
if not app_id in already_added:
version = app_id_ver_dict.get(app_id) or "No version"
app_info = AppInfo(app['name'], app_id, app['summary'], version, category, AppType.FLATPAK_APP)
already_added.append(app_id)
fp_app_info.append(app_info)

return fp_app_info
return app_list
Loading

0 comments on commit 1d6aa33

Please sign in to comment.