def server(): parser = argparse.ArgumentParser() parser.add_argument('action', choices=['start', 'stop'], help='action') parser.add_argument('-host', default='localhost') parser.add_argument('-port', default='8888') args = parser.parse_args() from tempstorage import server # init routes if args.action == 'start': print 'Started server %s:%s' % (args.host, args.port) else: print 'Stopped' daemon_run(args.host, args.port)
self.cards = [] # generate cards self._randomize() # generate random cards for the # of cards requested def _randomize(self): for c in range(self._num_cards): self.cards.append( Card() ) # return the json representation of the deal def json(self): return json.dumps(self, default=default_json, sort_keys=False, indent=4) # deal service @route('/deal') def deal(): # default # of cards is 2 cards = 2 try: cards = int(request.query.cards) except ValueError: # parameter error, return default # of cards print 'Number of cards not an integer value. Returning 2 cards.' deal = Deal(cards) return deal.json() if __name__ == "__main__": daemon_run(host='0.0.0.0', port=8080)
LOG_FILE = 'hook.log' BOTTLE_LOG_FILE = 'bottle.log' BOTTLE_PID = 'bottle.pid' LOG_PATH = os.path.dirname(os.path.realpath(__file__)) + '/' + LOG_FILE BOTTLE_PATH = os.path.dirname(os.path.realpath(__file__)) + '/' + BOTTLE_LOG_FILE BOTTLE_PID_PATH = os.path.dirname(os.path.realpath(__file__)) + '/' + BOTTLE_PID @post('/pull/<path:path>') @get('/pull/<path:path>') def pull(path): logging.basicConfig(filename=LOG_PATH, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) logging.info('======================') logging.info('Pulling for %s' % path) path = path if path.startswith('/') else '/' + path if os.path.isdir(path): output = subprocess.Popen(['git', 'pull'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=path).communicate()[0] # output = subprocess.check_output(["git", "pull"], stderr=subprocess.STDOUT, cwd=path) # output = subprocess.check_output(["git", "status"], stderr=subprocess.STDOUT, cwd=path) output = "%s" % (output.decode('unicode_escape')) logging.info(output) return output logging.info('given path %s does not exist' % path) return 'Given path does not exist, dude! Give me a proper path to work with lah! :)' # run(host='localhost', port=8989) if __name__ == "__main__": daemon_run(host='localhost', port=8989, logfile=BOTTLE_PATH, pidfile=BOTTLE_PID_PATH)
#!/usr/bin/env python """ Simple AFP mock to allow testing the afp-cli. """ import bottle from bottle import route from textwrap import dedent from bottledaemon import daemon_run import sys @route('/account') def account(): return """{"test_account": ["test_role"]}""" @route('/account/<account>/<role>') def credentials(account, role): return dedent(""" {"Code": "Success", "LastUpdated": "1970-01-01T00:00:00Z", "AccessKeyId": "XXXXXXXXXXXX", "SecretAccessKey": "XXXXXXXXXXXX", "Token": "XXXXXXXXXXXX", "Expiration": "2032-01-01T00:00:00Z", "Type": "AWS-HMAC"}""").strip() if len(sys.argv) > 1: daemon_run(host='localhost', port=5555) else: # manual testing mode on different port, so it won't stop "pyb install" from running tests bottle.run(host='localhost', port=5544)
# -*- coding:utf-8 -*- from bottledaemon import daemon_run from bottle import route, run, request from predict_question_tags import predict_question_tags from predictor import predict @route("/question_tags", method = "post") def question_tags(): keys = request.json['keys'] values = request.json["values"] return predict_question_tags(keys, values) @route("/predict", method = "post") def question_tags(): question = request.json['question'] return predict(question) if __name__ == "__main__": daemon_run(host="0.0.0.0", port=8080)
from bottle import route from bottledaemon import daemon_run from textwrap import dedent import sys @route('/account') def account(): return '{"test_account": ["test_role"],' \ '"test_account_with_long_name": ["test_role_with_long_name"]}' @route('/account/<account>/<role>') def credentials(account, role): return dedent(""" {"Code": "Success", "LastUpdated": "1970-01-01T00:00:00Z", "AccessKeyId": "XXXXXXXXXXXX", "SecretAccessKey": "XXXXXXXXXXXX", "Token": "XXXXXXXXXXXX", "Expiration": "2032-01-01T00:00:00Z", "Type": "AWS-HMAC"}""").strip() if len(sys.argv) > 1: daemon_run(host='localhost', port=5555) else: # manual testing mode on different port, so it won't stop # "pyb install" from running tests bottle.run(host='localhost', port=5544)