Exemplo n.º 1
0
 def renderInputNamePage(self, request):
     template = 'pages/input_name.html'
     possible_name = bpio.getUserName().lower()
     if misc.isEnglishString(possible_name):
         possible_name = 'e.g.: ' + possible_name
     else:
         possible_name = ''
     context = {'username': self.data['username'],
                'pksize': self.data['pksize'],
                'output': '',
                'usernameplaceholder': possible_name, }
     try:
         text, color = installer.A().getOutput().get('data', [('', '')])[-1]
         context['output'] = '<font color="%s">%s</font><br />\n' % (color, text)
     except:
         pass
     if request is None:
         return template, context, request
     action = request.REQUEST.get('action', None)
     if action == 'next':
         self.data['pksize'] = int(request.REQUEST.get('pksize', self.data['pksize']))
         self.data['username'] = request.REQUEST.get('username', self.data['username']).lower()
         installer.A('register-start', self.data)
         return None
     if action == 'back':
         installer.A('back')
         return None
     return template, context, request
Exemplo n.º 2
0
 def render(self, request):
     current_state = installer.A().state
     current_page = self.installer_state_to_page.get(current_state, None)
     if current_page is None:
         raise Exception('incorrect state in installer(): %s' % current_state)
     result = current_page(request)
     return result
Exemplo n.º 3
0
 def state_changed(self, oldstate, newstate, event, *args, **kwargs):
     """
     This method intended to catch the moment when automat's state were
     changed.
     """
     from main import installer
     installer.A('id_registrator.state', newstate)
Exemplo n.º 4
0
 def doPrint(self, arg):
     """
     Action method.
     """
     from main import installer
     installer.A().event('print', arg)
     self.last_message = arg[0]
     lg.out(6, 'id_registrator.doPrint: %s' % str(arg))
Exemplo n.º 5
0
 def doPrint(self, *args, **kwargs):
     """
     Action method.
     """
     from main import installer
     installer.A().event('print', *args, **kwargs)
     self.last_message = args[0][0]
     lg.out(6, 'id_registrator.doPrint: %s' % str(*args, **kwargs))
Exemplo n.º 6
0
 def state_changed(self, oldstate, newstate, event, *args, **kwargs):
     if newstate == 'CONTACTS' and oldstate == 'STORAGE':
         self.event('next', {})
         # TODO:
         # here just skip Contacts page!
         # we do not need that now, but can back to that soon when add chat
     from main import control
     control.request_update()
     installer.A('install_wizard.state', newstate)
Exemplo n.º 7
0
 def renderSelectPage(self, request):
     template = 'pages/select_action.html'
     context = {}
     if request is None:
         return template, context, request
     action = request.REQUEST.get('action', None)
     if action == 'next':
         installer.A(request.REQUEST.get('mode', 'register-selected'))
         return None
     return template, context, request
Exemplo n.º 8
0
 def renderRestorePage(self, request):
     template = 'pages/restore_identity.html'
     out = ''
     for text, color in installer.A().getOutput().get('data', []):
         if text.strip():
             out += '     <li><font color="%s">%s</font></li>\n' % (color, text)
     if out:
         out = '    <ul>\n' + out + '    </ul>\n'
     context = {'output': out,
                'idurl': '',
                }
     if installer.A().state == 'RESTORED':
         context['idurl'] = my_id.getLocalID()
         self.data['idurl'] = str(context['idurl'])
     if request is None:
         return template, context, request
     action = request.REQUEST.get('action', None)
     if action == 'next':
         installer.A(action)
         return None
     return template, context, request
Exemplo n.º 9
0
 def renderLoadKeyPage(self, request):
     template = 'pages/load_key.html'
     out = ''
     try:
         text, color = installer.A().getOutput('RECOVER').get('data', [('', '')])[-1]
         if text:
             out = '    <p><font color="%s">%s</font></p>\n' % (color, text)
     except:
         pass
     context = {'idurl': request.REQUEST.get('idurl',
                                             installer.A().getOutput().get('idurl', '')),
                'keysrc': request.REQUEST.get('keysrc',
                                              installer.A().getOutput().get('keysrc', '')),
                'output': out,
                }
     if context['idurl']:
         self.data['idurl'] = str(context['idurl'])
     if context['keysrc']:
         self.data['keysrc'] = str(context['keysrc'])
     if request is None:
         return template, context, request
     action = request.REQUEST.get('action', None)
     if action == 'load-from-file':
         try:
             self.data['keysrc'] = request.FILES['keyfilename'].read()
             context['output'] = ''
         except:
             self.data['keysrc'] = ''
             context['output'] = '<p><font color="red">error reading file</font></p>'
         if self.data['keysrc']:
             installer.A(action, self.data)
         return None
     if action == 'paste-from-clipboard':
         installer.A(action)
         return None
     if action == 'next':
         installer.A('restore-start', self.data)
         return None
     if action == 'back':
         installer.A(action)
         return None
     return template, context, request
Exemplo n.º 10
0
 def __init__(self):
     self.installer_state_to_page = {
         'AT_STARTUP': self.renderSelectPage,
         'WHAT_TO_DO?': self.renderSelectPage,
         'INPUT_NAME': self.renderInputNamePage,
         'REGISTER': self.renderRegisterNewUserPage,
         'AUTHORIZED': self.renderRegisterNewUserPage,
         'LOAD_KEY': self.renderLoadKeyPage,
         'RECOVER': self.renderRestorePage,
         'RESTORED': self.renderRestorePage,
         'WIZARD': self.renderWizardPage,
         'DONE': self.renderLastPage,
     }
     self.install_wizard_state_to_page = {
         'READY': self.renderWizardStartPage,
         'STORAGE': self.renderWizardStoragePage,
         'CONTACTS': self.renderWizardContactsPage,
         'LAST_PAGE': self.renderLastPage,
         'DONE': self.renderLastPage,
     }
     self.data = {
         'username': bpio.ReadTextFile(settings.UserNameFilename()).strip(),
         'pksize': settings.DefaultPrivateKeySize(),
         'needed': str(int(settings.DefaultNeededBytes() / (1024 * 1024))),
         'donated': str(int(settings.DefaultDonatedBytes() / (1024 * 1024))),
         'suppliers': str(settings.DefaultDesiredSuppliers()),
         'customersdir': unicode(settings.getCustomersFilesDir()),
         'localbackupsdir': unicode(settings.getLocalBackupsDir()),
         'restoredir': unicode(settings.getRestoreDir()),
         'idurl': '',
         'keysrc': '',
         'name': '',
         'surname': '',
         'nickname': '',
     }
     installer.A('init')
Exemplo n.º 11
0
 def doPrint(self, arg):
     from main import installer
     installer.A().event('print', arg)
     lg.out(6, 'id_restorer.doPrint: %s' % str(arg))
Exemplo n.º 12
0
 def _get_output(self, state):
     out = ''
     for text, color in installer.A().getOutput(state).get('data', []):
         if text.strip():
             out += '<font color="%s">%s</font><br />\n' % (color, text)
     return out
Exemplo n.º 13
0
 def A(self, event, *args, **kwargs):
     from main import installer
     from main import shutdowner
     #---AT_STARTUP---
     if self.state == 'AT_STARTUP':
         if event == 'run':
             self.state = 'LOCAL'
             shutdowner.A('init')
             self.doInitLocal(*args, **kwargs)
             self.flagCmdLine = False
         elif event == 'run-cmd-line-register':
             self.state = 'INSTALL'
             shutdowner.A('init')
             self.flagCmdLine = True
             installer.A('register-cmd-line', *args, **kwargs)
             shutdowner.A('ready')
         elif event == 'run-cmd-line-recover':
             self.state = 'INSTALL'
             shutdowner.A('init')
             self.flagCmdLine = True
             installer.A('recover-cmd-line', *args, **kwargs)
             shutdowner.A('ready')
     #---LOCAL---
     elif self.state == 'LOCAL':
         if event == 'init-local-done' and not self.isInstalled(
                 *args, **kwargs) and self.isGUIPossible(*args, **kwargs):
             self.state = 'INSTALL'
             installer.A('init')
             shutdowner.A('ready')
             self.doInitInterfaces(*args, **kwargs)
             self.doShowGUI(*args, **kwargs)
             self.doUpdate(*args, **kwargs)
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'STOPPING'
             self.doDestroyMe(*args, **kwargs)
         elif event == 'init-local-done' and (
             (not self.isInstalled(*args, **kwargs)
              and not self.isGUIPossible(*args, **kwargs))
                 or self.isInstalled(*args, **kwargs)):
             self.state = 'INTERFACES'
             shutdowner.A('ready')
             self.doInitInterfaces(*args, **kwargs)
     #---MODULES---
     elif self.state == 'MODULES':
         if event == 'init-modules-done':
             self.state = 'READY'
             self.doUpdate(*args, **kwargs)
             self.doShowGUI(*args, **kwargs)
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     #---INSTALL---
     elif self.state == 'INSTALL':
         if not self.flagCmdLine and (event == 'installer.state'
                                      and args[0] == 'DONE'):
             self.state = 'STOPPING'
             shutdowner.A('stop', "restartnshow")
         elif self.flagCmdLine and (event == 'installer.state'
                                    and args[0] == 'DONE'):
             self.state = 'STOPPING'
             shutdowner.A('stop', "exit")
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     #---READY---
     elif self.state == 'READY':
         if (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     #---STOPPING---
     elif self.state == 'STOPPING':
         if (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doUpdate(*args, **kwargs)
             self.doDestroyMe(*args, **kwargs)
     #---EXIT---
     elif self.state == 'EXIT':
         pass
     #---SERVICES---
     elif self.state == 'SERVICES':
         if event == 'init-services-done':
             self.state = 'MODULES'
             self.doInitModules(*args, **kwargs)
             shutdowner.A('ready')
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     #---INTERFACES---
     elif self.state == 'INTERFACES':
         if event == 'init-interfaces-done':
             self.state = 'SERVICES'
             self.doInitServices(*args, **kwargs)
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     return None
Exemplo n.º 14
0
 def doPrint(self, arg):
     from main import installer
     installer.A().event('print', arg)
     self.last_message = arg[0]
     lg.out(6, 'id_restorer.doPrint: %s' % str(arg))
Exemplo n.º 15
0
 def state_changed(self, oldstate, newstate, event, arg):
     global_state.set_global_state('ID_RESTORE ' + newstate)
     from main import installer
     installer.A('id_restorer.state', newstate)
Exemplo n.º 16
0
 def state_changed(self, oldstate, newstate, event, *args, **kwargs):
     from main import installer
     installer.A('id_restorer.state', newstate)
Exemplo n.º 17
0
 def doPrint(self, arg):
     """
     Action method.
     """
     from main import installer
     installer.A().event('print', arg)