#!/usr/bin/env python
# Programmer: Chris Bunch (chris@appscale.com)
""" Starts a Python web server that accepts REST-formatted requests to store and
retrieve data via cloud storage offerings. """


# General-purpose Python library imports
import argparse
import os
import sys


# Third-party library imports
from paste import httpserver
import webapp2


# Magik library imports
lib = os.path.dirname(__file__) + os.sep + ".."
sys.path.append(lib)
from magik.rest_server import MagikUI
from magik.rest_server import RESTServer
from magik.rest_server import StaticFileHandler


if __name__ == "__main__":
  parser = argparse.ArgumentParser(description='Upload or download files ' +
    'from supported cloud storage systems via a RESTful interface.')

  parser.add_argument('--address', '-a', default='127.0.0.1',
    help='the IP or FQDN that the web server should bind to')
  parser.add_argument('--port', '-p', default=8080, type=int,
    help='the port number that the web server should bind to')
  args = vars(parser.parse_args(sys.argv[1:]))

  app = webapp2.WSGIApplication([
   ('/', MagikUI),
   ('/static/(.+)', StaticFileHandler),
   ('(.*)', RESTServer),
  ], debug=True)

  httpserver.serve(app, host=args['address'], port=args['port'])
