Exemplo n.º 1
0
Arquivo: repo.py Projeto: dpq/spooce
 def __call__(self, env, start_response):
     req = Request(env)
     Config = ConfigParser()
     Config.read(configfile)
     params = {"host": "", "user": "", "database": "", "port": ""}
     for param in params:
         if not Config.has_option("MySQL", param):
             print "Malformed configuration file: mission option %s in section MySQL" % (param)
             sys.exit(1)
         params[param] = Config.get("MySQL", param)
     #print params
     #engine = create_engine("mysql+mysqldb://%s:%s@%s:%s/%s?charset=utf8&use_unicode=0" %
     #    (params["user"], secret.MySQL, params["host"], params["port"], params["database"]), pool_recycle=3600)
     Base = declarative_base(bind=engine)
     local.Session = []
     local.Package = []
     local.Session.append(sessionmaker(bind=engine))
     local.Package.append(makePackage(Base))
     resp = Response(status=200, content_type="text/plain")
     if req.path == '/pkg/upload':
         resp.content_type="text/html"
         resp.response = self.__upload(req)
         return resp(env, start_response)
     elif req.path == '/pkg/sdk':
         resp.content_disposition="application/force-download"
         resp.content_type="application/python"
         resp.headers.add("Content-Disposition", "attachment; filename=appcfg.py")
         f = open("appcfg.py").read().replace("__REPO_UPLOAD__", '"%s"' % (req.host_url + 'pkg/upload'))
         resp.headers.add("Content-Length", str(len(f)))
         resp.response = [f]
         return resp(env, start_response)
     elif req.path.startswith('/pkg'):
         resp.status_code, resp.content_encoding, resp.response = self.__download(req)
         return resp(env, start_response)
     else:
         resp.status_code = 404
         resp.response = [""]
         return resp(env, start_response)