summaryrefslogtreecommitdiff
path: root/scripts/proxy/main.py
authorClipperz <info@clipperz.com>2013-01-08 15:12:19 (UTC)
committer Clipperz <info@clipperz.com>2013-01-08 15:12:19 (UTC)
commit25bd3085c5464862172c5bd921deca550185fe83 (patch) (side-by-side diff)
tree2ea95bdd3606e9721fac81ab072d093fd46005fe /scripts/proxy/main.py
parent596e94dca490619acced2e38fb3221cc7237b1ce (diff)
downloadclipperz-25bd3085c5464862172c5bd921deca550185fe83.zip
clipperz-25bd3085c5464862172c5bd921deca550185fe83.tar.gz
clipperz-25bd3085c5464862172c5bd921deca550185fe83.tar.bz2
Updated builder script
Diffstat (limited to 'scripts/proxy/main.py') (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/proxy/main.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/scripts/proxy/main.py b/scripts/proxy/main.py
new file mode 100755
index 0000000..107ba16
--- a/dev/null
+++ b/scripts/proxy/main.py
@@ -0,0 +1,95 @@
+from twisted.internet import reactor
+from twisted.web import proxy, server, http, resource, static
+from posixpath import basename, dirname
+
+import copy
+import sys
+import os
+import pprint
+
+#--------------------------------------------------------------------
+
+def scriptDir ():
+ return os.path.dirname(sys.argv[0])
+
+def projectBaseDir ():
+ return os.path.abspath(scriptDir() + '/../..')
+
+def projectTargetDir():
+ return projectBaseDir() + '/target/'
+
+#--------------------------------------------------------------------
+
+class ClipperzTestSite(server.Site):
+
+ def __init__(self, resource, logPath=None, timeout=60 * 60 * 12):
+ server.Site.__init__(self, resource, logPath, timeout)
+
+
+ def getResourceFor(self, request):
+ if request.uri.startswith('/json') or request.uri.startswith('/dump'):
+ request.site = self
+ request.sitepath = copy.copy(request.prepath)
+ result = resource.getChildForRequest(self.resource, request)
+
+ else:
+ pathParts = request.uri.split('/')
+ version = pathParts[1]
+
+ if pathParts[2].startswith('index.'):
+ contentType = 'text/html'
+ absoluteFilePath = os.path.join(projectTargetDir(), 'dev', version, pathParts[2])
+ result = static.File(absoluteFilePath, contentType)
+
+ else:
+# http://homer.local:8888/beta/css/clipperz/images/loginInfoBackground.png
+# pathParts: ['', 'beta', 'css', 'clipperz', 'images', 'loginInfoBackground.png']
+ try:
+ imagePathIndex = pathParts.index('images')
+ resourceType = 'images'
+ for _ in range(2, imagePathIndex):
+ del pathParts[2]
+ except:
+ resourceType = pathParts[2]
+
+ basePath = projectBaseDir() + '/frontend'
+ if resourceType == 'images':
+ fileExtension = os.path.splitext(request.uri)[1]
+ if fileExtension == '.png':
+ contentType = 'image/png'
+ elif fileExtension == '.jpg':
+ contentType = 'image/jpeg'
+ elif fileExtension == '.gif':
+ contentType = 'image/gif'
+ else:
+ print "ERROR - unknown image extension: " + fileExtension
+
+ absoluteFilePath = basePath + '/'.join(pathParts)
+ else:
+ resourceType = pathParts[2]
+
+ if resourceType == 'css':
+ contentType = 'text/css'
+ elif resourceType == 'js':
+ contentType = 'text/javascript'
+ else:
+ contentType = 'text/html'
+
+ absoluteFilePath = basePath + request.uri
+
+ result = static.File(absoluteFilePath, contentType)
+
+
+ return result
+
+
+
+def main ():
+ site = ClipperzTestSite(proxy.ReverseProxyResource('localhost', 8084, '/java-backend'))
+ reactor.listenTCP(8888, site)
+ reactor.run()
+
+
+if __name__ == "__main__":
+ main()
+