Skip to content

Commit

Permalink
token gen fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Chase committed Nov 17, 2014
1 parent 2e06c47 commit 301370e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions includes/lib/bitcasa_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_bitcasa_token(self):
except ValueError:
log.info("Converting bitcasa.ini")
log.info("If you are using a custom CLIENTID and CLIENTSECRET please put them in bitcasa.ini")
with open(utils.BITCASA_SAMPLE_TOKEN, "r") as sample, open(utils.BITCASA_TOKEN, "w+") as tokenfile:
with open(utils.BITCASA_SAMPLE_TOKEN, "r") as sample, open(utils.BITCASA_TOKEN, "w") as tokenfile:
json_sample = json.loads(sample.read())
self.client_id = json_sample["bitcasa"]["CLIENTID"]
self.client_secret = json_sample["bitcasa"]["CLIENTSECRET"]
Expand All @@ -39,8 +39,18 @@ def get_bitcasa_token(self):
log.error("No token stored")
except:
log.exception("Failed to read Bitcasa token file")
elif os.path.isfile(utils.BITCASA_SAMPLE_TOKEN):
log.info("Creating bitcasa.ini")
try:
with open(utils.BITCASA_SAMPLE_TOKEN, "r") as sample, open(utils.BITCASA_TOKEN, "w") as tokenfile:
json_sample = json.loads(sample.read())
self.client_id = json_sample["bitcasa"]["CLIENTID"]
self.client_secret = json_sample["bitcasa"]["CLIENTSECRET"]
tokenfile.write(json.dumps(json_sample, indent=4))
except:
log.exception("Error writing bitcasa.ini")
else:
log.info("No auth token file found at %s ", os.path.abspath(utils.BITCASA_TOKEN))
log.info("No auth token file found at %s or %s ", utils.BITCASA_TOKEN, utils.BITCASA_SAMPLE_TOKEN)
return self.token

def create_client(self, force=False, redirect_uri=utils.REDIRECT_URI):
Expand Down

0 comments on commit 301370e

Please sign in to comment.