2016-02-13 17:06:36 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
2016-02-22 13:15:10 -06:00
|
|
|
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.")
|
2016-02-22 13:15:10 -06:00
|
|
|
self.fill_list()
|
|
|
|
if not hasattr(self, "session"):
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("the session list is empty, creating a new one...")
|
2016-02-22 13:15:10 -06:00
|
|
|
self.manage_new_account()
|
2016-02-13 17:06:36 -06:00
|
|
|
|
|
|
|
def fill_list(self):
|
2016-05-10 20:23:48 -05:00
|
|
|
log.debug("Filling the session list...")
|
2016-02-13 17:06:36 -06:00
|
|
|
for i in os.listdir(paths.config_path()):
|
2018-12-14 15:27:20 -06:00
|
|
|
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,))
|
2018-12-14 15:27:20 -06:00
|
|
|
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"]
|
2016-06-06 03:53:55 -05:00
|
|
|
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
|
|
|
|
2016-02-22 13:15:10 -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)
|
2018-12-14 15:27:20 -06:00
|
|
|
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)
|
2016-02-22 13:15:10 -06:00
|
|
|
session.sessions[location] = s
|
|
|
|
else:
|
|
|
|
sys.exit()
|
2016-02-13 17:06:36 -06:00
|
|
|
|
|
|
|
def get_authorisation(self, c):
|
2016-05-10 20:23:48 -05:00
|
|
|
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()
|