Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:Hoektronics/BotQueue

  • Loading branch information...
commit 004f8f1f843ccd7d2a0e941aa86a68bbe928f51a 2 parents 43bcdb9 + 3af6223
Zach Hoeken authored
View
34 bumblebee/botqueueapi.py
@@ -12,6 +12,9 @@ class NetworkError(Exception):
class ServerError(Exception):
pass
+
+class AuthError(Exception):
+ pass
class BotQueueAPI():
@@ -39,7 +42,6 @@ def __init__(self):
if 'token_key' in self.config['app'] and self.config['app']['token_key']:
self.setToken(self.config['app']['token_key'], self.config['app']['token_secret'])
else:
- self.my_oauth_hook = OAuthHook(consumer_key=self.config['app']['consumer_key'], consumer_secret=self.config['app']['consumer_secret'])
self.authorize()
def setToken(self, token_key, token_secret):
@@ -47,8 +49,7 @@ def setToken(self, token_key, token_secret):
self.token_secret = token_secret
self.my_oauth_hook = OAuthHook(access_token = token_key, access_token_secret = token_secret, consumer_key=self.config['app']['consumer_key'], consumer_secret=self.config['app']['consumer_secret'])
-
- def apiCall(self, call, parameters = {}, url = False, method = "POST", retries = 999999, filepath = None):
+ def apiCall(self, call, parameters = {}, url = False, method = "POST", retries = 999999, filepath = None, ignoreInvalid = False):
#what url to use?
if (url == False):
url = self.endpoint_url
@@ -100,13 +101,20 @@ def apiCall(self, call, parameters = {}, url = False, method = "POST", retries =
#did the api itself return an error?
if result['status'] == 'error':
self.log.error("API: %s" % result['error'])
-
- #is the site database down?
- if result['status'] == 'error' and result['error'] == "Failed to connect to database!":
- raise ServerError("Database is down.")
-
+
+ #is the site database down?
+ if result['error'] == "Failed to connect to database!":
+ raise ServerError("Database is down.")
+ #shit, de-authed? re-auth!
+ if result['error'] == "Invalid token" and not ignoreInvalid:
+ raise AuthError("Token invalid, re-authorizing.")
+
return result
+ #we need to re-auth, do it.
+ except AuthError as ex:
+ self.log.error(ex)
+ self.authorize()
#these are our known errors that typically mean the network is down.
except (requests.ConnectionError, requests.Timeout, ServerError) as ex:
#raise NetworkError(str(ex))
@@ -115,7 +123,8 @@ def apiCall(self, call, parameters = {}, url = False, method = "POST", retries =
retries = retries - 1
#unknown exceptions... get a stacktrace for debugging.
except ValueError as ex:
- self.log.error("%s call failed: bad response: %s" % (call, response.text))
+ self.log.error("%s call failed: value error" % call)
+ self.log.exception(ex)
self.netError(True)
retries = retries - 1
except Exception as ex:
@@ -135,7 +144,7 @@ def netError(self, netStatus = False):
def requestToken(self):
#make our token request call or error
- result = self.apiCall('requesttoken')
+ result = self.apiCall('requesttoken', ignoreInvalid = True)
if result['status'] == 'success':
self.setToken(result['data']['oauth_token'], result['data']['oauth_token_secret'])
@@ -148,7 +157,7 @@ def getAuthorizeUrl(self):
def convertToken(self):
#switch our temporary auth token for our real credentials
- result = self.apiCall('accesstoken')
+ result = self.apiCall('accesstoken', ignoreInvalid = True)
if result['status'] == 'success':
self.setToken(result['data']['oauth_token'], result['data']['oauth_token_secret'])
return result['data']
@@ -157,6 +166,9 @@ def convertToken(self):
def authorize(self):
try:
+ #Step 0: Initialize to just our consumer key and secret.
+ self.my_oauth_hook = OAuthHook(consumer_key=self.config['app']['consumer_key'], consumer_secret=self.config['app']['consumer_secret'])
+
# Step 1: Get a request token. This is a temporary token that is used for
# having the user authorize an access token and to sign the request to obtain
# said access token.
View
2  bumblebee/bumblebee.py
@@ -172,7 +172,7 @@ def mainMenu(self, screen):
#show an intro screen.
self.screen.erase()
- self.screen.addstr("\nBotQueue v%s starting up.\n\n" % self.api.version)
+ self.screen.addstr("\nBotQueue v%s starting up. Scanning devices, please be patient.\n\n" % self.api.version)
self.screen.refresh()
#our main loop until we're done.
View
7 bumblebee/drivers/printcoredriver.py
@@ -71,8 +71,11 @@ def isConnected(self):
return self.p.online and self.p.printer
def stop(self):
- self.p.stop()
- self.disconnect()
+ try:
+ self.p.stop()
+ self.disconnect()
+ except AttributeError as ex:
+ self.log.error(ex)
def getTemperature(self):
return self.p.get_temperatures()
Please sign in to comment.
Something went wrong with that request. Please try again.