diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index 4bbc9ca..8f740c9 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -5,6 +5,7 @@ import sys from .core import util, io from .core.modules import * from .core.settings import SettingsBase +from .core.config import ConfigFinder __all__ = [ "SettingsBase", @@ -12,6 +13,9 @@ __all__ = [ "Status", "I3statusHandler", ] +def main(): + ConfigFinder().run_config() + class Status: def __init__(self, standalone=False, interval=1, input_stream=sys.stdin): if standalone: diff --git a/i3pystatus/core/config.py b/i3pystatus/core/config.py new file mode 100644 index 0000000..c3ec4fe --- /dev/null +++ b/i3pystatus/core/config.py @@ -0,0 +1,43 @@ + +import os +import os.path +import runpy + +SEARCHPATH = ( + "~/.i3pystatus.py", + "~/.i3/i3pystatus.py", + "~/.config/i3pystatus.py", + "$XDG_CONFIG_HOME/i3pystatus.py", + "/etc/i3pystatus.py", + "/etc/xdg/i3pystatus.py", + "$XDG_CONFIG_DIRS/i3pystatus.py", +) + +class ConfigFinder: + def __init__(self, searchpath=SEARCHPATH): + self.searchpath = searchpath + + @staticmethod + def expand(path): + return os.path.expandvars(os.path.expanduser(path)) + + @staticmethod + def exists(path): + return os.path.isfile(path) + + def get_config_path(self): + failed = [] + for path in map(self.expand, self.searchpath): + if self.exists(path): + return failed, path + else: + failed.append(path) + + return failed, None + + def run_config(self): + failed, path = self.get_config_path() + if path: + runpy.run_path(path, run_name="i3pystatus._config") + else: + raise ImportError("Didn't find a config module, tried\n {mods}".format(mods="\n".join(failed))) diff --git a/setup.py b/setup.py index aeba4c6..1be0468 100755 --- a/setup.py +++ b/setup.py @@ -21,9 +21,9 @@ setup(name="i3pystatus", "console_scripts": ["i3pystatus = i3pystatus:main"], }, - install_requires=[ - "gobject", - ], +# install_requires=[ + # "gobject", + # ], # install_requires=[ # "Jinja2", # "lxml",