Ejemplo n.º 1
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.º 2
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)

            execute(["npm", "install"], True, True, self.tmp_path)

            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")

            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.º 3
0
    def create(self, filename):
        """Backup functions."""
        from src.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)
                mchown(backup_file)
Ejemplo n.º 4
0
if (not DESKTOP_ENV or DESKTOP_ENV == "other") and not App.icon_size():
    exit(_("You need to run the script using 'sudo -E'.\nPlease try again"))

print(_("Welcome to Hardcode-Tray!"))
print(_("Desktop Environment: {}").format(DESKTOP_ENV.title()))
print(_("Scaling Factor: {}").format(App.scaling_factor()))
print(_("Icon Size: {}").format(App.icon_size()))
if not isinstance(App.theme(), dict):
    print(_("Icon Theme: {}").format(App.theme()))
else:
    print(_("Dark Icon Theme: {}").format(App.theme("dark")))
    print(_("Light Icon Theme: {}").format(App.theme("light")))
print(_("Conversion Tool: {}").format(App.svg()))
print(_("To Do: "), end="")
print(", ".join(map(lambda x: x.title(), App.get("only")))
      if App.get("only") else _("All"))


action = App.get("action")
if action == Action.APPLY:
    print(_("Applying now.."))
elif action == Action.REVERT:
    print(_("Reverting now.."))
elif action == Action.CLEAR_CACHE:
    print(_("Clearing cache..."))
print("\n")
App.execute()

print(_("\nDone, Thank you for using the Hardcode-Tray fixer!"))