Better error handling
This commit is contained in:
parent
c44dea5228
commit
257307fbc1
1 changed files with 11 additions and 6 deletions
|
@ -25,7 +25,10 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
|
||||||
# Some xdg data
|
# Some xdg data
|
||||||
self.home = os.environ.get('HOME')
|
self.home = os.environ.get('HOME')
|
||||||
self.base_dirs = []
|
self.base_dirs = []
|
||||||
pos_dirs = os.environ.get('XDG_DATA_DIRS').split(":")
|
xdg_dirs = os.environ.get('XDG_DATA_DIRS')
|
||||||
|
pos_dirs = []
|
||||||
|
if xdg_dirs:
|
||||||
|
pos_dirs = xdg_dirs.split(":")
|
||||||
if not pos_dirs:
|
if not pos_dirs:
|
||||||
pos_dirs = [
|
pos_dirs = [
|
||||||
"/usr/share", "/usr/local/share", self.home + "/.local/share",
|
"/usr/share", "/usr/local/share", self.home + "/.local/share",
|
||||||
|
@ -99,18 +102,17 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
|
||||||
def get_desktop_file(self, command):
|
def get_desktop_file(self, command):
|
||||||
"""From here we return first dektopfile"""
|
"""From here we return first dektopfile"""
|
||||||
desktop_file = None
|
desktop_file = None
|
||||||
for base_dir in [
|
for base_dir in self.base_dirs:
|
||||||
directory for directory in self.base_dirs if directory
|
|
||||||
]:
|
|
||||||
directory = base_dir + "/applications"
|
directory = base_dir + "/applications"
|
||||||
if os.path.exists(directory):
|
if os.path.exists(directory):
|
||||||
command = "grep -l {} {}/*.desktop".format(command, directory)
|
command = "grep -s -l {} {}/*.desktop".format(command, directory)
|
||||||
process = subprocess.Popen(command,
|
process = subprocess.Popen(command,
|
||||||
shell=True,
|
shell=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
for data in [i for i in process.communicate() if i]:
|
for data in [i for i in process.communicate() if i]:
|
||||||
for result in data.decode().split('\n'):
|
for result in data.decode().split('\n'):
|
||||||
|
print(result)
|
||||||
desktop_file = result
|
desktop_file = result
|
||||||
break
|
break
|
||||||
return desktop_file
|
return desktop_file
|
||||||
|
@ -123,7 +125,10 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
for data in [i.rstrip() for i in process.communicate() if i]:
|
for data in [i.rstrip() for i in process.communicate() if i]:
|
||||||
|
try:
|
||||||
icon_name = data.decode().split('=')[1]
|
icon_name = data.decode().split('=')[1]
|
||||||
|
except IndexError:
|
||||||
|
return ""
|
||||||
# Find icon dirs
|
# Find icon dirs
|
||||||
icon_dirs = []
|
icon_dirs = []
|
||||||
for base_dir in [
|
for base_dir in [
|
||||||
|
|
Loading…
Add table
Reference in a new issue