Commit 34825230 authored by Roman Alifanov's avatar Roman Alifanov

load modules from /usr/share/tuneit/modules/ but local modules are a priority.

parent 8c1759b4
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="tuneit"> <schemalist gettext-domain="tuneit">
<schema id="ru.ximperlinux.TuneIt" path="/ru.ximperlinux.TuneIt/"> <schema id="ru.ximperlinux.TuneIt" path="/ru.ximperlinux.TuneIt/">
<key name="show_root_modules" type="b">
<default>false</default>
<description>Show modules that require root permissions</description>
</key>
</schema> </schema>
</schemalist> </schemalist>
pluginsdir = pkgdatadir / 'modules' pluginsdir = pkgdatadir / 'modules'
plugins = [ plugins = [
'exampleplug.yml', 'exampleplug',
] ]
install_data(plugins, install_dir: pluginsdir) install_subdir(plugins, install_dir: pluginsdir)
...@@ -2,22 +2,31 @@ import os ...@@ -2,22 +2,31 @@ import os
import yaml import yaml
def get_local_share_directory(): def get_local_module_directory():
home_directory = os.path.expanduser("~") home_directory = os.path.expanduser("~")
local_share_directory = os.path.join(home_directory, ".local", "share", "tuneit") return os.path.join(home_directory, ".local", "share", "tuneit", "modules")
return local_share_directory
def get_module_directory():
return "/usr/share/tuneit/modules"
def load_modules(): def load_modules():
modules = [] modules = []
local_share_directory = get_local_share_directory() local_modules_directory = get_local_module_directory()
global_modules_directory = get_module_directory()
modules_directory = os.path.join(local_share_directory, "modules")
if not os.path.exists(modules_directory): all_modules = set(os.listdir(global_modules_directory))
print(f"Директория {modules_directory} не существует")
return modules for module_name in os.listdir(local_modules_directory):
module_path = os.path.join(local_modules_directory, module_name)
modules = load_yaml_files_from_directory(modules_directory) if os.path.isdir(module_path):
modules += load_yaml_files_from_directory(module_path)
all_modules.discard(module_name)
for module_name in all_modules:
module_path = os.path.join(global_modules_directory, module_name)
if os.path.isdir(module_path):
modules += load_yaml_files_from_directory(module_path)
return modules return modules
def load_yaml_files_from_directory(directory): def load_yaml_files_from_directory(directory):
...@@ -35,7 +44,6 @@ def load_yaml_files_from_directory(directory): ...@@ -35,7 +44,6 @@ def load_yaml_files_from_directory(directory):
print(f"Ошибка при чтении файла {file_path}: {e}") print(f"Ошибка при чтении файла {file_path}: {e}")
return yaml_data return yaml_data
def merge_categories_by_name(categories_data): def merge_categories_by_name(categories_data):
categories_dict = {} categories_dict = {}
for category_data in categories_data: for category_data in categories_data:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment