def verify_game_auth(): game_def = get_definition() id = game_def['game_id'] try: game = get_game(id) except urllib2.HTTPError as e: if e.code == 404: print panic("You don't own a game with an Game ID '%s'" %id) else: raise e
def submit(): token, consumer = authenticate() game_def = get_definition() project_path, y = get_game_dir_info() path = "%s/%s" % (project_path,y) pack() content = open(project_path + "/game.zip", 'rb').read() digest = hashlib.sha1() digest.update(content) game = get_game(game_def['game_id']) if game_def['autoVersion']: print "Submiting %s" % (game['name']) else: print "Submiting %s v%s" % (game['name'],game_def['version']) print "Digest (SHA1): " + digest.hexdigest() files = [("submission", 'game', content)] params = { 'oauth_version': "1.0", 'oauth_nonce': oauth.generate_nonce(), 'oauth_timestamp': int(time.time()), 'oauth_token': token.key, 'oauth_consumer_key': consumer.key, 'game_id': game_def['game_id'], } #create a fake request with your upload url and parameters faux_req = oauth.Request(method='POST', url="http://localhost:8000/api/submissions.json", parameters=params) #sign the fake request. signature_method = oauth.SignatureMethod_HMAC_SHA1() faux_req.sign_request(signature_method, consumer, token) #create a dict out of the fake request signed params params = dict(parse_qsl(faux_req.to_postdata())) content_type, body = encode_multipart_formdata(params, files) headers = {'Content-Type': content_type, 'Content-Length': str(len(body))} r = urllib2.Request('%s' % "http://localhost:8000/api/submissions.json", body, headers) try: urllib2.urlopen(r).read() print "Successful" except urllib2.HTTPError, ex: print >> sys.stderr, 'Received error code: ', ex.code print >> sys.stderr print >> sys.stderr, ex f = open("coredump",'w') f.write(ex.read()) sys.exit(1)