Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
0
def symlink_file(source, link_name):
    """Symlink a file, remove the dest file if already exists."""
    try:
        symlink(source, link_name)
    except FileExistsError:
        remove(link_name)
        symlink_file(source, link_name)
    except FileNotFoundError:
        Logger.warning("File not found: {0}".format(source))
Ejemplo n.º 6
0
def symlink_file(source, link_name):
    """Symlink a file, remove the dest file if already exists."""
    try:
        symlink(source, link_name)
    except FileExistsError:
        remove(link_name)
        symlink_file(source, link_name)
    except FileNotFoundError:
        Logger.warning("File not found: {0}".format(source))
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 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.")
Ejemplo n.º 10
0
 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.")
Ejemplo n.º 11
0
    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))
Ejemplo n.º 12
0
    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))