export config in config file + add static file
authorymh <ymh.work@gmail.com>
Thu, 09 Oct 2014 08:44:36 +0200
changeset 2 fc1ab0074e29
parent 1 1cdebfeb77f9
child 3 1b94e6e9579f
export config in config file + add static file
.hgignore
annot-server/annotserver.py
annot-server/config.py.tmpl
annot-server/server.tac
annot-server/static/css/base.css
annot-server/templates/index.html
utils/pianoroll-client.py
--- a/.hgignore	Wed Oct 08 18:08:52 2014 +0200
+++ b/.hgignore	Thu Oct 09 08:44:36 2014 +0200
@@ -1,25 +1,15 @@
 syntax: regexp
-utils/pianoroll_test*
 
-syntax: regexp
+^utils/pianoroll_test.*
 ^client/bower_components$
-syntax: regexp
 ^client/build$
-syntax: regexp
 ^client/node_modules$
-syntax: regexp
 ^.project$
-syntax: regexp
 ^annot-server/mymonsenv$
-syntax: regexp
 ^.pydevproject$
-syntax: regexp
 ^client/.bowerrc$
-syntax: regexp
 ^client/.editorconfig$
-syntax: regexp
 ^client/.jscsrc$
-syntax: regexp
 ^client/.jshintrc$
-syntax: regexp
-^annot-server/twistd.pid$
\ No newline at end of file
+^annot-server/twistd.pid$
+^annot-server/config.py$
--- a/annot-server/annotserver.py	Wed Oct 08 18:08:52 2014 +0200
+++ b/annot-server/annotserver.py	Thu Oct 09 08:44:36 2014 +0200
@@ -8,8 +8,9 @@
 from twisted.internet import reactor
 from twisted.python.threadpool import ThreadPool
 from twisted.web import server
+from twisted.web import resource
 from twisted.web.wsgi import WSGIResource
-from twisted.web.static import Data
+from twisted.web.static import Data, File
 
 from oscserver import OSCServerProtocol
 from websockets import BroadcastServerFactory, AnotationServerFactory
@@ -53,12 +54,16 @@
     rootWs.putChild("annot", wsAnnotResource)
 
 
+    webResource = resource.Resource()
+    webResource.putChild(config['static_url'], File(config['static_root']))
     # Create the WSGI resource
     wsgiAppAsResource = WSGIResource(reactor, wsgiThreadPool, app)
+    webResource.putChild('', wsgiAppAsResource)
+
 
     # Hooks for twistd
 
-    webserver = strports.service('tcp:%d' % config.get('web_port',WEB_PORT), server.Site(wsgiAppAsResource))
+    webserver = strports.service('tcp:%d' % config.get('web_port',WEB_PORT), server.Site(webResource))
     webserver.setServiceParent(s)
 
     wsserver = strports.service('tcp:%d' % config.get('ws_port',WS_PORT), server.Site(rootWs))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/annot-server/config.py.tmpl	Thu Oct 09 08:44:36 2014 +0200
@@ -0,0 +1,8 @@
+config = {
+    'web_port': 8080,
+    'ws_port': 8090,
+    'osc_port': 9090,
+    'conn_str': 'postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]',
+    'static_url': 'static',
+    'static_root' : os.path.join(os.path.dirname(os.path.abspath(__file__)),'static')
+}
--- a/annot-server/server.tac	Wed Oct 08 18:08:52 2014 +0200
+++ b/annot-server/server.tac	Thu Oct 09 08:44:36 2014 +0200
@@ -4,6 +4,7 @@
 # Copyright (c) 2014 IRI
 #
 
+import os.path
 import sys
 
 import psycopg2.extras
@@ -13,22 +14,14 @@
 from txpostgres import txpostgres
 
 from annotserver import make_service
+frpm config import config
 from models import get_table_create_stmt
 from utils import create_connection_pool
 
-#postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
 
 psycopg2.extras.register_uuid()
 
 
-config = {
-    'web_port': 8080,
-    'ws_port': 8090,
-    'osc_port': 9090,
-    'conn_str': 'postgresql://iri:iri@localhost:5432/annotations'
-}
-
-
 conn, d = create_connection_pool(config['conn_str'])
 #to do treat error
 d.addCallback(lambda _: conn.runOperation(get_table_create_stmt()))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/annot-server/static/css/base.css	Thu Oct 09 08:44:36 2014 +0200
@@ -0,0 +1,5 @@
+#log {
+    height: 20em;
+    overflow-y: scroll;
+    background-color: #faa;
+}
--- a/annot-server/templates/index.html	Wed Oct 08 18:08:52 2014 +0200
+++ b/annot-server/templates/index.html	Thu Oct 09 08:44:36 2014 +0200
@@ -46,10 +46,11 @@
             ellog.scrollTop = ellog.scrollHeight;
          };
       </script>
+      <link rel="stylesheet" type="text/css" href="/static/css/base.css">
    </head>
    <body>
       <h1>OSC websocket Test</h1>
       <noscript>You must enable JavaScript</noscript>
-      <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
+      <pre id="log"></pre>
    </body>
 </html>
--- a/utils/pianoroll-client.py	Wed Oct 08 18:08:52 2014 +0200
+++ b/utils/pianoroll-client.py	Thu Oct 09 08:44:36 2014 +0200
@@ -40,7 +40,6 @@
             time.sleep((row_conv[1].value-tc)/10**3)
             tc = row_conv[1].value
             self._send(osc.Message(self.address,*row_conv))
-            break
         print("Goodbye.")
         reactor.callLater(0.1, reactor.stop)