Ported to Python 3
This commit is contained in:
20
settings.py
20
settings.py
@@ -1,24 +1,28 @@
|
||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||
import json
|
||||
import os
|
||||
import locale
|
||||
from util import Singleton, curr_directory
|
||||
from toxcore_enums_and_consts import *
|
||||
from wrapper.toxcore_enums_and_consts import *
|
||||
|
||||
global LOG
|
||||
import logging
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
class Settings(Singleton, dict):
|
||||
|
||||
def __init__(self):
|
||||
self.path = curr_directory() + '/settings.json'
|
||||
self.path = os.path.join(curr_directory(), 'settings.json')
|
||||
if os.path.isfile(self.path):
|
||||
with open(self.path) as fl:
|
||||
data = fl.read()
|
||||
super(self.__class__, self).__init__(json.loads(data))
|
||||
else:
|
||||
super(self.__class__, self).__init__(Settings.get_default_settings())
|
||||
self['read'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['read']))
|
||||
self['write'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['write']))
|
||||
self['delete'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['delete']))
|
||||
self['master'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['master']))
|
||||
self['read'] = list(map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['read'])))
|
||||
self['write'] = list(map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['write'])))
|
||||
self['delete'] = list(map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['delete'])))
|
||||
self['master'] = list(map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['master'])))
|
||||
if self['folder'][-1] == '/' or self['folder'][-1] == '\\':
|
||||
self['folder'] = self['folder'][:-1]
|
||||
self.save()
|
||||
@@ -31,12 +35,13 @@ class Settings(Singleton, dict):
|
||||
'delete': [],
|
||||
'master': [],
|
||||
'folder': curr_directory(),
|
||||
'folder_save': curr_directory(),
|
||||
'auto_rights': 'r',
|
||||
'size': 500
|
||||
}
|
||||
|
||||
def save(self):
|
||||
print 'Saving'
|
||||
LOG.debug('Saving')
|
||||
text = json.dumps(self)
|
||||
with open(self.path, 'w') as fl:
|
||||
fl.write(text)
|
||||
@@ -49,7 +54,6 @@ class ProfileHelper(object):
|
||||
|
||||
@staticmethod
|
||||
def open_profile(path):
|
||||
path = path.decode(locale.getpreferredencoding())
|
||||
ProfileHelper._path = path
|
||||
with open(ProfileHelper._path, 'rb') as fl:
|
||||
data = fl.read()
|
||||
|
||||
Reference in New Issue
Block a user