Revert "Merge remote-tracking branch 'origin/dev'"

This reverts commit e06ea66f, reversing
changes made to b8df9b8f.
parent e06ea66f
......@@ -37,8 +37,9 @@ mock/var/lib/application-utility/status.json
.mr.developer.cfg
.project
.pydevproject
#.idea
.idea
.vscode
# Complexity
output/*.html
output/*/index.html
......
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.vscode" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (application-utility)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BashSupportProjectSettings">
<option name="globalVariables">
<set>
<option value="PKG_CONFIG_PATH=/usr/lib/pkgconfig" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<component name="ProjectDictionaryState">
<dictionary name="fh">
<words>
<w>appstream</w>
<w>archlinux</w>
<w>filedefault</w>
<w>levelname</w>
<w>manjaro</w>
<w>pacman</w>
<w>pamac</w>
<w>pkgs</w>
<w>pythonpath</w>
<w>screenshot</w>
<w>treeview</w>
</words>
</dictionary>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="E402" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="gi.repository.Pamac" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (application-utility)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/application-utility.iml" filepath="$PROJECT_DIR$/.idea/application-utility.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -103,9 +103,9 @@ An editor of choice e.g.
```bash
git clone https://gitlab.manjaro.org/fhdk/application-utility.git
cd application-utility
sudo pacman -Syu python-pip python-virtualenvwrapper gobject-introspection
sudo pacman -Syu python-pip python-virtualenvwrapper
mkvirtualenv application-utility
pip install mkdocs coverage babel flake8 transifex-client pygobject
pip install mkdocs coverage babel flake8 transifex-client
python setup.py develop
```
__version__ = "1.1.0.dev2"
__all__ = ["browser", "__version__", "translation", "constants", "config"]
__version__ = "1.0.2"
__all__ = ["browser", "__version__"]
......@@ -18,14 +18,15 @@
# papajoke
import gi
import requests
from requests.exceptions import ConnectionError
import os
import logging
import sys
from application_utility.browser.app_config import AppConfig
from application_utility.browser.application_browser import ApplicationBrowser
from .browser.app_config import AppConfig
from .browser.application_browser import ApplicationBrowser
from application_utility.__init__ import __version__
from application_utility.translation import custom_help_formatter
_ = custom_help_formatter.CustomHelpFormatter
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, GdkPixbuf
......
......@@ -22,16 +22,9 @@ Module alpm
Install / remove packages
use pamac-installer
"""
import gi
import subprocess
import glob
import logging
import subprocess
gi.require_version("Pamac", "1.0")
from gi.repository import Pamac
from application_utility.translation import i18n
_ = i18n.language.gettext
class Alpm:
......@@ -138,10 +131,3 @@ class Alpm:
def __str__(self):
return f"pkg list install: {self.pkg_list_install}\n pkg list removal: {self.pkg_list_removal}"
@staticmethod
def pkg_exist(pkgname: str) ->bool:
"""check if a package exist"""
config = Pamac.Config(conf_path="/etc/pamac.conf")
db = Pamac.Database(config=config)
return bool(db.search_pkgs(pkgname))
......@@ -23,9 +23,6 @@ import sys
from .config import Config
from application_utility.translation import i18n
_ = i18n.language.gettext
class AppConfig(Config):
"""
......@@ -37,5 +34,22 @@ class AppConfig(Config):
self.pref = {"data-set": "default"}
self.url = {"desktop": "", "main": ""}
self.file = {"desktop": "", "main": f"{self._DATA_DIR}/default.json"}
self.file["main"] = self.get_datafile(self.file["main"], "file")
self.desktop = os.environ.get("XDG_SESSION_DESKTOP")
if len(sys.argv) > 1: # and not "--dev" in sys.argv:
file = sys.argv[1]
if os.path.isfile(file):
self.file["main"] = file
else:
if file.startswith("http"):
try:
# TODO make only head() ?
requests.get(file)
self.url["main"] = file
logging.info(f"json to use: f{self.url['main']}")
# TODO save in self._MERGE_FILE
except ConnectionError:
logging.critical('json data not found')
# else:
# self.file["main"] = file
return self
......@@ -35,9 +35,6 @@ from gi.repository import Gtk
gi.require_version('Pamac', '1.0')
from gi.repository import Pamac
from application_utility.translation import i18n
_ = i18n.language.gettext
# Applications class constants
TITLE = f"{txt.MAU} v.{__version__}"
......@@ -46,9 +43,7 @@ GROUP, ICON, APPLICATION, DESCRIPTION, ACTIVE, PACKAGE, INSTALLED = list(range(7
class ApplicationBrowser(Gtk.Box):
"""
Class Applications with veiw, title and buttons
"""
"""Class Applications with viw, title and btns"""
def __init__(self, config: Config, window: Gtk.Window, orientation=Gtk.Orientation.VERTICAL, spacing=1):
super().__init__(orientation=orientation, spacing=spacing, expand=True)
......@@ -65,8 +60,6 @@ class ApplicationBrowser(Gtk.Box):
pix_buf96 = Gtk.IconTheme.get_default().load_icon(icon, 96, 0)
window.set_icon_list([pix_buf24, pix_buf32, pix_buf48, pix_buf64, pix_buf96])
self.info_bar_appstream = Gtk.InfoBar()
# initialize data storage
self.app_store = list()
self.group_store = list()
......@@ -76,7 +69,7 @@ class ApplicationBrowser(Gtk.Box):
self.app_browser_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, expand=True)
self.add(self.app_browser_box)
if not isinstance(self.config, HelloConfig):
if isinstance(self.config, HelloConfig):
# InfoBar title
self.info_bar_title = Gtk.InfoBar()
self.info_bar_title.set_message_type(Gtk.MessageType.OTHER)
......@@ -85,7 +78,8 @@ class ApplicationBrowser(Gtk.Box):
self.info_bar_title.connect("response", self.on_remove_title_box)
# title label
self.title_label = Gtk.Label()
self.title_label.set_markup(f"{txt.SELECT_APPS} <b>{txt.BTN_UPDATE_SYSTEM}</b> {txt.WHEN_READY}. ")
self.title_label.set_markup(f"<b>{txt.MAM}</b>\n"
f"{txt.SELECT_APPS} <b>{txt.BTN_UPDATE_SYSTEM}</b> {txt.WHEN_READY}. ")
# pack title info
self.info_bar_title.pack_start(self.title_label, expand=True, fill=True, padding=0)
# pack title info to app browser box
......@@ -107,34 +101,24 @@ class ApplicationBrowser(Gtk.Box):
else:
# InfoBar title
self.info_bar_title = Gtk.InfoBar()
self.info_bar_title.set_message_type(Gtk.MessageType.OTHER)
self.info_bar_title.set_show_close_button(True)
self.info_bar_title.set_revealed(True)
self.info_bar_title.connect("response", self.on_remove_title_box)
self.info_bar_title = Gtk.Box()
# self.info_bar_title.set_message_type(Gtk.MessageType.OTHER)
# self.info_bar_title.set_show_close_button(True)
# self.info_bar_title.set_revealed(True)
# self.info_bar_title.connect("response", self.on_remove_title_box)
title_image = Gtk.Image()
title_image.set_size_request(100, 100)
title_image.set_from_file("/usr/share/icons/manjaro/maia/96x96.png")
self.info_bar_title.pack_start(title_image, expand=False, fill=False, padding=0)
# title label
self.title_label = Gtk.Label()
self.title_label.set_markup(f"<b>{txt.MAM}</b>\n"
self.title_label.set_markup(f"<b>{txt.MAU}</b>\n"
f"{txt.SELECT_APPS} <b>{txt.BTN_UPDATE_SYSTEM}</b> {txt.WHEN_READY}. ")
# pack title info
self.info_bar_title.pack_start(self.title_label, expand=True, fill=True, padding=0)
# pack title info to app browser box
self.app_browser_box.pack_start(self.info_bar_title, expand=False, fill=True, padding=0)
# InfoBar appstream detail
self.info_bar_appstream = Gtk.InfoBar()
self.info_bar_appstream.set_message_type(Gtk.MessageType.OTHER)
self.info_bar_appstream.set_show_close_button(True)
self.info_bar_appstream.set_revealed(True)
self.info_bar_appstream.connect("response", self.on_remove_detail_box)
# app stream data
self.detail_label = Gtk.Label()
self.detail_label.set_line_wrap(True)
self.info_bar_appstream.pack_start(self.detail_label, expand=True, fill=True, padding=0)
# pack appstream info to app browser box
self.app_browser_box.pack_start(self.info_bar_appstream, expand=False, fill=True, padding=0)
# button box
self.button_box = Gtk.Box(spacing=10)
# advanced button
......@@ -214,8 +198,10 @@ class ApplicationBrowser(Gtk.Box):
# show time
self.show_all()
if self.info_bar_appstream:
self.info_bar_appstream.hide()
# hide appstream data until needed - why does it not hide?
# not completely
# # if self.info_bar_appstream:
# self.info_bar_appstream.hide()
def create_view_tree(self):
"""create gtk view and model"""
......@@ -326,36 +312,40 @@ class ApplicationBrowser(Gtk.Box):
self.tree_view.expand_all()
self.update_system_button.set_sensitive(not self.alpm.empty)
@staticmethod
def treeview_cell_check_data_function(column: Gtk.TreeViewColumn,
renderer_cell: Gtk.CellRenderer,
model: Gtk.TreeModel,
iter_a: Gtk.TreeIter,
user_data):
"""
hide checkbox for groups
"""
value = model.get(iter_a, GROUP)
renderer_cell.set_visible(not value[0])
@staticmethod
def treeview_cell_app_data_function(column: Gtk.TreeViewColumn,
renderer_cell: Gtk.CellRenderer,
model: Gtk.TreeModel,
iter_a: Gtk.TreeIter,
user_data):
"""
change font if installed
"""
"""change font if installed"""
value = model.get(iter_a, INSTALLED)
if value[0]:
renderer_cell.props.weight = 600
else:
renderer_cell.props.weight = 400
def on_remove_title_box(self, panel: Gtk.InfoBar, id: str):
if self.info_bar_title:
self.info_bar_title.hide()
@staticmethod
def treeview_cell_check_data_function(column: Gtk.TreeViewColumn,
renderer_cell: Gtk.CellRenderer,
model: Gtk.TreeModel,
iter_a: Gtk.TreeIter,
user_data):
"""hide checkbox for groups"""
value = model.get(iter_a, GROUP)
renderer_cell.set_visible(not value[0])
@staticmethod
def on_signal_close(panel: Gtk.InfoBar):
if panel:
panel.hide()
@staticmethod
def on_remove_title_box(panel: Gtk.InfoBar, response_id: str):
if panel:
panel.hide()
# if self.info_bar_title:
# self.info_bar_title.hide()
# Or not destroy ? for use set_title_box
# self.title_box.destroy()
# self.title_box = None
......@@ -410,7 +400,7 @@ class ApplicationBrowser(Gtk.Box):
db = Pamac.Database(config=Pamac.Config(conf_path="/etc/pamac.conf"))
db.enable_appstream()
detail = db.get_pkg_details(pkg['pkg'], pkg['name'], False)
detail = db.get_pkg_details(pkg['pkg'], pkg['name'])
if detail:
if self.info_bar_title:
self.info_bar_title.hide()
......@@ -498,7 +488,6 @@ class ApplicationBrowser(Gtk.Box):
self.reload_app_data(True)
self.set_title_box(txt.DOWNLOAD_COMPLETE)
except Exception as e:
print(e)
logging.error(e)
else:
......@@ -559,7 +548,7 @@ class ApplicationBrowser(Gtk.Box):
def net_check():
"""Check for internet connection"""
resp = None
host = f"https://{txt.GITLAB}"
host = f"https://{txt.URL_GITLAB}"
# noinspection PyBroadException
try:
resp = urllib.request.urlopen(host, timeout=2)
......
......@@ -24,10 +24,7 @@ import os
import logging
import tempfile
import requests
# from requests.exceptions import ConnectionError
from application_utility.translation import i18n
_ = i18n.language.gettext
#from requests.exceptions import ConnectionError
from application_utility.constants import txt
......@@ -118,7 +115,7 @@ class BaseConfig:
if ret.status_code < 300:
logging.info("iso json to use: %s", src)
request = requests.get(src, allow_redirects=True)
# TODO create /tmp/m-apps ?
#TODO create /tmp/m-apps ?
tmp_file = tempfile.NamedTemporaryFile(delete=False) # dir="m-apps"
tmp_file.write(request.content)
tmp_file.close()
......@@ -137,60 +134,36 @@ class BaseConfig:
desktop = BaseConfig.get_arg_value("desktop")
if not desktop:
desktop = os.environ.get("DESKTOP_SESSION", "?").lower()
switcher = {
"budgie-desktop": "budgie",
"/usr/share/xsessions/plasma": "kde",
"/usr/share/xsessions/lxqt": "lxqt",
"jade": "webdad",
"/usr/share/xsessions/jwm": "jwm",
desktops = {
"awesome": "awesome",
"bspwm": "bspwm",
"budgie-desktop": "budgie",
"cinnamon": "cinnamon",
"deepin": "deepin",
"i3": "i3",
"jade": "webdad",
"jwm": "/usr/share/xsessions/jwm",
"kde": "/usr/share/xsessions/plasma",
"lxde": "lxde",
"lxqt": "/usr/share/xsessions/lxqt",
"mate": "mate",
"openbox": "openbox",
"gnome": "gnome",
"xfce": "xfce",
"openbox": "openbox"
}
desktop = switcher.get(desktop, "?")
return desktop.lower()
@staticmethod
def get_manjaro_desktop(find_desktop: str, prefix: bool = True) ->str:
"""return generator on all manjaro desktop available"""
desks = ["xfce", "kde", "gnome"]
if find_desktop in desks:
if prefix:
find_desktop = "manjaro/"+find_desktop
return find_desktop
desks = ["openbox", "mate", "deepin", "bspwm", "cinnamon", "lxqt", "awesome", "budgie", "lxde", "i3", "webdad"]
if find_desktop in desks:
if prefix:
find_desktop = "community/"+find_desktop
return find_desktop
return ""
#TODO to remove or move to tests
@staticmethod
def get_desktop_tests():
for test in ["LXDE", "lxde", 'MATE', 'mate', "budgie-desktop", "/usr/share/xsessions/plasma"]:
os.environ["DESKTOP_SESSION"] = test
desktop = BaseConfig.get_desktop()
print("desktop", desktop, "for env:"+test)
desktop = BaseConfig.get_manjaro_desktop(desktop)
print("\t", desktop)
for de_key, de_value in desktops.items():
if desktop == de_value:
return de_key
# return the ? if no result from the dictionary
return desktop
def get_iso_filename(self) ->str:
"""get filename from env, if url create temp file
can use parameter:
can use parameter:
app.py --iso="https://gitlab.manjaro.org/papajoke/application-utility/raw/dev/share/kde.json"
app.py --iso="/home/****.json"
app.py --desktop=gnome
"""
# TODO
# to rewrite by a maintener
# to rewrite by a maintainer
desktop = self.get_desktop()
# test if exist
......@@ -199,15 +172,13 @@ class BaseConfig:
if src and not os.path.isfile(src):
logging.warning("iso not found: %s", src)
# TODO use txt.OFFICIAL_ISO_URL
desktop = self.get_manjaro_desktop(desktop)
if desktop:
src = f"https://gitlab.manjaro.org/profiles-and-settings/iso-profiles/raw/manjaro-architect/{desktop}/apps.json"
logging.debug("find iso url: %s", src)
return self.download_file(src)
# TODO rewrite with self.preferences ... ?
# TODO get Packages-Desktop and parse maintainers tags?
if desktop in ("xfce", "kde", "gnome"):
src = f"{txt.ISO_URL_OFFICIAL}/{desktop}/{desktop}.json"
else:
src = f"{txt.ISO_URL_COMMUNITY}/{desktop}/{desktop}.json"
logging.debug("find iso url: %s", src)
return self.download_file(src)
else:
return src
#test desktops
#BaseConfig.get_desktop_tests()
#exit(0)
......@@ -22,14 +22,10 @@ import logging
import os
import shutil
import urllib.request
import json
import collections
from .data import Data
from .base_config import BaseConfig
from application_utility.translation import i18n
_ = i18n.language.gettext
class Config(BaseConfig, Data):
"""Configuration with data"""
......@@ -40,7 +36,6 @@ class Config(BaseConfig, Data):
def __init__(self, application: str):
BaseConfig.__init__(self, application)
Data.__init__(self)
self.desktop = self.get_desktop()
self.application = application
self.load()
self.merge_json()
......@@ -52,32 +47,18 @@ class Config(BaseConfig, Data):
and use only self._MERGE_FILE ?
Always save .json in self._MERGE_FILE ?
"""
src = self.file["main"]
logging.info(f"json to merge : {src}")
if not src or not os.path.isfile(src):
raise ImportError(f"ERROR: json file not found: {src}")
# write temp
if self.url["main"]:
src = f"/tmp/{self.application}-download.json"
urllib.request.urlretrieve(self.url["main"], src)
logging.info(f"URL: [{self.url['main']} downloaded")
else:
src = self.file["main"]
logging.info(f"json to merge : {src}")
if not os.path.isfile(src):
logging.error(f"ERROR: File not found: {src}")
raise ImportError(src)
shutil.copyfile(src, self._MERGE_FILE)
logging.debug(f"json : {self._MERGE_FILE}")
self.load_from_file(self._MERGE_FILE)
iso_file = self.get_iso_filename()
if iso_file:
# iso to merge found
#iso_json = json.loads(iso_file)
with open(iso_file, "rb") as infile:
iso_json = json.loads(
infile.read().decode("utf8"),
object_pairs_hook=collections.OrderedDict)
for group in iso_json:
print(type(group))
print(group)
for app in group['apps']:
print(app)
print(type(app))
self.append_app(group, app)
# save merged
self.save_apps_to_json(self._MERGE_FILE)
# load complete json
self.load_from_file(self._MERGE_FILE)
#exit(0)
......@@ -30,9 +30,6 @@ import gi
gi.require_version('Pamac', '1.0')
from gi.repository import Pamac
from application_utility.translation import i18n
_ = i18n.language.gettext
class Data:
def __init__(self):
......@@ -158,7 +155,7 @@ class Data:
use pamac/appstream for locale description
"""
app['appstream'] = False
detail = db.get_pkg_details(app['pkg'], app['name'], False)
detail = db.get_pkg_details(app['pkg'], app['name'])
if detail:
app['appstream'] = True
d = detail.get_desc()
......@@ -178,11 +175,6 @@ class Data:
pass
return result
def save_apps_to_json(self, filename):
with open(filename, "w") as data_file:
json.dump(self._json, data_file, indent=2) # sort_keys=True
data_file.flush()
@property
def categories(self) -> Iterator[str]:
"""
......@@ -226,34 +218,6 @@ class Data:
if founds:
return founds[0]
def append_app(self, group, app):