Esempio n. 1
0
    def _read(self):
        """Get the theme icon,extensions and size. Save all of that to icon."""
        from HardcodeTray.app import App

        if isinstance(self.icon_data, str):
            orig_icon = theme_icon = self.icon_data
        else:
            orig_icon = self.icon_data["original"]
            theme_icon = self.icon_data["theme"]

        base_name = path.splitext(theme_icon)[0]
        theme = Icon.get_theme(orig_icon)
        theme_icon = theme.lookup_icon(base_name, App.icon_size(), 0)

        if theme_icon:
            self.original = orig_icon
            self.theme = theme_icon.get_filename()
            self.theme_ext = get_extension(self.theme)
            self.orig_ext = get_extension(orig_icon)
            self.icon_size = self.get_icon_size(App.icon_size())
            self._exists = True

            if (not isinstance(self.icon_data, str)
                    and self.icon_data.get("symlinks")):
                symlinks = get_iterated_icons(self.icon_data["symlinks"])
                # Make sure that symlinks have the right extension
                for symlink in symlinks:
                    if not get_extension(symlink):
                        symlink += ".{0}".format(self.theme_ext)
                    self.symlinks.append(symlink)
Esempio n. 2
0
    def _read(self):
        """
            Read the json file and parse it.
        """
        from HardcodeTray.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")
Esempio n. 3
0
    def get_theme(icon_name):
        """Get the theme to be used dark or light."""

        if isinstance(App.theme(), dict):
            is_dark = "dark" in icon_name.lower()
            if is_dark:
                theme = App.theme()["dark"]
            else:
                theme = App.theme()["light"]
        else:
            theme = App.theme()

        return theme
Esempio n. 4
0
    def pack(self, icon_path):
        """Recreate the zip file from the tmp directory."""
        from HardcodeTray.app import App
        nwjs_sdk = App.get("nwjs")
        if nwjs_sdk:
            binary_file = path.join(gettempdir(), 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)
Esempio n. 5
0
    def pack(self, icon_path):
        """Recreate the zip file from the tmp directory."""
        from HardcodeTray.app import App
        nwjs_sdk = App.get("nwjs")
        if nwjs_sdk:
            binary_file = path.join(gettempdir(), 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)
Esempio n. 6
0
def get_pngbytes(icon):
    """Return the pngbytes of a svg/png icon."""
    from HardcodeTray.app import App
    icon_for_replace = icon.theme
    icon_extension = icon.theme_ext
    icon_size = icon.icon_size
    if icon_extension == 'svg':
        if icon_size != App.icon_size():
            png_bytes = App.svg().to_bin(icon_for_replace, App.icon_size())
        else:
            png_bytes = App.svg().to_bin(icon_for_replace)
    elif icon_extension == "png":
        with open(icon_for_replace, 'rb') as png_file:
            png_bytes = png_file.read()
    else:
        png_bytes = None
    return png_bytes
Esempio n. 7
0
def get_pngbytes(icon):
    """Return the pngbytes of a svg/png icon."""
    from HardcodeTray.app import App
    icon_for_replace = icon.theme
    icon_extension = icon.theme_ext
    icon_size = icon.icon_size
    if icon_extension == 'svg':
        if icon_size != App.icon_size():
            png_bytes = App.svg().to_bin(icon_for_replace,
                                         App.icon_size())
        else:
            png_bytes = App.svg().to_bin(icon_for_replace)
    elif icon_extension == "png":
        with open(icon_for_replace, 'rb') as png_file:
            png_bytes = png_file.read()
    else:
        png_bytes = None
    return png_bytes
Esempio n. 8
0
    def wrapper(app):
        """
        Create backup file and apply the modifications.
        """
        from HardcodeTray.app import App
        if not app.backup_ignore and not App.get("backup_ignore"):
            app.backup.create_backup_dir()

        app.install_symlinks()
        func(app)
    def wrapper(app):
        """
        Create backup file and apply the modifications.
        """
        from HardcodeTray.app import App
        if not app.backup_ignore and not App.get("backup_ignore"):
            app.backup.create_backup_dir()

        app.install_symlinks()
        func(app)
Esempio n. 10
0
    def install_icon(self, icon, icon_path):
        """Install the icon."""
        icon.icon_size = App.icon_size()

        png_bytes = get_pngbytes(icon)

        if png_bytes:
            # Read a target file
            asar = AsarFile(path.join(str(icon_path), self.binary))
            target = B64ElectronApplication.get_real_path(self.file)
            file_content = asar.read_file(target).decode()
            # Create new base64 binary file
            base64_icon = b64encode(App.svg().to_bin(icon.theme, icon.icon_size, icon.icon_size))
            # Build new icon
            new_icon = "data:image/png;base64," + base64_icon.decode()
            # Replace the original icon with newly built one
            file_content = file_content.replace(icon.original, new_icon)
            bytes = file_content.encode()
            self.set_icon(target, icon_path, bytes, True)
        else:
            Logger.error("Icon file was not found.")
Esempio n. 11
0
    def create(self, filename):
        """Backup functions."""
        from HardcodeTray.app import App

        if not App.get('backup_ignore'):
            if not self.backup_dir:
                self.create_backup_dir()

            backup_file = path.join(self.backup_dir, path.basename(filename))

            if path.exists(filename):
                Logger.debug("Backup file: {0} to: {1}".format(
                    filename, backup_file))
                copy_file(filename, backup_file, True)
Esempio n. 12
0
 def wrapper(app):
     """
         Revert to the old version and remove symlinks.
     """
     from HardcodeTray.app import App
     if app.BACKUP_IGNORE or app.backup_ignore or App.get("backup_ignore"):
         app.remove_symlinks()
         func(app)
     else:
         app.backup.select()
         if app.backup.selected_backup:
             app.remove_symlinks()
             func(app)
         else:
             app.success = False
Esempio n. 13
0
    def create(self, filename):
        """Backup functions."""
        from HardcodeTray.app import App

        if not App.get("backup_ignore"):
            if not self.backup_dir:
                self.create_backup_dir()

            backup_file = path.join(self.backup_dir,
                                    path.basename(filename))

            if path.exists(filename):
                Logger.debug("Backup file: {0} to: {1}".format(filename,
                                                               backup_file))
                copy_file(filename, backup_file, True)
Esempio n. 14
0
 def wrapper(app):
     """
         Revert to the old version and remove symlinks.
     """
     from HardcodeTray.app import App
     if app.BACKUP_IGNORE or app.backup_ignore or App.get("backup_ignore"):
         app.remove_symlinks()
         func(app)
     else:
         app.backup.select()
         if app.backup.selected_backup:
             app.remove_symlinks()
             func(app)
         else:
             app.success = False
Esempio n. 15
0
    def _validate(self):
        """Check whether a folder path exists or not."""

        Path.DB_VARIABLES["{size}"] = str(App.icon_size())

        for key, value in Path.DB_VARIABLES.items():
            if key in self.path:
                # Check whether it's a function or not
                if value.endswith("_callback"):
                    self._validate_with_callback(key, value)
                else:
                    self.path = self.path.replace(key, str(value))

        if self.parser.script and self.type == "icons_path":
            binary_file = path.join(self.path, self.parser.binary)
            self._exists = path.exists(self.path) and path.exists(binary_file)
        else:
            self._exists = path.exists(self.path)
Esempio n. 16
0
    def _validate(self):
        """
            Check wether a folder path exists or not.
        """
        from HardcodeTray.app import App

        Path.DB_VARIABLES["{size}"] = str(App.icon_size())

        for key, value in Path.DB_VARIABLES.items():
            if key in self.path:
                if value.endswith("_callback"):  # Check wether it's a function or not
                    self._validate_with_callback(key, value)
                else:
                    self.path = self.path.replace(key, str(value))

        if self.parser.script and self.type == "icons_path":
            binary_file = path.join(self.path, self.parser.binary)
            self._exists = path.exists(self.path) and path.exists(binary_file)
        else:
            self._exists = path.exists(self.path)
Esempio n. 17
0
    def install_icon(self, icon, icon_path):
        """Install icon to the current directory."""
        ext_orig = icon.orig_ext
        theme_icon = icon.theme
        ext_theme = icon.theme_ext
        icon_size = icon.icon_size
        output_icon = path.join(str(icon_path), icon.original)

        # Backup the output_icon
        if not self.backup_ignore:
            self.backup.create(output_icon)

        if ext_theme == ext_orig and theme_icon != output_icon:
            symlink_file(theme_icon, output_icon)
        elif ext_theme == "svg" and ext_orig == "png":
            from HardcodeTray.app import App
            if icon_size != App.icon_size():
                App.svg().to_png(theme_icon, output_icon, App.icon_size())
            else:
                App.svg().to_png(theme_icon, output_icon)
Esempio n. 18
0
    def install_icon(self, icon, icon_path):
        """Install icon to the current directory."""
        ext_orig = icon.orig_ext
        theme_icon = icon.theme
        ext_theme = icon.theme_ext
        icon_size = icon.icon_size
        output_icon = path.join(str(icon_path), icon.original)

        # Backup the output_icon
        if not self.backup_ignore:
            self.backup.create(output_icon)

        if ext_theme == ext_orig and theme_icon != output_icon:
            symlink_file(theme_icon, output_icon)
        elif ext_theme == "svg" and ext_orig == "png":
            from HardcodeTray.app import App
            if icon_size != App.icon_size():
                App.svg().to_png(theme_icon, output_icon, App.icon_size())
            else:
                App.svg().to_png(theme_icon, output_icon)