socializer/src/sessionmanager/sessionManager.py

57 lines
1.7 KiB
Python
Raw Normal View History

2016-02-13 17:06:36 -06:00
# -*- coding: utf-8 -*-
import os
import sys
2016-02-13 17:06:36 -06:00
import widgetUtils
import wxUI as view
import paths
import time
import logging
import session
from config_utils import Configuration
log = logging.getLogger("sessionmanager.sessionManager")
class sessionManagerController(object):
def __init__(self):
super(sessionManagerController, self).__init__()
log.debug("Setting up the session manager.")
self.fill_list()
if not hasattr(self, "session"):
log.debug("the session list is empty, creating a new one...")
self.manage_new_account()
2016-02-13 17:06:36 -06:00
def fill_list(self):
log.debug("Filling the session list...")
2016-02-13 17:06:36 -06:00
for i in os.listdir(paths.config_path()):
if os.path.isdir(os.path.join(paths.config_path(), i)):
2016-02-13 17:06:36 -06:00
log.debug("Adding session %s" % (i,))
config_test = Configuration(os.path.join(paths.config_path(), i, "session.conf"))
2016-02-13 17:06:36 -06:00
name = config_test["vk"]["user"]
if name != "" and config_test["vk"]["password"] != "":
self.session = i
s = session.vkSession(self.session)
s.get_configuration()
session.sessions[self.session] = s
2016-02-13 17:06:36 -06:00
def manage_new_account(self):
if view.new_account_dialog() == widgetUtils.YES:
2016-02-13 17:06:36 -06:00
location = (str(time.time())[-6:])
log.debug("Creating session in the %s path" % (location,))
s = session.vkSession(location)
path = os.path.join(paths.config_path(), location)
2016-02-13 17:06:36 -06:00
if not os.path.exists(path):
os.mkdir(path)
s.get_configuration()
self.get_authorisation(s)
session.sessions[location] = s
else:
sys.exit()
2016-02-13 17:06:36 -06:00
def get_authorisation(self, c):
log.debug("Starting the authorisation process...")
2016-02-13 17:06:36 -06:00
dl = view.newSessionDialog()
if dl.ShowModal() == widgetUtils.OK:
c.settings["vk"]["user"] = dl.get_email()
c.settings["vk"]["password"] = dl.get_password()
c.settings.write()