summaryrefslogtreecommitdiffstats
path: root/py3status
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2014-12-21 21:06:21 +0100
committerUltrabug <ultrabug@gentoo.org>2014-12-21 21:06:21 +0100
commit0404dd070ceda03937aad3116c76955e513373ca (patch)
tree831f8daf69aedb6723344b6af496e3011fc0d7fd /py3status
parent388e4a7450fd8519b83a5d7bc8e4e9554e33ae05 (diff)
python3 compatibility code for i3status tmp config generation
Diffstat (limited to 'py3status')
-rwxr-xr-xpy3status/__init__.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py
index 04a5d06..9a9a484 100755
--- a/py3status/__init__.py
+++ b/py3status/__init__.py
@@ -293,6 +293,16 @@ class I3status(Thread):
ordered.append(j)
return ordered
+ @staticmethod
+ def write_in_tmpfile(text, tmpfile):
+ """
+ Write the given text in the given tmpfile in python2 and python3.
+ """
+ try:
+ tmpfile.write(text)
+ except TypeError:
+ tmpfile.write(str.encode(text))
+
def write_tmp_i3status_config(self, tmpfile):
"""
Given a temporary file descriptor, write a valid i3status config file
@@ -304,13 +314,19 @@ class I3status(Thread):
elif section_name == 'order':
for module_name in conf:
if self.valid_config_param(module_name):
- tmpfile.write('order += "%s"\n' % module_name)
- tmpfile.write('\n')
+ self.write_in_tmpfile(
+ 'order += "%s"\n' % module_name,
+ tmpfile
+ )
+ self.write_in_tmpfile('\n', tmpfile)
elif self.valid_config_param(section_name):
- tmpfile.write('%s {\n' % section_name)
+ self.write_in_tmpfile('%s {\n' % section_name, tmpfile)
for key, value in conf.items():
- tmpfile.write(' %s = "%s"\n' % (key, value))
- tmpfile.write('}\n\n')
+ self.write_in_tmpfile(
+ ' %s = "%s"\n' % (key, value),
+ tmpfile
+ )
+ self.write_in_tmpfile('}\n\n', tmpfile)
tmpfile.flush()
def run(self):