encoding fix
This commit is contained in:
parent
50a0850c6e
commit
9335892183
@ -8,6 +8,7 @@ from profile import tox_factory
|
|||||||
from callbacks import init_callbacks
|
from callbacks import init_callbacks
|
||||||
from util import curr_directory, get_style
|
from util import curr_directory, get_style
|
||||||
import styles.style
|
import styles.style
|
||||||
|
import locale
|
||||||
|
|
||||||
|
|
||||||
class Toxygen(object):
|
class Toxygen(object):
|
||||||
@ -68,6 +69,7 @@ class Toxygen(object):
|
|||||||
self.tox = tox_factory(data, settings)
|
self.tox = tox_factory(data, settings)
|
||||||
else:
|
else:
|
||||||
path, name = auto_profile
|
path, name = auto_profile
|
||||||
|
path = path.encode(locale.getpreferredencoding())
|
||||||
data = ProfileHelper.open_profile(path, name)
|
data = ProfileHelper.open_profile(path, name)
|
||||||
settings = Settings(name)
|
settings = Settings(name)
|
||||||
self.tox = tox_factory(data, settings)
|
self.tox = tox_factory(data, settings)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from platform import system
|
from platform import system
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import locale
|
||||||
from util import Singleton, curr_directory
|
from util import Singleton, curr_directory
|
||||||
|
|
||||||
|
|
||||||
@ -25,14 +26,14 @@ class Settings(Singleton, dict):
|
|||||||
data = fl.read()
|
data = fl.read()
|
||||||
auto = json.loads(data)
|
auto = json.loads(data)
|
||||||
if 'path' in auto and 'name' in auto:
|
if 'path' in auto and 'name' in auto:
|
||||||
return auto['path'], auto['name']
|
return unicode(auto['path']), unicode(auto['name'])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_auto_profile(path, name):
|
def set_auto_profile(path, name):
|
||||||
p = Settings.get_default_path() + 'toxygen.json'
|
p = Settings.get_default_path() + 'toxygen.json'
|
||||||
data = json.dumps({'path': path, 'name': name})
|
data = json.dumps({'path': unicode(path.decode(locale.getpreferredencoding())), 'name': unicode(name)})
|
||||||
with open(p, 'w') as fl:
|
with open(p, 'w') as fl:
|
||||||
fl.write(data)
|
fl.write(data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_default_settings():
|
def get_default_settings():
|
||||||
@ -78,7 +79,7 @@ class Settings(Singleton, dict):
|
|||||||
with open(path) as fl:
|
with open(path) as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
app_settings = json.loads(data)
|
app_settings = json.loads(data)
|
||||||
app_settings['active_profile'].remove(ProfileHelper.get_path() + self.name + '.tox')
|
app_settings['active_profile'].remove(unicode(ProfileHelper.get_path() + self.name + '.tox'))
|
||||||
data = json.dumps(app_settings)
|
data = json.dumps(app_settings)
|
||||||
with open(path, 'w') as fl:
|
with open(path, 'w') as fl:
|
||||||
fl.write(data)
|
fl.write(data)
|
||||||
@ -93,7 +94,8 @@ class Settings(Singleton, dict):
|
|||||||
app_settings = {}
|
app_settings = {}
|
||||||
if 'active_profile' not in app_settings:
|
if 'active_profile' not in app_settings:
|
||||||
app_settings['active_profile'] = []
|
app_settings['active_profile'] = []
|
||||||
app_settings['active_profile'].append(ProfileHelper.get_path() + str(self.name) + '.tox')
|
profile_path = ProfileHelper.get_path()
|
||||||
|
app_settings['active_profile'].append(unicode(profile_path + str(self.name) + '.tox'))
|
||||||
data = json.dumps(app_settings)
|
data = json.dumps(app_settings)
|
||||||
with open(path, 'w') as fl:
|
with open(path, 'w') as fl:
|
||||||
fl.write(data)
|
fl.write(data)
|
||||||
@ -136,7 +138,7 @@ class ProfileHelper(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_active_profile(path, name):
|
def is_active_profile(path, name):
|
||||||
path = path + name + '.tox'
|
path = path.decode(locale.getpreferredencoding()) + name + '.tox'
|
||||||
settings = Settings.get_default_path() + 'toxygen.json'
|
settings = Settings.get_default_path() + 'toxygen.json'
|
||||||
if os.path.isfile(settings):
|
if os.path.isfile(settings):
|
||||||
with open(settings) as fl:
|
with open(settings) as fl:
|
||||||
@ -149,15 +151,15 @@ class ProfileHelper(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def open_profile(path, name):
|
def open_profile(path, name):
|
||||||
|
path = path.decode(locale.getpreferredencoding())
|
||||||
ProfileHelper._path = path + name + '.tox'
|
ProfileHelper._path = path + name + '.tox'
|
||||||
ProfileHelper._directory = path
|
ProfileHelper._directory = path
|
||||||
with open(ProfileHelper._path, 'rb') as fl:
|
with open(ProfileHelper._path, 'rb') as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
if data:
|
if data:
|
||||||
print 'Data loaded from: {}'.format(ProfileHelper._path)
|
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
raise IOError('Save file not found. Path: {}'.format(ProfileHelper._path))
|
raise IOError('Save file has zero size!')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def save_profile(data, name=None):
|
def save_profile(data, name=None):
|
||||||
@ -166,7 +168,6 @@ class ProfileHelper(object):
|
|||||||
ProfileHelper._directory = Settings.get_default_path()
|
ProfileHelper._directory = Settings.get_default_path()
|
||||||
with open(ProfileHelper._path, 'wb') as fl:
|
with open(ProfileHelper._path, 'wb') as fl:
|
||||||
fl.write(data)
|
fl.write(data)
|
||||||
print 'Data saved to: {}'.format(ProfileHelper._path)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def export_profile(new_path):
|
def export_profile(new_path):
|
||||||
@ -180,4 +181,3 @@ class ProfileHelper(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_path():
|
def get_path():
|
||||||
return ProfileHelper._directory
|
return ProfileHelper._directory
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user