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