diff --git a/tools/reset_styles b/tools/reset_styles index 3a475a9f..bd07d856 100755 --- a/tools/reset_styles +++ b/tools/reset_styles @@ -8,43 +8,45 @@ var mapnik = require('mapnik'); var redis = require('redis'); function usage(me, exitcode) { - console.log("Usage: " + me + " [--convert] []"); + console.log("Usage: " + me + " [--convert] "); process.exit(exitcode); } var doConvert = false; -var MAPNIK_VERSION; var node_path = process.argv.shift(); var script_path = process.argv.shift(); var me = path.basename(script_path); +var ENV; var arg; while ( arg = process.argv.shift() ) { if ( arg == '--convert' ) { doConvert = true; - } else if ( ! MAPNIK_VERSION ) { - MAPNIK_VERSION = arg; + } + else if ( ! ENV ) { + ENV = arg; } else { usage(me, 1); } } -if ( ! MAPNIK_VERSION ) { - MAPNIK_VERSION = mapnik.versions.mapnik; -} +if ( ! ENV ) usage(me, 1); + +global.environment = require('../config/environments/' + ENV); +var serverOptions = require('../lib/cartodb/server_options'); // _after_ setting global.environment + +var MAPNIK_VERSION = global.environment.mapnik_version || mapnik.versions.mapnik; console.log( (doConvert ? "Converting" : "Resetting" ) + ' all styles to target ' + MAPNIK_VERSION); -var REDIS_PORT = 6379; // TODO: make a command line parameter - var dbnum = 0; -var mml_store = new grainstore.MMLStore({port:REDIS_PORT}, {mapnik_version:MAPNIK_VERSION}); +var mml_store = new grainstore.MMLStore(serverOptions.redis, serverOptions.grainstore); var failures = []; -var client = redis.createClient(REDIS_PORT, 'localhost'); +var client = redis.createClient(serverOptions.redis.port, serverOptions.redis.host); client.on('connect', function() { client.select(dbnum); client.keys('map_style|*', function(err, matches) {