mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 04:48:09 -06:00
Config validation, invisible interface fix
This commit is contained in:
parent
a513303a9a
commit
d2f7228653
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: cp1252 -*-
|
# -*- coding: cp1252 -*-
|
||||||
from config_utils import Configuration, ConfigurationResetException
|
import config_utils
|
||||||
import paths
|
import paths
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -13,7 +13,4 @@ app = None
|
|||||||
def setup ():
|
def setup ():
|
||||||
global app
|
global app
|
||||||
log.debug("Loading global app settings...")
|
log.debug("Loading global app settings...")
|
||||||
try:
|
app = config_utils.load_config(paths.config_path(MAINFILE), paths.app_path(MAINSPEC))
|
||||||
app = Configuration(paths.config_path(MAINFILE), paths.app_path(MAINSPEC))
|
|
||||||
except ConfigurationResetException:
|
|
||||||
pass
|
|
||||||
|
@ -1,50 +1,18 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from UserDict import UserDict
|
|
||||||
from configobj import ConfigObj, ParseError
|
from configobj import ConfigObj, ParseError
|
||||||
from validate import Validator, VdtValueError
|
from validate import Validator, ValidateError
|
||||||
import os
|
import os
|
||||||
|
|
||||||
"""We're using the configobj python package
|
class ConfigLoadError(Exception): pass
|
||||||
from http://www.voidspace.org.uk/python/configobj.html """
|
|
||||||
|
|
||||||
class ConfigurationResetException(Exception):
|
def load_config(config_path, configspec_path=None, *args, **kwargs):
|
||||||
pass
|
spec = ConfigObj(configspec_path, encoding='UTF8', list_values=False, _inspec=True)
|
||||||
|
try:
|
||||||
|
config = ConfigObj(infile=config_path, configspec=spec, create_empty=True, encoding='UTF8', *args, **kwargs)
|
||||||
class Configuration (UserDict):
|
except ParseError:
|
||||||
|
raise ConfigLoadError("Unable to load %r" % config_path)
|
||||||
def __init__ (self, file=None, spec=None, *args, **kwargs):
|
validator = Validator()
|
||||||
self.file = file
|
validated = config.validate(validator, copy=True)
|
||||||
self.spec = spec
|
if validated == True:
|
||||||
self.validator = Validator()
|
config.write()
|
||||||
self.setup_config(file=file, spec=spec)
|
return config
|
||||||
self.validated = self.config.validate(self.validator, copy=True)
|
|
||||||
if self.validated:
|
|
||||||
self.write()
|
|
||||||
UserDict.__init__(self, self.config)
|
|
||||||
|
|
||||||
def setup_config (self, file, spec):
|
|
||||||
#The default way -- load from a file
|
|
||||||
spec = ConfigObj(spec, list_values=False, encoding="utf-8")
|
|
||||||
try:
|
|
||||||
self.config = ConfigObj(infile=file, configspec=spec, create_empty=True, stringify=True, encoding="utf-8")
|
|
||||||
except ParseError:
|
|
||||||
os.remove(file)
|
|
||||||
self.config = ConfigObj(infile=file, configspec=spec, create_empty=True, stringify=True)
|
|
||||||
raise ConfigurationResetException
|
|
||||||
def __getitem__ (self, *args, **kwargs):
|
|
||||||
return dict(self.config).__getitem__(*args, **kwargs)
|
|
||||||
|
|
||||||
def __setitem__ (self, *args, **kwargs):
|
|
||||||
self.config.__setitem__(*args, **kwargs)
|
|
||||||
UserDict.__setitem__(self, *args, **kwargs)
|
|
||||||
|
|
||||||
def write (self):
|
|
||||||
if hasattr(self.config, 'write'):
|
|
||||||
self.config.write()
|
|
||||||
|
|
||||||
class SessionConfiguration (Configuration):
|
|
||||||
def setup_config (self, file, spec):
|
|
||||||
#No infile required.
|
|
||||||
spec = ConfigObj(spec, list_values=False)
|
|
||||||
self.config = ConfigObj(configspec=spec, stringify=True)
|
|
||||||
|
@ -69,7 +69,7 @@ class Controller(object):
|
|||||||
buffer = self.search_buffer("home_timeline", view_buffer.account)
|
buffer = self.search_buffer("home_timeline", view_buffer.account)
|
||||||
else:
|
else:
|
||||||
buffer = self.search_buffer(view_buffer.name, view_buffer.account)
|
buffer = self.search_buffer(view_buffer.name, view_buffer.account)
|
||||||
return buffer
|
if buffer != None: return buffer
|
||||||
|
|
||||||
def get_first_buffer(self, account):
|
def get_first_buffer(self, account):
|
||||||
""" Gets the first valid buffer for an account.
|
""" Gets the first valid buffer for an account.
|
||||||
@ -785,9 +785,13 @@ class Controller(object):
|
|||||||
self.view.check_menuitem("autoread", autoread)
|
self.view.check_menuitem("autoread", autoread)
|
||||||
|
|
||||||
def fix_wrong_buffer(self):
|
def fix_wrong_buffer(self):
|
||||||
for i in self.accounts:
|
buf = self.get_best_buffer()
|
||||||
buffer = self.view.search("home_timeline", i)
|
if buf == None:
|
||||||
if buffer != None: break
|
for i in self.accounts:
|
||||||
|
buffer = self.view.search("home_timeline", i)
|
||||||
|
if buffer != None: break
|
||||||
|
else:
|
||||||
|
buffer = self.view.search("home_timeline", buf.session.db["user_name"])
|
||||||
self.view.change_buffer(buffer)
|
self.view.change_buffer(buffer)
|
||||||
|
|
||||||
def up(self, *args, **kwargs):
|
def up(self, *args, **kwargs):
|
||||||
|
@ -11,7 +11,7 @@ import sound
|
|||||||
import logging
|
import logging
|
||||||
from twitter import utils
|
from twitter import utils
|
||||||
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
|
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
|
||||||
from config_utils import Configuration, ConfigurationResetException
|
import config_utils
|
||||||
from mysc.thread_utils import stream_threaded
|
from mysc.thread_utils import stream_threaded
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
log = logging.getLogger("sessionmanager.session")
|
log = logging.getLogger("sessionmanager.session")
|
||||||
@ -106,7 +106,7 @@ class Session(object):
|
|||||||
file_ = "%s/session.conf" % (self.session_id,)
|
file_ = "%s/session.conf" % (self.session_id,)
|
||||||
# try:
|
# try:
|
||||||
log.debug("Creating config file %s" % (file_,))
|
log.debug("Creating config file %s" % (file_,))
|
||||||
self.settings = Configuration(paths.config_path(file_), paths.app_path("Conf.defaults"))
|
self.settings = config_utils.load_config(paths.config_path(file_), paths.app_path("Conf.defaults"))
|
||||||
self.init_sound()
|
self.init_sound()
|
||||||
# except:
|
# except:
|
||||||
# log.exception("The session configuration has failed.")
|
# log.exception("The session configuration has failed.")
|
||||||
|
@ -8,7 +8,7 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
import session
|
import session
|
||||||
import manager
|
import manager
|
||||||
from config_utils import Configuration
|
import config_utils
|
||||||
import config
|
import config
|
||||||
|
|
||||||
log = logging.getLogger("sessionmanager.sessionManager")
|
log = logging.getLogger("sessionmanager.sessionManager")
|
||||||
@ -32,7 +32,7 @@ class sessionManagerController(object):
|
|||||||
if os.path.isdir(paths.config_path(i)):
|
if os.path.isdir(paths.config_path(i)):
|
||||||
log.debug("Adding session %s" % (i,))
|
log.debug("Adding session %s" % (i,))
|
||||||
strconfig = "%s/session.conf" % (paths.config_path(i))
|
strconfig = "%s/session.conf" % (paths.config_path(i))
|
||||||
config_test = Configuration(strconfig)
|
config_test = config_utils.load_config(strconfig)
|
||||||
name = config_test["twitter"]["user_name"]
|
name = config_test["twitter"]["user_name"]
|
||||||
if config_test["twitter"]["user_key"] != "" and config_test["twitter"]["user_secret"] != "":
|
if config_test["twitter"]["user_key"] != "" and config_test["twitter"]["user_secret"] != "":
|
||||||
sessionsList.append(name)
|
sessionsList.append(name)
|
||||||
|
Loading…
Reference in New Issue
Block a user