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
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))
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
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))
def icon_size(self): """Return the icon size in the config file.""" icon_size = None if self.icons: icon_size = self.icons.get("size") Logger.debug("Config/Icon Size: {}".format(icon_size)) if icon_size not in ICONS_SIZE: Logger.warning("Config/Icon Size: Incorrect.") Logger.debug("Config/Icon Size: Detected icon " "size will be used.") return icon_size
def _read(self): """Read the config file.""" if path.isfile(CONFIG_FILE): Logger.debug("Reading config file: {}".format(CONFIG_FILE)) with open(CONFIG_FILE, 'r') as data: try: config = load(data) for key, value in config.items(): setattr(self, "_" + key, value) except ValueError: Logger.warning("The config file is " "not a valid json file.") else: Logger.debug("Config file: Not found.")
def icon_size(): """Return the icon size in the config file.""" if JSONConfig._icon_size is None: json = JSONConfig.get_default() icons = json.get("icons") if icons: icon_size = icons.get("size") Logger.debug("Config/Icon Size: {}".format(icon_size)) if icon_size not in ICONS_SIZE: Logger.warning("Config/Icon Size: Incorrect.") Logger.debug( "Config/Icon Size: Detected icon size will be used.") JSONConfig._icon_size = icon_size return JSONConfig._icon_size
def set_icon(self, icon, icon_path, pngbytes, backup=False): """Update the icon bytes with the new one.""" self.set_binary_file(path.join(str(icon_path), self.binary)) if self.pak: icon_name = icon.original if pngbytes and self.pak.haskey(icon_name): if backup: self.backup.file(icon_name, self.pak.get_value(icon_name)) self.pak.set_value(icon_name, pngbytes) self.pak.write() else: Logger.error("Couldn't find a PNG file.") else: Logger.warning("The file {0} was not found".format( self.binary_file))
def get_default(): """Return default instance.""" if JSONConfig._config is None: config = {} if path.isfile(CONFIG_FILE): Logger.debug("Reading config file: {}".format(CONFIG_FILE)) with open(CONFIG_FILE, 'r') as data: try: config = load(data) except ValueError: Logger.warning("The config file is " "not a valid json file.") else: Logger.debug("Config file: Not found.") JSONConfig._config = config return JSONConfig._config