fixes for Python 2 + color

This commit is contained in:
Mathieu Virbel 2014-04-21 01:04:58 +02:00
parent 0669808f19
commit e8483f8c46
3 changed files with 13 additions and 6 deletions

View file

@ -206,7 +206,7 @@ class Buildozer(object):
color = COLOR_SEQ(LOG_LEVELS_C[level])
print(''.join((RESET_SEQ, color, '# ', msg, RESET_SEQ)))
else:
print(LOG_LEVELS_T[level], msg)
print('{} {}'.format(LOG_LEVELS_T[level], msg))
def debug(self, msg):
self.log(2, msg)

View file

@ -6,9 +6,11 @@ This is currently needed to correctly support db between Python 2 and 3.
__all__ = ["JsonStore"]
import io
from json import load, dump
import sys
from json import load, dump, dumps
from os.path import exists
IS_PY3 = sys.version_info[0] >= 3
class JsonStore(object):
@ -44,6 +46,11 @@ class JsonStore(object):
return self.data.keys()
def sync(self):
with io.open(self.filename, 'w', encoding='utf-8') as fd:
dump(self.data, fd)
# http://stackoverflow.com/questions/12309269/write-json-data-to-file-in-python/14870531#14870531
if IS_PY3:
with open(self.filename, 'w') as fd:
dump(self.data, fd, ensure_ascii=False)
else:
with io.open(self.filename, 'w', encoding='utf-8') as fd:
fd.write(unicode(dumps(self.data, ensure_ascii=False)))

View file

@ -616,9 +616,9 @@ class TargetAndroid(Target):
# recreate the project.properties
with io.open(project_fn, 'w', encoding='utf-8') as fd:
for line in content:
fd.write(line)
fd.write(line.decode('utf-8'))
for index, ref in enumerate(references):
fd.write('android.library.reference.{}={}\n'.format(
fd.write(u'android.library.reference.{}={}\n'.format(
index + 1, ref))
self.buildozer.debug('project.properties updated')