make setting_util zip_safe and location-independent
This commit is contained in:
parent
db88ea7a72
commit
f5598b8b7c
@ -17,6 +17,7 @@ mkdir ${BUILD}/test-install ${BUILD}/test-install-bin
|
|||||||
PYTHONPATH=${BUILD}/test-install python3 setup.py --quiet install --install-lib ${BUILD}/test-install --install-scripts ${BUILD}/test-install-bin
|
PYTHONPATH=${BUILD}/test-install python3 setup.py --quiet install --install-lib ${BUILD}/test-install --install-scripts ${BUILD}/test-install-bin
|
||||||
|
|
||||||
test -f ${BUILD}/test-install-bin/i3pystatus
|
test -f ${BUILD}/test-install-bin/i3pystatus
|
||||||
|
test -f ${BUILD}/test-install-bin/i3pystatus-setting-util
|
||||||
|
|
||||||
PYTHONPATH=${BUILD}/test-install py.test --junitxml ${BUILD}/testlog.xml tests
|
PYTHONPATH=${BUILD}/test-install py.test --junitxml ${BUILD}/testlog.xml tests
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import i3pystatus.core.modules
|
|||||||
from i3pystatus.core.imputil import ClassFinder
|
from i3pystatus.core.imputil import ClassFinder
|
||||||
from i3pystatus.core.color import ColorRangeModule
|
from i3pystatus.core.color import ColorRangeModule
|
||||||
|
|
||||||
IGNORE_MODULES = ("__main__", "core")
|
IGNORE_MODULES = ("__main__", "core", "tools")
|
||||||
|
|
||||||
|
|
||||||
def is_module(obj):
|
def is_module(obj):
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#!/usr/bin/env python
|
|
||||||
import glob
|
import glob
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
import getpass
|
import getpass
|
||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
|
import pkgutil
|
||||||
from collections import defaultdict, OrderedDict
|
from collections import defaultdict, OrderedDict
|
||||||
|
|
||||||
import keyring
|
import keyring
|
||||||
|
|
||||||
|
import i3pystatus
|
||||||
from i3pystatus import Module, SettingsBase
|
from i3pystatus import Module, SettingsBase
|
||||||
from i3pystatus.core import ClassFinder
|
from i3pystatus.core import ClassFinder
|
||||||
|
|
||||||
@ -34,10 +35,6 @@ def get_int_in_range(prompt, _range):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
print("Invalid input!")
|
print("Invalid input!")
|
||||||
|
|
||||||
modules = [os.path.basename(m.replace('.py', ''))
|
|
||||||
for m in glob.glob(os.path.join(os.path.dirname(__file__), "i3pystatus", "*.py"))
|
|
||||||
if not os.path.basename(m).startswith('_')]
|
|
||||||
|
|
||||||
|
|
||||||
def enumerate_choices(choices):
|
def enumerate_choices(choices):
|
||||||
lines = []
|
lines = []
|
||||||
@ -46,12 +43,21 @@ def enumerate_choices(choices):
|
|||||||
return "".join(lines)
|
return "".join(lines)
|
||||||
|
|
||||||
|
|
||||||
protected_settings = SettingsBase._SettingsBase__PROTECTED_SETTINGS
|
def get_modules():
|
||||||
class_finder = ClassFinder(Module)
|
for importer, modname, ispkg in pkgutil.iter_modules(i3pystatus.__path__):
|
||||||
credential_modules = defaultdict(dict)
|
if modname not in ["core", "tools"]:
|
||||||
for module_name in modules:
|
yield modname
|
||||||
try:
|
|
||||||
module = class_finder.get_module(module_name)
|
|
||||||
|
def get_credential_modules():
|
||||||
|
protected_settings = SettingsBase._SettingsBase__PROTECTED_SETTINGS
|
||||||
|
class_finder = ClassFinder(Module)
|
||||||
|
credential_modules = defaultdict(dict)
|
||||||
|
for module_name in get_modules():
|
||||||
|
try:
|
||||||
|
module = class_finder.get_module(module_name)
|
||||||
|
except ImportError:
|
||||||
|
continue
|
||||||
clazz = class_finder.get_class(module)
|
clazz = class_finder.get_class(module)
|
||||||
members = [m[0] for m in inspect.getmembers(clazz) if not m[0].startswith('_')]
|
members = [m[0] for m in inspect.getmembers(clazz) if not m[0].startswith('_')]
|
||||||
if any([hasattr(clazz, setting) for setting in protected_settings]):
|
if any([hasattr(clazz, setting) for setting in protected_settings]):
|
||||||
@ -66,9 +72,7 @@ for module_name in modules:
|
|||||||
if protected:
|
if protected:
|
||||||
credential_modules[clazz.__name__]['credentials'] = protected
|
credential_modules[clazz.__name__]['credentials'] = protected
|
||||||
credential_modules[clazz.__name__]['key'] = "%s.%s" % (clazz.__module__, clazz.__name__)
|
credential_modules[clazz.__name__]['key'] = "%s.%s" % (clazz.__module__, clazz.__name__)
|
||||||
|
return credential_modules
|
||||||
except ImportError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -78,7 +82,9 @@ def main():
|
|||||||
This allows you to edit keyring-protected settings of
|
This allows you to edit keyring-protected settings of
|
||||||
i3pystatus modules, which are stored globally (independent
|
i3pystatus modules, which are stored globally (independent
|
||||||
of your i3pystatus configuration) in your keyring.
|
of your i3pystatus configuration) in your keyring.
|
||||||
""" % os.path.baename(sys.argv[0]))
|
""" % os.path.basename(sys.argv[0]))
|
||||||
|
|
||||||
|
credential_modules = get_credential_modules()
|
||||||
|
|
||||||
choices = list(credential_modules.keys())
|
choices = list(credential_modules.keys())
|
||||||
prompt = "Choose a module to edit:\n"
|
prompt = "Choose a module to edit:\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user