# HG changeset patch # User ymh # Date 1413197027 -7200 # Node ID 435d5c15275adf5e27864433bf28c31232ce01fe # Parent a0f1f77148d98d2640de085fd7405b2c192d1be9 clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention diff -r a0f1f77148d9 -r 435d5c15275a .hgignore --- a/.hgignore Fri Oct 10 17:08:31 2014 +0200 +++ b/.hgignore Mon Oct 13 12:43:47 2014 +0200 @@ -12,4 +12,11 @@ ^client/.jscsrc$ ^client/.jshintrc$ ^annot-server/twistd.pid$ -^annot-server/config.py$ +^annot-server/settings.py$ +^annot-server/static/css/app +^annot-server/static/css/lib +^annot-server/static/css/fonts/ +^annot-server/static/js/app +^annot-server/static/js/lib +^annot-server/static/data +^annot-server/templates/annotationclient.html$ diff -r a0f1f77148d9 -r 435d5c15275a annot-server/README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/annot-server/README.md Mon Oct 13 12:43:47 2014 +0200 @@ -0,0 +1,9 @@ + +# Mons Annotation server + + +To start it : + 1. create virtualenv with requirements.txt + 1. activate the virtualenv + 1. create settings.py from settings.py.tmpl + 1. `twistd -ny server.tac` diff -r a0f1f77148d9 -r 435d5c15275a annot-server/annotserver.py --- a/annot-server/annotserver.py Fri Oct 10 17:08:31 2014 +0200 +++ b/annot-server/annotserver.py Mon Oct 13 12:43:47 2014 +0200 @@ -12,6 +12,7 @@ from twisted.web.wsgi import WSGIResource from twisted.web.static import Data, File +import config from oscserver import OSCServerProtocol from websockets import BroadcastServerFactory, AnotationServerFactory from webapp import app @@ -21,7 +22,7 @@ WS_PORT = 8090 OSC_PORT = 9090 -def make_service(config, conn, debug=False): +def make_service(conn, debug=False): s = service.MultiService() # Create and start a thread pool, @@ -32,14 +33,14 @@ reactor.addSystemEventTrigger('after', 'shutdown', wsgiThreadPool.stop) - wsFactory = BroadcastServerFactory("ws://localhost:%d/broadcast" % config.get('ws_port',WS_PORT), + wsFactory = BroadcastServerFactory("ws://localhost:%d/broadcast" % getattr(config,'WS_PORT',WS_PORT), debug = debug, debugCodePaths = debug) wsFactory.setProtocolOptions(allowHixie76 = True) wsResource = WebSocketResource(wsFactory) - wsAnnotFactory = AnotationServerFactory("ws://localhost:%d/annot" % config.get('ws_port',WS_PORT), + wsAnnotFactory = AnotationServerFactory("ws://localhost:%d/annot" % getattr(config,'WS_PORT',WS_PORT), debug = debug, debugCodePaths = debug, ws_factory = wsFactory, @@ -55,21 +56,21 @@ webResource = resource.Resource() - webResource.putChild(config['static_url'], File(config['static_root'])) + webResource.putChild(getattr(config,'STATIC_URL').lstrip('/'), File(getattr(config,'STATIC_ROOT'))) # Create the WSGI resource wsgiAppAsResource = WSGIResource(reactor, wsgiThreadPool, app) - webResource.putChild('', wsgiAppAsResource) + webResource.putChild('p', wsgiAppAsResource) # Hooks for twistd - webserver = strports.service('tcp:%d' % config.get('web_port',WEB_PORT), server.Site(webResource)) + webserver = strports.service('tcp:%d' % getattr(config,'WEB_PORT',WEB_PORT), server.Site(webResource)) webserver.setServiceParent(s) - wsserver = strports.service('tcp:%d' % config.get('ws_port',WS_PORT), server.Site(rootWs)) + wsserver = strports.service('tcp:%d' % getattr(config,'WS_PORT',WS_PORT), server.Site(rootWs)) wsserver.setServiceParent(s) - oscservice = internet.UDPServer(config.get('osc_port',OSC_PORT), OSCServerProtocol(wsFactory, conn)) + oscservice = internet.UDPServer(getattr(config,'OSC_PORT',OSC_PORT), OSCServerProtocol(wsFactory, conn)) oscservice.setServiceParent(s) return s diff -r a0f1f77148d9 -r 435d5c15275a annot-server/config.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/annot-server/config.py Mon Oct 13 12:43:47 2014 +0200 @@ -0,0 +1,12 @@ +import os.path + +WEB_PORT = 8080 +WS_PORT = 8090 +OSC_PORT = 9090 + +CONN_STR = '' + +STATIC_URL = '/static' +STATIC_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)),'static') + +from settings import * diff -r a0f1f77148d9 -r 435d5c15275a annot-server/config.py.tmpl --- a/annot-server/config.py.tmpl Fri Oct 10 17:08:31 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -import os.path - -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') -} diff -r a0f1f77148d9 -r 435d5c15275a annot-server/server.tac --- a/annot-server/server.tac Fri Oct 10 17:08:31 2014 +0200 +++ b/annot-server/server.tac Mon Oct 13 12:43:47 2014 +0200 @@ -14,7 +14,7 @@ from txpostgres import txpostgres from annotserver import make_service -from config import config +import config from models import get_table_create_stmt from utils import create_connection_pool @@ -22,7 +22,7 @@ psycopg2.extras.register_uuid() -conn, d = create_connection_pool(config['conn_str']) +conn, d = create_connection_pool(config.CONN_STR) #to do treat error d.addCallback(lambda _: conn.runOperation(get_table_create_stmt())) @@ -32,5 +32,5 @@ application = service.Application("annot-server") -annotserver = make_service(config, conn) +annotserver = make_service(conn) annotserver.setServiceParent(service.IServiceCollection(application)) diff -r a0f1f77148d9 -r 435d5c15275a annot-server/settings.py.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/annot-server/settings.py.tmpl Mon Oct 13 12:43:47 2014 +0200 @@ -0,0 +1,12 @@ +import os.path + +WEB_PORT = 8080 +WS_PORT = 8090 +OSC_PORT = 9090 + +CONN_STR = '' + +STATIC_URL = '/static' +STATIC_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)),'static') + +from settings import * diff -r a0f1f77148d9 -r 435d5c15275a annot-server/webapp.py --- a/annot-server/webapp.py Fri Oct 10 17:08:31 2014 +0200 +++ b/annot-server/webapp.py Mon Oct 13 12:43:47 2014 +0200 @@ -8,8 +8,11 @@ from flask import Flask, render_template +import config + app = Flask(__name__) app.secret_key = str(uuid.uuid4()) +app.config.from_object(config) @app.route('/') def page_home(): diff -r a0f1f77148d9 -r 435d5c15275a client/app/annotationclient.html --- a/client/app/annotationclient.html Fri Oct 10 17:08:31 2014 +0200 +++ b/client/app/annotationclient.html Mon Oct 13 12:43:47 2014 +0200 @@ -4,8 +4,8 @@ Mons by IRI - - + +
@@ -46,7 +46,7 @@
-
@@ -59,7 +59,7 @@
-
@@ -86,15 +86,15 @@
- + - + diff -r a0f1f77148d9 -r 435d5c15275a client/app/app.css --- a/client/app/app.css Fri Oct 10 17:08:31 2014 +0200 +++ b/client/app/app.css Mon Oct 13 12:43:47 2014 +0200 @@ -1,5 +1,5 @@ .row{ - margin-top: 10px; + margin-top: 10px; } footer{ background: none; @@ -13,20 +13,21 @@ cursor: pointer; } .btn-lg{ - width: 100%; - line-height: 2; - font-size: 4vw; - background-color: #E6E6E6; + width: 100%; + line-height: 2; + font-size: 4vw; + background-color: #E6E6E6; } .row{ - margin-left: 0px; - margin-right: 0px; + margin-left: 0; + margin-right: 0; } .mons-content{ width: 100%; } .mons-button{ - background-color: #1e1e1e; + box-sizing: content-box; + background-color: #1e1e1e; border: 10px solid #fff; float: left; margin: 0.5%; @@ -36,7 +37,8 @@ width: 47%; } .mons-button .content{ - height: 90%; + box-sizing: content-box; + height: 90%; padding: 5%; position: absolute; width: 90%; @@ -50,7 +52,7 @@ display: table-cell; text-align: center; vertical-align: middle; - text-shadow: 0px 0px 5px #fff; + text-shadow: 0 0 5px #fff; } .large-cat{ font-size: 300%; @@ -67,7 +69,7 @@ background-color: #e6e6e6; } .send, .return{ - padding-bottom: 20%; + padding-bottom: 20%; } .row input{ @@ -75,15 +77,14 @@ } .messages { - position: fixed; - top: 0px; - z-index: 7000; + position: fixed; + top: 0; + z-index: 7000; } .success-border{ - border: 10px solid #3c763d; + border: 10px solid #3c763d; } /*.ng-scope{ border: red 1px solid; }*/ - diff -r a0f1f77148d9 -r 435d5c15275a client/gulpfile.js --- a/client/gulpfile.js Fri Oct 10 17:08:31 2014 +0200 +++ b/client/gulpfile.js Mon Oct 13 12:43:47 2014 +0200 @@ -1,20 +1,22 @@ var gulp = require('gulp'); +var del = require('del'); var gutil = require('gulp-util') var plugins = require("gulp-load-plugins")({lazy:false}); -//var flatten = require('gulp-flatten'); -//var uglify = require('gulp-uglify'); -//var clean = require('gulp-clean'); -//var rename = require('gulp-rename'); -//var filesize = require('gulp-filesize'); -//var cssmin = require('gulp-cssmin'); var templateFolder = '../annot-server/templates/'; var templateFileDest = '../annot-server/templates/annotationclient.html'; var staticFolder = '../annot-server/static'; -gulp.task('clean', function () { - gulp.src(templateFileDest, {read: false}).pipe(clean()); - gulp.src(staticFolder, {read: false}).pipe(clean()); +var clientBaseName = 'app'; +var vendorBaseName = 'lib'; + +gulp.task('clean', function (cb) { + del([ + templateFileDest, + staticFolder + "/css/app*", + staticFolder + "/js/app*", + staticFolder + "/data/categories.json", + ],{'force':true}, cb); }); var scriptsSrc = ['!./app/**/*_test.js','./app/**/*.js']; @@ -25,34 +27,26 @@ .pipe(plugins.jshint()) .pipe(plugins.jshint.reporter('default')) .pipe(plugins.jshint.reporter('fail')) - .pipe(plugins.concat('app.js')) + .pipe(plugins.concat(clientBaseName+'.js')) .pipe(gulp.dest(staticFolder+'/js')) .pipe(plugins.filesize()) .pipe(plugins.uglify()) - .pipe(plugins.rename('app.min.js')) + .pipe(plugins.rename(clientBaseName+'.min.js')) .pipe(gulp.dest(staticFolder+'/js')) .pipe(plugins.filesize()) .on('error', gutil.log); }); -//gulp.task('templates',function(){ -// //combine all template files of the app into a js file -// gulp.src(['!./app/index.html', -// './app/**/*.html']) -// .pipe(plugins.angularTemplatecache('templates.js',{standalone:true})) -// .pipe(gulp.dest(staticFolder+'/js')); -//}); - gulp.task('css', function(){ gulp.src('./app/**/*.css') -// .pipe(plugins.csslint()) -// .pipe(plugins.csslint.reporter()) - .pipe(plugins.concat('app.css')) + .pipe(plugins.csslint({ 'box-sizing': false })) + .pipe(plugins.csslint.reporter()) + .pipe(plugins.concat(clientBaseName+'.css')) .pipe(gulp.dest(staticFolder+'/css')) .pipe(plugins.filesize()) .pipe(plugins.minifyCss({keepBreaks:true})) - .pipe(plugins.rename('app.min.css')) + .pipe(plugins.rename(clientBaseName+'.min.css')) .pipe(gulp.dest(staticFolder+'/css')) .pipe(plugins.filesize()); }); @@ -85,11 +79,11 @@ //concatenate vendor CSS files gulp.src(['!./bower_components/**/*.min.css', './bower_components/**/*.css']) - .pipe(plugins.concat('lib.css')) + .pipe(plugins.concat(vendorBaseName+'.css')) .pipe(gulp.dest(staticFolder+'/css')) .pipe(plugins.filesize()) .pipe(plugins.minifyCss({keepBreaks:true})) - .pipe(plugins.rename('lib.min.css')) + .pipe(plugins.rename(vendorBaseName+'.min.css')) .pipe(gulp.dest(staticFolder+'/css')) .pipe(plugins.filesize()); }); @@ -122,10 +116,9 @@ staticFolder+'/**/*.css' ], function(event) { return gulp.src(event.path) - .pipe(plugins.connect.reload()); + .pipe(plugins.webserver.reload()); }); gulp.watch(['./app/**/*.js','!./app/**/*test.js'],['scripts']); - //gulp.watch(['!./app/index.html','./app/**/*.html'],['templates']); gulp.watch('./app/**/*.css',['css']); gulp.watch('./app/annotationclient.html',['copy-index']); gulp.watch('./data/**/*',['copy-data']); @@ -133,11 +126,13 @@ }); -gulp.task('connect', plugins.connect.server({ - root: ['build'], - port: 9000, - livereload: true -})); +gulp.task('connect', function() { + gulp.src('build').pipe( + plugins.webserver({ + port: 9000, + livereload: true + }) + ); +}); -//gulp.task('default',['connect','scripts','templates','css','copy-index','copy-data','copy-img','vendorJS','vendorCSS','vendorFonts','watch']); -gulp.task('default',['scripts','css','copy-index','copy-data','copy-img','vendorJS','vendorCSS','vendorFonts','watch']); +gulp.task('default',['scripts','css','copy-index','copy-data','copy-img','vendorJS','vendorCSS','vendorFonts']); diff -r a0f1f77148d9 -r 435d5c15275a client/package.json --- a/client/package.json Fri Oct 10 17:08:31 2014 +0200 +++ b/client/package.json Mon Oct 13 12:43:47 2014 +0200 @@ -10,24 +10,24 @@ "author": "IRI", "license": "Cecill-C", "devDependencies": { - "bower": "^1.3.4", + "bower": "^1.3.12", + "del": "^0.1.3", "grunt-cli": "^0.1.13", - "gulp": "~3.5.5", - "gulp-angular-templatecache": "^1.1.0", - "gulp-clean": "^0.3.0", - "gulp-concat": "~2.1.7", - "gulp-connect": "^1.0.7", - "gulp-csslint": "^0.1.4", + "gulp": "~3.8.8", + "gulp-angular-templatecache": "^1.4.2", + "gulp-concat": "~2.4.1", + "gulp-csslint": "^0.1.5", "gulp-filesize": "0.0.6", - "gulp-flatten": "0.0.2", - "gulp-jshint": "~1.5.0", - "gulp-load-plugins": "~0.4.0", - "gulp-minify-css": "^0.3.4", + "gulp-flatten": "0.0.4", + "gulp-jshint": "~1.8.5", + "gulp-load-plugins": "~0.7.0", + "gulp-minify-css": "^0.3.10", "gulp-rename": "^1.2.0", - "gulp-uglify": "^0.3.0", - "gulp-util": "^2.2.16", - "karma": "^0.12.1", - "karma-chrome-launcher": "^0.1.2", + "gulp-uglify": "^1.0.1", + "gulp-util": "^3.0.1", + "gulp-webserver": "^0.8.3", + "karma": "^0.12.23", + "karma-chrome-launcher": "^0.1.4", "karma-jasmine": "^0.1.5" } }