コード例 #1
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
コード例 #2
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))
コード例 #3
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
コード例 #4
0
ファイル: utils.py プロジェクト: Jacobtey/Hardcode-Tray
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))
コード例 #5
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
コード例 #6
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.")
コード例 #7
0
ファイル: cjson.py プロジェクト: kmyi/Hardcode-Tray
 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
コード例 #8
0
ファイル: pak.py プロジェクト: kmyi/Hardcode-Tray
    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))
コード例 #9
0
ファイル: cjson.py プロジェクト: kmyi/Hardcode-Tray
 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