Esempio n. 1
0
def initialize( config_path = None ):
    if not os.path.isdir(Paths.user_dir):
        os.mkdir( Paths.user_dir )
    if not os.path.isfile( Paths.config ):
        shutil.copy( Paths.default_config, Paths.config )
    if config_path:
        config.load_from_file( config_path )
    else:
        config.load_from_file( Paths.config )
    if not getattr( config, 'username', False ):
        gui_queue.put( (messages.REQUEST_USER_CREDS, ) )
Esempio n. 2
0
 def handle_command( self, command ):
     if command[0] == messages.REQUEST_START_SESSION:
         self.start = int( time.time() )
         gui_queue.put( ( messages.STARTED_SESSION,) )
         api_queue.put( partial( api.create_session, self) )
         api_queue.put( partial( api.start_session, self) )
     if command[0] == messages.REQUEST_END_SESSION:
         self.end = int( time.time() )
         gui_queue.put( (messages.ENDED_SESSION,) )
         api_queue.put( partial( api.end_session, self ) )
     if command[0] == messages.REQUEST_PAUSE_SESSION and not self.paused:
         self.paused = True
         gui_queue.put( (messages.PAUSED_SESSION,) )
     if command[0] == messages.REQUEST_RESUME_SESSION and self.paused:
         self.paused = False
         gui_queue.put( (messages.RESUMED_SESSION,) )
Esempio n. 3
0
def api_call( url, params=None, req_func=requests.post, callback = None, data=None, accept_failure=False ):
    global pending_signin
    while True:
        logger.debug( "Making API call %s" % (str({
            'type': req_func.__name__,
            'url':url,
            'params':params,
            'req':req_func,
            'callback':callback} ) ) )
        try:
            response = req_func(
                url = url,
                headers = get_headers(),
                params = params or {},
                data = data,
                verify = False )
            logger.debug( str(\
                {   'request headers': response.request.headers,
                    'response': response.text, 
                    'code':response.status_code,
                    'url':response.url  }))
            if response.ok:
                break
            elif response.status_code in (400,401) and not pending_signin:
                pending_signin = True
                gui_queue.put( ( messages.REQUEST_USER_CREDS, ) )
            if not response.ok and accept_failure:
                break
        except requests.ConnectionError as e:
            logger.debug("Couldn't reach server, waiting 5 seconds and retrying (%s)"%str(e))
        except AttributeError:
            logger.debug("Invalid request, waiting 5 seconds and retrying")
        finally:
            sleep(5)
    if callback:
        callback( response )
Esempio n. 4
0
def initialize():
    if not os.path.isdir(Paths.user_dir):
        os.mkdir( Paths.user_dir )
    if not os.path.isfile( Paths.config ):
        gui_queue.put( (messages.REQUEST_USER_CREDS, ) )