summaryrefslogtreecommitdiffstats
path: root/py3status/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'py3status/__init__.py')
-rwxr-xr-xpy3status/__init__.py102
1 files changed, 93 insertions, 9 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py
index 4bad6bd..e453cda 100755
--- a/py3status/__init__.py
+++ b/py3status/__init__.py
@@ -549,7 +549,8 @@ class Module(Thread):
if self.config['debug']:
syslog(
LOG_INFO,
- 'method {} returned {}'.format(meth, result)
+ 'method {} returned {} '.format(meth, result) +
+ 'for position {}'.format(position)
)
except Exception:
err = sys.exc_info()[1]
@@ -597,6 +598,14 @@ class Py3statusWrapper():
'interval': 1
}
+ # package version
+ try:
+ import pkg_resources
+ version = pkg_resources.get_distribution('py3status').version
+ except:
+ version = 'unknown'
+ config['version'] = version
+
# command line options
parser = argparse.ArgumentParser(
description='The agile, python-powered, i3status wrapper')
@@ -625,8 +634,21 @@ class Py3statusWrapper():
default=config['cache_timeout'],
help="""default injection cache timeout in seconds
(default 60 sec)""")
+ parser.add_argument('-v', '--version', action="store_true",
+ help="""show py3status version and exit""")
options = parser.parse_args()
+ # only asked for version
+ if options.version:
+ from platform import python_version
+ print(
+ 'py3status version {} (python {})'.format(
+ config['version'],
+ python_version()
+ )
+ )
+ sys.exit(0)
+
# override configuration and helper variables
config['cache_timeout'] = options.cache_timeout
config['debug'] = options.debug
@@ -699,8 +721,9 @@ class Py3statusWrapper():
syslog(LOG_INFO, 'events thread started')
# suppress modules' ouput wrt issue #20
- sys.stdout = open('/dev/null', 'w')
- sys.stderr = open('/dev/null', 'w')
+ if not self.config['debug']:
+ sys.stdout = open('/dev/null', 'w')
+ sys.stderr = open('/dev/null', 'w')
# load and spawn modules threads
for include_path, f_name in self.list_modules():
@@ -777,27 +800,88 @@ class Py3statusWrapper():
"""
# prepopulate the list so that every usable index exists, thx @Lujeni
m_list = [
- '' for value in range(sum([len(x.methods) for x in self.modules]))
+ '' for value in range(
+ sum([len(x.methods) for x in self.modules]) + len(json_list)
+ )
]
- # append i3status json list to the modules' list
- m_list += json_list
+
+ # debug the ordering matrix
+ if self.config['debug']:
+ syslog(
+ LOG_INFO,
+ 'ordering matrix {}'.format(list(range(len(m_list))))
+ )
+
# run through modules/methods output and insert them in reverse order
+ debug_msg = ''
for m in reversed(self.modules):
for meth in m.methods:
position = m.methods[meth]['position']
last_output = m.methods[meth]['last_output']
try:
+ assert position in range(len(m_list))
if m_list[position] == '':
m_list[position] = last_output
else:
if '' in m_list:
m_list.remove('')
m_list.insert(position, last_output)
- except IndexError:
+ except (AssertionError, IndexError):
# out of range indexes get placed at the end of the output
m_list.append(last_output)
- # cleanup and return output list
- m_list = list(filter(lambda a: a != '', m_list))
+ finally:
+ # debug user module's index
+ if self.config['debug']:
+ debug_msg += '{}={} '.format(
+ meth,
+ m_list.index(last_output)
+ )
+
+ # debug the user modules ordering
+ if self.config['debug']:
+ syslog(
+ LOG_INFO,
+ 'ordering user modules positions {}'.format(debug_msg.strip())
+ )
+
+ # append i3status json list to the modules' list in empty slots
+ debug_msg = ''
+ for i3s_json in json_list:
+ for i in range(len(m_list)):
+ if m_list[i] == '':
+ m_list[i] = i3s_json
+ break
+ else:
+ # this should not happen !
+ m_list.append(i3s_json)
+
+ # debug i3status module's index
+ if self.config['debug']:
+ debug_msg += '{}={} '.format(
+ i3s_json['name'],
+ m_list.index(i3s_json)
+ )
+
+ # debug i3status modules ordering
+ if self.config['debug']:
+ syslog(
+ LOG_INFO,
+ 'ordering i3status modules positions {}'.format(
+ debug_msg.strip()
+ )
+ )
+
+ # cleanup and return output list, we also remove empty outputs
+ m_list = list(filter(lambda a: a != '' and a['full_text'], m_list))
+
+ # log the final ordering in debug mode
+ if self.config['debug']:
+ syslog(
+ LOG_INFO,
+ 'ordering result {}'.format([m['name'] for m in m_list])
+ )
+
+ # return the ordered result
return m_list
def run(self):