From 776c8338f3a425f10eb84c6f9a0bb15601b50f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Mon, 22 Feb 2016 13:15:10 -0600 Subject: [PATCH] Removed unneeded code fin the session manager --- src/main.py | 4 -- src/sessionmanager/sessionManager.py | 56 ++++++-------------------- src/sessionmanager/wxUI.py | 59 +--------------------------- 3 files changed, 15 insertions(+), 104 deletions(-) diff --git a/src/main.py b/src/main.py index 0846671..d4c439a 100644 --- a/src/main.py +++ b/src/main.py @@ -29,10 +29,6 @@ def setup(): from sessionmanager import sessionManager app = widgetUtils.mainLoopObject() sm = sessionManager.sessionManagerController() - sm.fill_list() - if len(sm.sessions) == 0: sm.show() - else: - sm.do_ok() del sm r = mainController.Controller() call_threaded(r.login) diff --git a/src/sessionmanager/sessionManager.py b/src/sessionmanager/sessionManager.py index 049f868..e153db6 100644 --- a/src/sessionmanager/sessionManager.py +++ b/src/sessionmanager/sessionManager.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- import os -import shutil +import sys import widgetUtils import wxUI as view import paths import time -import os import logging import session from config_utils import Configuration @@ -16,41 +15,24 @@ class sessionManagerController(object): def __init__(self): super(sessionManagerController, self).__init__() log.debug("Setting up the session manager.") - self.view = view.sessionManagerWindow() - widgetUtils.connect_event(self.view.new, widgetUtils.BUTTON_PRESSED, self.manage_new_account) - widgetUtils.connect_event(self.view.remove, widgetUtils.BUTTON_PRESSED, self.remove) - self.new_sessions = {} - self.removed_sessions = [] + self.fill_list() + if not hasattr(self, "session"): + self.manage_new_account() def fill_list(self): - sessionsList = [] - log.debug("Filling the sessions list.") - self.sessions = [] for i in os.listdir(paths.config_path()): if os.path.isdir(paths.config_path(i)): log.debug("Adding session %s" % (i,)) strconfig = "%s/session.conf" % (paths.config_path(i)) config_test = Configuration(strconfig) name = config_test["vk"]["user"] - sessionsList.append(name) - self.sessions.append(i) - self.view.fill_list(sessionsList) + self.session = i + s = session.vkSession(self.session) + s.get_configuration() + session.sessions[self.session] = s - def show(self): - if self.view.get_response() == widgetUtils.OK: - self.do_ok() - - def do_ok(self): - log.debug("Starting sessions...") - for i in self.sessions: - if session.sessions.has_key(i) == True: continue - s = session.vkSession(i) - s.get_configuration() - session.sessions[i] = s - self.new_sessions[i] = s - - def manage_new_account(self, *args, **kwargs): - if self.view.new_account_dialog() == widgetUtils.YES: + def manage_new_account(self): + if view.new_account_dialog() == widgetUtils.YES: location = (str(time.time())[-6:]) log.debug("Creating session in the %s path" % (location,)) s = session.vkSession(location) @@ -60,25 +42,13 @@ class sessionManagerController(object): os.mkdir(path) s.get_configuration() self.get_authorisation(s) - self.sessions.append(location) - self.view.add_new_session_to_list() -# except: -# log.exception("Error authorising the session") -# self.view.show_unauthorised_error() -# return - - def remove(self, *args, **kwargs): - if self.view.remove_account_dialog() == widgetUtils.YES: - selected_account = self.sessions[self.view.get_selected()] - self.view.remove_session(self.view.get_selected()) - self.removed_sessions.append(selected_account) - self.sessions.remove(selected_account) - shutil.rmtree(path=paths.config_path(selected_account), ignore_errors=True) + session.sessions[location] = s + else: + sys.exit() def get_authorisation(self, c): dl = view.newSessionDialog() if dl.ShowModal() == widgetUtils.OK: c.settings["vk"]["user"] = dl.get_email() c.settings["vk"]["password"] = dl.get_password() - c.authorise() c.settings.write() diff --git a/src/sessionmanager/wxUI.py b/src/sessionmanager/wxUI.py index 63c76ef..b0155c3 100644 --- a/src/sessionmanager/wxUI.py +++ b/src/sessionmanager/wxUI.py @@ -2,63 +2,8 @@ import wx import widgetUtils -class sessionManagerWindow(widgetUtils.BaseDialog): - def __init__(self): - super(sessionManagerWindow, self).__init__(parent=None, title="Session manager", size=wx.DefaultSize) - panel = wx.Panel(self) - sizer = wx.BoxSizer(wx.VERTICAL) - label = wx.StaticText(panel, -1, u"Accounts", size=wx.DefaultSize) - listSizer = wx.BoxSizer(wx.HORIZONTAL) - self.list = widgetUtils.list(panel, u"Account", style=wx.LC_SINGLE_SEL|wx.LC_REPORT) - listSizer.Add(label, 0, wx.ALL, 5) - listSizer.Add(self.list.list, 0, wx.ALL, 5) - sizer.Add(listSizer, 0, wx.ALL, 5) - self.new = wx.Button(panel, -1, u"New account", size=wx.DefaultSize) - self.remove = wx.Button(panel, -1, _(u"Remove account")) - ok = wx.Button(panel, wx.ID_OK, size=wx.DefaultSize) - ok.SetDefault() - cancel = wx.Button(panel, wx.ID_CANCEL, size=wx.DefaultSize) - buttons = wx.BoxSizer(wx.HORIZONTAL) - buttons.Add(self.new, 0, wx.ALL, 5) - buttons.Add(ok, 0, wx.ALL, 5) - buttons.Add(cancel, 0, wx.ALL, 5) - sizer.Add(buttons, 0, wx.ALL, 5) - panel.SetSizer(sizer) - min = sizer.CalcMin() - self.SetClientSize(min) - - def fill_list(self, sessionsList): - for i in sessionsList: - self.list.insert_item(False, i) - if self.list.get_count() > 0: - self.list.select_item(0) - self.list.list.SetSize(self.list.list.GetBestSize()) - - def ok(self, ev): - if self.list.get_count() == 0: - wx.MessageDialog(None, _(u"You need to configure an account."), _(u"Account Error"), wx.ICON_ERROR).ShowModal() - return - self.controller.do_ok() - self.EndModal(wx.ID_OK) - - def new_account_dialog(self): - return wx.MessageDialog(self, _(u"Would you like to autorhise a new account now?"), _(u"Authorisation"), wx.YES_NO).ShowModal() - - def add_new_session_to_list(self): - total = self.list.get_count() - name = _(u"Authorised account %d") % (total+1) - self.list.insert_item(False, name) - if self.list.get_count() == 1: - self.list.select_item(0) - - def remove_account_dialog(self): - return wx.MessageDialog(self, _(u"Do you really want delete this account?"), _(u"Remove account"), wx.YES_NO).ShowModal() - - def get_selected(self): - return self.list.get_selected() - - def remove_session(self, sessionID): - self.list.remove_item(sessionID) +def new_account_dialog(): + return wx.MessageDialog(None, _(u"In order to continue, you need to configure your VK account before. Would you like to autorhise a new account now?"), _(u"Authorisation"), wx.YES_NO).ShowModal() class newSessionDialog(widgetUtils.BaseDialog): def __init__(self):