From 12b2b0b2a4bd4bdda20d55fea4a45096651460be Mon Sep 17 00:00:00 2001 From: Gobinath Date: Fri, 25 Dec 2020 19:22:57 -0500 Subject: [PATCH] Create desktop entries from the code --- .../icons/hicolor/128x128/apps/safeeyes.png | Bin .../icons/hicolor/16x16/apps/safeeyes.png | Bin .../16x16/status/safeeyes_disabled.png | Bin .../hicolor/16x16/status/safeeyes_enabled.png | Bin .../hicolor/16x16/status/safeeyes_timer.png | Bin .../icons/hicolor/24x24/apps/safeeyes.png | Bin .../24x24/status/safeeyes_disabled.png | Bin .../hicolor/24x24/status/safeeyes_enabled.png | Bin .../hicolor/24x24/status/safeeyes_timer.png | Bin .../icons/hicolor/32x32/apps/safeeyes.png | Bin .../32x32/status/safeeyes_disabled.png | Bin .../hicolor/32x32/status/safeeyes_enabled.png | Bin .../icons/hicolor/48x48/apps/safeeyes.png | Bin .../48x48/status/safeeyes_disabled.png | Bin .../hicolor/48x48/status/safeeyes_enabled.png | Bin .../icons/hicolor/64x64/apps/safeeyes.png | Bin .../platform}/safeeyes.desktop | 0 safeeyes/utility.py | 75 ++++++++++++++---- setup.py | 4 +- 19 files changed, 64 insertions(+), 15 deletions(-) rename {share => safeeyes/platform}/icons/hicolor/128x128/apps/safeeyes.png (100%) rename {share => safeeyes/platform}/icons/hicolor/16x16/apps/safeeyes.png (100%) rename {share => safeeyes/platform}/icons/hicolor/16x16/status/safeeyes_disabled.png (100%) rename {share => safeeyes/platform}/icons/hicolor/16x16/status/safeeyes_enabled.png (100%) rename {share => safeeyes/platform}/icons/hicolor/16x16/status/safeeyes_timer.png (100%) rename {share => safeeyes/platform}/icons/hicolor/24x24/apps/safeeyes.png (100%) rename {share => safeeyes/platform}/icons/hicolor/24x24/status/safeeyes_disabled.png (100%) rename {share => safeeyes/platform}/icons/hicolor/24x24/status/safeeyes_enabled.png (100%) rename {share => safeeyes/platform}/icons/hicolor/24x24/status/safeeyes_timer.png (100%) rename {share => safeeyes/platform}/icons/hicolor/32x32/apps/safeeyes.png (100%) rename {share => safeeyes/platform}/icons/hicolor/32x32/status/safeeyes_disabled.png (100%) rename {share => safeeyes/platform}/icons/hicolor/32x32/status/safeeyes_enabled.png (100%) rename {share => safeeyes/platform}/icons/hicolor/48x48/apps/safeeyes.png (100%) rename {share => safeeyes/platform}/icons/hicolor/48x48/status/safeeyes_disabled.png (100%) rename {share => safeeyes/platform}/icons/hicolor/48x48/status/safeeyes_enabled.png (100%) rename {share => safeeyes/platform}/icons/hicolor/64x64/apps/safeeyes.png (100%) rename {share/applications => safeeyes/platform}/safeeyes.desktop (100%) diff --git a/share/icons/hicolor/128x128/apps/safeeyes.png b/safeeyes/platform/icons/hicolor/128x128/apps/safeeyes.png similarity index 100% rename from share/icons/hicolor/128x128/apps/safeeyes.png rename to safeeyes/platform/icons/hicolor/128x128/apps/safeeyes.png diff --git a/share/icons/hicolor/16x16/apps/safeeyes.png b/safeeyes/platform/icons/hicolor/16x16/apps/safeeyes.png similarity index 100% rename from share/icons/hicolor/16x16/apps/safeeyes.png rename to safeeyes/platform/icons/hicolor/16x16/apps/safeeyes.png diff --git a/share/icons/hicolor/16x16/status/safeeyes_disabled.png b/safeeyes/platform/icons/hicolor/16x16/status/safeeyes_disabled.png similarity index 100% rename from share/icons/hicolor/16x16/status/safeeyes_disabled.png rename to safeeyes/platform/icons/hicolor/16x16/status/safeeyes_disabled.png diff --git a/share/icons/hicolor/16x16/status/safeeyes_enabled.png b/safeeyes/platform/icons/hicolor/16x16/status/safeeyes_enabled.png similarity index 100% rename from share/icons/hicolor/16x16/status/safeeyes_enabled.png rename to safeeyes/platform/icons/hicolor/16x16/status/safeeyes_enabled.png diff --git a/share/icons/hicolor/16x16/status/safeeyes_timer.png b/safeeyes/platform/icons/hicolor/16x16/status/safeeyes_timer.png similarity index 100% rename from share/icons/hicolor/16x16/status/safeeyes_timer.png rename to safeeyes/platform/icons/hicolor/16x16/status/safeeyes_timer.png diff --git a/share/icons/hicolor/24x24/apps/safeeyes.png b/safeeyes/platform/icons/hicolor/24x24/apps/safeeyes.png similarity index 100% rename from share/icons/hicolor/24x24/apps/safeeyes.png rename to safeeyes/platform/icons/hicolor/24x24/apps/safeeyes.png diff --git a/share/icons/hicolor/24x24/status/safeeyes_disabled.png b/safeeyes/platform/icons/hicolor/24x24/status/safeeyes_disabled.png similarity index 100% rename from share/icons/hicolor/24x24/status/safeeyes_disabled.png rename to safeeyes/platform/icons/hicolor/24x24/status/safeeyes_disabled.png diff --git a/share/icons/hicolor/24x24/status/safeeyes_enabled.png b/safeeyes/platform/icons/hicolor/24x24/status/safeeyes_enabled.png similarity index 100% rename from share/icons/hicolor/24x24/status/safeeyes_enabled.png rename to safeeyes/platform/icons/hicolor/24x24/status/safeeyes_enabled.png diff --git a/share/icons/hicolor/24x24/status/safeeyes_timer.png b/safeeyes/platform/icons/hicolor/24x24/status/safeeyes_timer.png similarity index 100% rename from share/icons/hicolor/24x24/status/safeeyes_timer.png rename to safeeyes/platform/icons/hicolor/24x24/status/safeeyes_timer.png diff --git a/share/icons/hicolor/32x32/apps/safeeyes.png b/safeeyes/platform/icons/hicolor/32x32/apps/safeeyes.png similarity index 100% rename from share/icons/hicolor/32x32/apps/safeeyes.png rename to safeeyes/platform/icons/hicolor/32x32/apps/safeeyes.png diff --git a/share/icons/hicolor/32x32/status/safeeyes_disabled.png b/safeeyes/platform/icons/hicolor/32x32/status/safeeyes_disabled.png similarity index 100% rename from share/icons/hicolor/32x32/status/safeeyes_disabled.png rename to safeeyes/platform/icons/hicolor/32x32/status/safeeyes_disabled.png diff --git a/share/icons/hicolor/32x32/status/safeeyes_enabled.png b/safeeyes/platform/icons/hicolor/32x32/status/safeeyes_enabled.png similarity index 100% rename from share/icons/hicolor/32x32/status/safeeyes_enabled.png rename to safeeyes/platform/icons/hicolor/32x32/status/safeeyes_enabled.png diff --git a/share/icons/hicolor/48x48/apps/safeeyes.png b/safeeyes/platform/icons/hicolor/48x48/apps/safeeyes.png similarity index 100% rename from share/icons/hicolor/48x48/apps/safeeyes.png rename to safeeyes/platform/icons/hicolor/48x48/apps/safeeyes.png diff --git a/share/icons/hicolor/48x48/status/safeeyes_disabled.png b/safeeyes/platform/icons/hicolor/48x48/status/safeeyes_disabled.png similarity index 100% rename from share/icons/hicolor/48x48/status/safeeyes_disabled.png rename to safeeyes/platform/icons/hicolor/48x48/status/safeeyes_disabled.png diff --git a/share/icons/hicolor/48x48/status/safeeyes_enabled.png b/safeeyes/platform/icons/hicolor/48x48/status/safeeyes_enabled.png similarity index 100% rename from share/icons/hicolor/48x48/status/safeeyes_enabled.png rename to safeeyes/platform/icons/hicolor/48x48/status/safeeyes_enabled.png diff --git a/share/icons/hicolor/64x64/apps/safeeyes.png b/safeeyes/platform/icons/hicolor/64x64/apps/safeeyes.png similarity index 100% rename from share/icons/hicolor/64x64/apps/safeeyes.png rename to safeeyes/platform/icons/hicolor/64x64/apps/safeeyes.png diff --git a/share/applications/safeeyes.desktop b/safeeyes/platform/safeeyes.desktop similarity index 100% rename from share/applications/safeeyes.desktop rename to safeeyes/platform/safeeyes.desktop diff --git a/safeeyes/utility.py b/safeeyes/utility.py index 427432a..d9e2f83 100644 --- a/safeeyes/utility.py +++ b/safeeyes/utility.py @@ -34,6 +34,7 @@ import subprocess import threading from distutils.version import LooseVersion from logging.handlers import RotatingFileHandler +from pathlib import Path import babel.core import babel.dates @@ -60,6 +61,8 @@ LOG_FILE_PATH = os.path.join(HOME_DIRECTORY, 'safeeyes.log') SYSTEM_PLUGINS_DIR = os.path.join(BIN_DIRECTORY, 'plugins') USER_PLUGINS_DIR = os.path.join(CONFIG_DIRECTORY, 'plugins') LOCALE_PATH = os.path.join(BIN_DIRECTORY, 'config/locale') +SYSTEM_DESKTOP_FILE = os.path.join(BIN_DIRECTORY, "platform/safeeyes.desktop") +SYSTEM_ICONS = os.path.join(BIN_DIRECTORY, "platform/icons") DESKTOP_ENVIRONMENT = None IS_WAYLAND = False @@ -362,35 +365,77 @@ def initialize_safeeyes(): logging.info('Copy the config files to ~/.config/safeeyes') style_dir_path = os.path.join(HOME_DIRECTORY, '.config/safeeyes/style') - startup_dir_path = os.path.join(HOME_DIRECTORY, '.config/autostart') - + # Remove the ~/.config/safeeyes/safeeyes.json file delete(CONFIG_FILE_PATH) - # Remove the startup file - delete(os.path.join(HOME_DIRECTORY, os.path.join( - startup_dir_path, 'safeeyes.desktop'))) - # Create the ~/.config/safeeyes/style directory mkdir(style_dir_path) - mkdir(startup_dir_path) # Copy the safeeyes.json shutil.copy2(SYSTEM_CONFIG_FILE_PATH, CONFIG_FILE_PATH) os.chmod(CONFIG_FILE_PATH, 0o777) - # Copy the new startup file - try: - os.symlink("/usr/share/applications/safeeyes.desktop", - os.path.join(startup_dir_path, 'safeeyes.desktop')) - except OSError: - pass - # Copy the new style sheet if not os.path.isfile(STYLE_SHEET_PATH): shutil.copy2(SYSTEM_STYLE_SHEET_PATH, STYLE_SHEET_PATH) os.chmod(STYLE_SHEET_PATH, 0o777) + initialize_platform() + + +def initialize_platform(): + """ + Copy icons and generate desktop entries. + """ + logging.debug("Initialize the platform") + + applications_dir_path = os.path.join(HOME_DIRECTORY, '.local/share/applications') + icons_dir_path = os.path.join(HOME_DIRECTORY, '.local/share/icons') + startup_dir_path = os.path.join(HOME_DIRECTORY, '.config/autostart') + desktop_entry = os.path.join(applications_dir_path, 'safeeyes.desktop') + startup_entry = os.path.join(startup_dir_path, 'safeeyes.desktop') + + # Create the folders if not exist + mkdir(applications_dir_path) + mkdir(icons_dir_path) + mkdir(startup_dir_path) + + # Remove existing files + delete(desktop_entry) + delete(startup_entry) + + # Create a destop entry + try: + os.symlink(SYSTEM_DESKTOP_FILE, desktop_entry) + except OSError: + logging.error("Failed to create desktop entry at %s" % desktop_entry) + + # Create the new startup entry + try: + os.symlink(SYSTEM_DESKTOP_FILE, startup_entry) + except OSError: + logging.error("Failed to create startup entry at %s" % startup_entry) + + # Add links for all icons + for (path, _, filenames) in os.walk(SYSTEM_ICONS): + for filename in filenames: + system_icon = os.path.join(path, filename) + local_icon = os.path.join(icons_dir_path, os.path.relpath(system_icon, SYSTEM_ICONS)) + parent_dir = str(Path(local_icon).parent) + + # Create the directory if not exists + mkdir(parent_dir) + + # Remove the link if already exists + delete(local_icon) + + # Add a link for the icon + try: + os.symlink(system_icon, local_icon) + except OSError: + logging.error("Failed to create icon link at %s" % local_icon) + def reset_config(): # Remove the ~/.config/safeeyes/safeeyes.json and safeeyes_style.css @@ -405,6 +450,8 @@ def reset_config(): os.chmod(CONFIG_FILE_PATH, 0o777) os.chmod(STYLE_SHEET_PATH, 0o777) + initialize_platform() + def replace_style_sheet(): """ Replace the user style sheet by system style sheet. diff --git a/setup.py b/setup.py index da6de92..07dfc74 100644 --- a/setup.py +++ b/setup.py @@ -65,10 +65,12 @@ def __package_data(): data = ['glade/*.glade', 'resource/*'] data.extend(__package_files('safeeyes/config')) data.extend(__package_files('safeeyes/plugins')) + data.extend(__package_files('safeeyes/platform')) return data -__data_files = list(_data_files('share')) +# __data_files = list(_data_files('share')) +__data_files = list() setuptools.setup( name="safeeyes",