#5: Support for real config files
This commit is contained in:
parent
ae4eefdffa
commit
93bfab1d7b
@ -5,6 +5,7 @@ import sys
|
|||||||
from .core import util, io
|
from .core import util, io
|
||||||
from .core.modules import *
|
from .core.modules import *
|
||||||
from .core.settings import SettingsBase
|
from .core.settings import SettingsBase
|
||||||
|
from .core.config import ConfigFinder
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"SettingsBase",
|
"SettingsBase",
|
||||||
@ -12,6 +13,9 @@ __all__ = [
|
|||||||
"Status", "I3statusHandler",
|
"Status", "I3statusHandler",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ConfigFinder().run_config()
|
||||||
|
|
||||||
class Status:
|
class Status:
|
||||||
def __init__(self, standalone=False, interval=1, input_stream=sys.stdin):
|
def __init__(self, standalone=False, interval=1, input_stream=sys.stdin):
|
||||||
if standalone:
|
if standalone:
|
||||||
|
43
i3pystatus/core/config.py
Normal file
43
i3pystatus/core/config.py
Normal file
@ -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)))
|
6
setup.py
6
setup.py
@ -21,9 +21,9 @@ setup(name="i3pystatus",
|
|||||||
"console_scripts": ["i3pystatus = i3pystatus:main"],
|
"console_scripts": ["i3pystatus = i3pystatus:main"],
|
||||||
},
|
},
|
||||||
|
|
||||||
install_requires=[
|
# install_requires=[
|
||||||
"gobject",
|
# "gobject",
|
||||||
],
|
# ],
|
||||||
# install_requires=[
|
# install_requires=[
|
||||||
# "Jinja2",
|
# "Jinja2",
|
||||||
# "lxml",
|
# "lxml",
|
||||||
|
Loading…
Reference in New Issue
Block a user