Ejemplo n.º 1
0
 def conversion_tool():
     """Return conversion tool set in the config file."""
     if not JSONConfig._conversion_tool:
         conversion_tool = JSONConfig.get_default().get("conversion-tool")
         Logger.debug("Config/Conversion Tool: {}".format(conversion_tool))
         JSONConfig._conversion_tool = conversion_tool
     return JSONConfig._conversion_tool
Ejemplo n.º 2
0
 def icon_size():
     """Return Icon size set by args --size."""
     if ArgumentsConfig._icon_size is None:
         icon_size = ArgumentsConfig.args().size
         Logger.debug("Arguments/Icon Size: {}".format(icon_size))
         ArgumentsConfig._icon_size = icon_size
     return ArgumentsConfig._icon_size
Ejemplo n.º 3
0
 def set_value(self, key, value):
     """Set a value in the resources list using a key."""
     try:
         self._resources[int(key)] = value
     except KeyError:
         Logger.warning("The key {0} dosen't seem to"
                        " be found on {1}".format(key, self._filename))
Ejemplo n.º 4
0
    def _read(self):
        """
            Read the json file and parse it.
        """
        from src.app import App
        do_later = ["app_path", "icons_path", "icons"]
        try:
            with open(self._db_file, 'r') as db_obj:
                data = json.load(db_obj)
                for key, value in data.items():
                    if key not in do_later:
                        setattr(self, key, value)
        except (FileNotFoundError, ValueError, KeyError):
            Logger.error("Application file is broken: {}".format(
                self._db_file))

        self._parse_paths(data["app_path"], "app_path")
        self._parse_paths(data["icons_path"], "icons_path")
        self._parse_icons(data["icons"])

        if len(App.get("only")) == 1 and App.path():
            self.app_path.append(App.path())

        found = self.icons and self.app_path
        if self.force_create_folder and found:
            for icon_path in self.icons_path:
                create_dir(str(icon_path))
            self.dont_install = False
        else:
            self.dont_install = not (found and self.icons_path)

        # NWJS special case
        if self.get_type() == "nwjs" and not self.dont_install:
            self.dont_install = not App.get("nwjs")
Ejemplo n.º 5
0
 def nwjs(self):
     """Return nwjs sdk path."""
     nwjs = self._nwjs
     if nwjs and path.exists(nwjs):
         Logger.debug("Config/NWJS SDK: {}".format(nwjs))
         return nwjs
     return None
Ejemplo n.º 6
0
 def install_icon(self, icon, icon_path):
     """Install the icon."""
     pngbytes = get_pngbytes(icon)
     if pngbytes:
         self.set_icon(icon.original, icon_path, pngbytes, True)
     else:
         Logger.error("PNG file was not found.")
Ejemplo n.º 7
0
 def backup_ignore():
     """Return a boolean, ignore backup or not."""
     if JSONConfig._backup_ignore is None:
         backup_ignore = JSONConfig.get_default().get("backup-ignore", False)
         Logger.debug("Config/Backup Ignore: {}".format(str(backup_ignore)))
         JSONConfig._backup_ignore = backup_ignore
     return JSONConfig._backup_ignore
Ejemplo n.º 8
0
    def pack(self, icon_path):
        """Recreate the zip file from the tmp directory."""
        from src.app import App
        nwjs_sdk = App.get("nwjs")
        if nwjs_sdk:
            binary_file = "/tmp/{0}".format(self.binary)

            Logger.debug("NWJS Application: Creating new archive {}".format(
                self.binary))
            make_archive(binary_file, "zip", self.tmp_path)

            move(binary_file + ".zip", binary_file + ".nw")

            local_binary_file = path.join(nwjs_sdk, self.binary)

            move(binary_file + ".nw", local_binary_file + ".nw")

            Logger.debug("NWJS Application: Creating executable file.")
            execute(["cat which nw " + self.binary + ".nw > " + self.binary],
                    True, True, nwjs_sdk)

            remove(local_binary_file + ".nw")

            move(local_binary_file, path.join(str(icon_path), self.binary))
            execute(["chmod", "+x", path.join(str(icon_path), self.binary)])

        rmtree(self.tmp_path)
Ejemplo n.º 9
0
 def _validate_with_callback(self, key, callback):
     module = import_module("src.path")
     if hasattr(module, callback):
         method = getattr(module, callback)
         self.path = get_exact_folder(key, self.path, method)
         Logger.debug("Path with condition: {} {}".format(
             callback, self.path))
Ejemplo n.º 10
0
    def select(self):
        """Show a select option for the backup of each application."""
        backup_folders = self.get_backup_folders()
        total = len(backup_folders)

        if total != 0:
            backup_folders.sort()

            self._display_choices(backup_folders)
            print(_("(Q)uit to cancel"))

            has_chosen = False
            stopped = False

            while not has_chosen and not stopped:
                try:
                    selected = input("Select a restore date : ")
                    if selected in ["q", "quit", "exit"]:
                        stopped = True
                    selected = int(selected)
                    if 1 <= selected <= total:
                        has_chosen = True
                        self._exists = True
                        self._selected_backup = backup_folders[selected - 1]
                except ValueError:
                    pass
                except KeyboardInterrupt:
                    exit()

            if stopped:
                Logger.debug("The user stopped the "
                             "reversion for {}".format(self.app.name))
            else:
                Logger.debug("No backup folder found for "
                             "the application {0}".format(self.app.name))
Ejemplo n.º 11
0
 def __getattr__(self, name):
     if hasattr(self.parser, name):
         return getattr(self.parser, name)
     elif hasattr(self, name):
         return getattr(self, name)
     Logger.warning("Couldn't find attribute {}".format(name))
     return None
Ejemplo n.º 12
0
 def install_icon(self, icon, icon_path):
     """Install the icon."""
     png_bytes = get_pngbytes(icon)
     if png_bytes:
         icon = ElectronApplication.get_real_path(icon.original)
         self.set_icon(icon, icon_path, png_bytes, True)
     else:
         Logger.error("PNG file was not found.")
Ejemplo n.º 13
0
 def only(self):
     """Return list of apps to be fixed."""
     only = self._args.only
     if only:
         only = only.lower().strip()
         Logger.debug("Arguments/Only: {}".format(only))
         return only.split(",")
     return []
Ejemplo n.º 14
0
 def icon_size():
     """Return the icon size."""
     if DESKTOP_ENV in ("pantheon", "xfce"):
         icon_size = 24
     else:
         icon_size = 22
     Logger.debug("System/Icon Size: {}".format(icon_size))
     return icon_size
Ejemplo n.º 15
0
 def conversion_tool():
     """Return conversion tool set by --conversion-tool."""
     if not ArgumentsConfig._conversion_tool:
         conversion_tool = ArgumentsConfig.args().conversion_tool
         Logger.debug(
             "Arguments/Conversion Tool: {}".format(conversion_tool))
         ArgumentsConfig._conversion_tool = conversion_tool
     return ArgumentsConfig._conversion_tool
Ejemplo n.º 16
0
 def nwjs():
     """Return nwjs sdk path."""
     if not JSONConfig._nwjs:
         nwjs = JSONConfig.get_default().get("nwjs")
         if nwjs and path.exists(nwjs):
             JSONConfig._nwjs = nwjs
             Logger.debug("Config/NWJS SDK: {}".format(nwjs))
     return JSONConfig._nwjs
Ejemplo n.º 17
0
 def get_value(self, key):
     """Get the value of a specific key in the resources list."""
     try:
         return self._resources.get(int(key))
     except KeyError:
         Logger.warning("The key {0} dosen't seem to"
                        " be found on {1}".format(key, self._filename))
         return None
Ejemplo n.º 18
0
 def only():
     """Return list of apps to be fixed."""
     if ArgumentsConfig._only is None:
         only = ArgumentsConfig.args().only
         if only:
             only = only.lower().strip()
             Logger.debug("Arguments/Only: {}".format(only))
             ArgumentsConfig._only = only.split(",")
     return ArgumentsConfig._only
Ejemplo n.º 19
0
 def blacklist():
     """Return a list of blacklist apps."""
     if not JSONConfig._blacklist:
         blacklist = JSONConfig.get_default().get("blacklist", [])
         if blacklist:
             Logger.debug(
                 "Config/Blacklist: {}".format(",".join(blacklist)))
         JSONConfig._blacklist = blacklist
     return JSONConfig._blacklist
Ejemplo n.º 20
0
 def icon_size():
     """Return the icon size."""
     if SystemConfig._icon_size is None:
         if DESKTOP_ENV in ("pantheon", "xfce"):
             icon_size = 24
         else:
             icon_size = 22
         Logger.debug("System/Icon Size: {}".format(icon_size))
         SystemConfig._icon_size = icon_size
     return SystemConfig._icon_size
Ejemplo n.º 21
0
def symlink_file(source, link_name):
    """Symlink a file, remove the dest file if already exists."""
    try:
        symlink(source, link_name)
        mchown(link_name)
    except FileExistsError:
        remove(link_name)
        symlink_file(source, link_name)
    except FileNotFoundError:
        Logger.warning("File not found: {0}".format(source))
Ejemplo n.º 22
0
    def revert_icon(self, icon, icon_path):
        """Revert to the original icon."""
        asar_icon_path = ElectronApplication.get_real_path(icon.original)
        backup_file = "|".join(asar_icon_path.split("/"))

        png_bytes = self.get_backup_file(backup_file)
        if png_bytes:
            self.set_icon(icon.original, icon_path, png_bytes)
        else:
            Logger.error("Backup file of {0} was not found".format(self.name))
Ejemplo n.º 23
0
    def extract(self, icon_path):
        """Extract the zip file in /tmp directory."""

        if path.exists(self.tmp_path):
            rmtree(self.tmp_path)

        Logger.debug("NWJS Application: Extracting of {}".format(self.binary))
        execute([
            "unzip",
            path.join(str(icon_path), self.binary), "-d", self.tmp_path
        ])
Ejemplo n.º 24
0
def get_gnome_scaling_factor():
    """Return gnome scaling factor."""
    source = Gio.SettingsSchemaSource.get_default()
    if source.lookup("org.gnome.desktop.interface", True):
        gsettings = Gio.Settings.new("org.gnome.desktop.interface")
        scaling_factor = gsettings.get_uint('scaling-factor') + 1
        Logger.debug("Scaling Factor/GNOME: {}".format(scaling_factor))
        return scaling_factor
    else:
        Logger.debug("Scaling Factor/Gnome not detected.")
    return 1
Ejemplo n.º 25
0
 def theme():
     """Return a theme object."""
     theme_name = Gtk.Settings.get_default().get_property(
         "gtk-icon-theme-name")
     theme = None
     if theme_name:
         Logger.debug("System/Theme: {}".format(theme_name))
         theme = Theme(theme_name)
     else:
         Logger.error("System/Theme: Not detected.")
     return theme
Ejemplo n.º 26
0
def create_dir(directory):
    """
    Create a directory and fix folder permissions.

    Args :
        folder (str): folder path
    """
    if not path.exists(directory):
        Logger.debug("Creating directory: {}".format(directory))
        makedirs(directory, exist_ok=True)
        mchown(directory)
Ejemplo n.º 27
0
 def theme():
     """Return a theme object."""
     if SystemConfig._theme is None:
         source = Gio.SettingsSchemaSource.get_default()
         if source.lookup("org.gnome.desktop.interface", True):
             gsettings = Gio.Settings.new("org.gnome.desktop.interface")
             theme_name = gsettings.get_string("icon-theme")
             SystemConfig._theme = Theme(theme_name)
             Logger.debug("System/Theme: {}".format(theme_name))
         else:
             Logger.error("System/Theme: Not detected.")
     return SystemConfig._theme
Ejemplo n.º 28
0
 def scaling_factor():
     """
         Returns the scaling factor.
     """
     if not App._scaling_factor:
         scaling_factor = App.get("scaling_factor")
         if scaling_factor and scaling_factor > 1:
             # Change icon size by * it by the scaling factor
             App._icon_size = round(App.icon_size() * scaling_factor, 0)
             Logger.debug("Icon Size: {}".format(App._icon_size))
         App._scaling_factor = scaling_factor
     return App._scaling_factor
Ejemplo n.º 29
0
def detect_de(de_list):
    """Detect the desktop environment, used to choose the proper icons size."""
    try:
        desktop_env = [environ.get("DESKTOP_SESSION").lower(),
                       environ.get("XDG_CURRENT_DESKTOP").lower()]
    except AttributeError:
        desktop_env = []

    for desktop in desktop_env:
        if desktop in de_list:
            Logger.debug("DE: {0}".format(desktop.title()))
            return desktop
    Logger.debug("DE not detected.")
    return "other"
Ejemplo n.º 30
0
def get_cinnamon_scaling_factor():
    """Return Cinnamon desktop scaling factor."""
    source = Gio.SettingsSchemaSource.get_default()
    if source.lookup("org.cinnamon.desktop.interface", True):
        gsettings = Gio.Settings.new("org.cinnamon.desktop.interface")
        scaling_factor = gsettings.get_uint('scaling-factor')
        if scaling_factor == 0:
            # Cinnamon does have an auto scaling feature which we can't use
            scaling_factor = 1
        Logger.debug("Scaling Factor/Cinnamon: {}".format(scaling_factor))
        return scaling_factor
    else:
        Logger.debug("Scaling Factor/Cinnamon not detected")
    return 1