From 5e7312480b3b4707b1fc0a0081db09a3c71d753b Mon Sep 17 00:00:00 2001 From: Yasuhiro Asaka Date: Mon, 5 Mar 2012 17:34:50 +0100 Subject: [PATCH 5/5] Added drb_process switching by flavor --- bin/oddbd | 12 ++++++++++-- doc/index.rbx | 7 ++++++- src/util/flavorlizer.rb | 37 +++++++++++++++++++++++++++++++++++++ src/util/oddbconfig.rb | 22 ++++++++++++++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 src/util/flavorlizer.rb diff --git a/bin/oddbd b/bin/oddbd index a423e42..87d0ae3 100755 --- a/bin/oddbd +++ b/bin/oddbd @@ -1,10 +1,12 @@ #!/usr/bin/env ruby +# OddbServer -- oddb.org -- 05.03.2012 -- yasaka@ywesee.com # OddbServer $: << File.expand_path("../src", File.dirname(__FILE__)) $: << File.expand_path("..", File.dirname(__FILE__)) require 'drb/drb' +require 'util/flavorlizer' require 'util/currency' require 'util/oddbapp' require 'etc/db_connection' @@ -22,14 +24,20 @@ trap("USR2") { $stdout.flush } +server_uri = ODDB::Flavorlizer.server_uri_with_flavor(ARGV.first) + ODBA.cache.setup ODBA.cache.clean_prefetched $oddb = ODDB::App.new -$0 = "Oddb (OddbApp)" +if (ARGV.first.nil?) + $0 = "Oddb (OddbApp)" +else + $0 = "Oddb (OddbApp:#{ARGV.first})" +end DRb.install_id_conv ODBA::DRbIdConv.new -DRb.start_service(ODDB::SERVER_URI, $oddb) +DRb.start_service(server_uri, $oddb) DRb.thread.join diff --git a/doc/index.rbx b/doc/index.rbx index 6227145..a8c2ba0 100755 --- a/doc/index.rbx +++ b/doc/index.rbx @@ -1,15 +1,20 @@ #!/usr/bin/env ruby +# index.rbx -- oddb.org -- 05.03.2012 -- yasaka@ywesee.com # index.rbx -- oddb.org -- 21.02.2012 -- mhatakeyama@ywesee.com # index.rbx -- oddb.org -- hwyss@ywesee.com # When SBSM is updated, the SBSM lib path should also be updated require '/usr/local/lib/ruby/gems/1.9.1/gems/sbsm-1.1.4/lib/sbsm/request' require 'util/oddbconfig' +require 'util/flavorlizer' DRb.start_service('druby://localhost:0') begin - SBSM::Request.new(ODDB::SERVER_URI).process + request = SBSM::Request.new(ODDB::SERVER_URI) + flavor = request.unparsed_uri[/^\/(de|en|fr)\/([a-z\-]+)/, 2] + server_uri = ODDB::Flavorlizer.server_uri_with_flavor(flavor) + SBSM::Request.new(server_uri).process rescue Exception => e $stderr << "ODDB-Client-Error: " << e.message << "\n" $stderr << e.class << "\n" diff --git a/src/util/flavorlizer.rb b/src/util/flavorlizer.rb new file mode 100644 index 0000000..5ba7897 --- /dev/null +++ b/src/util/flavorlizer.rb @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby +# encoding: utf-8 +# Flavorlizer -- oddb.org -- 05.03.2012 -- yasaka@ywesee.com + +require 'util/oddbconfig' + +module ODDB + class Flavorlizer +=begin +* atupri +* atupri-web +* carenaschweiz +* desitin +* generika +* just-medical +* konsuminfo +* mobile +* mymedi +* mymigel +* oekk +* provita +* santesuisse +* swissmedic +* swissmedinfo +* anthroposophy +* homeopathy +* phyto-pharma +=end + def self.server_uri_with_flavor(flavor=nil) + if ODDB::FLAVORED_SERVER_URI[flavor] + ODDB::FLAVORED_SERVER_URI[flavor] + else + ODDB::SERVER_URI + end + end + end +end diff --git a/src/util/oddbconfig.rb b/src/util/oddbconfig.rb index dbbbf19..1f1ed4a 100644 --- a/src/util/oddbconfig.rb +++ b/src/util/oddbconfig.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby # encoding: utf-8 +# OddbConfig -- oddb.org -- 05.03.2012 -- yasaka@ywesee.com # OddbConfig -- oddb.org -- 11.01.2012 -- mhatakeyama@ywesee.com # OddbConfig -- oddb.org -- 09.04.2003 -- hwyss@ywesee.com @@ -31,6 +32,27 @@ module ODDB PAYPAL_SERVER = 'www.paypal.com' PAYPAL_RECEIVER = 'zdavatz@ywesee.com' ENCODING = 'UTF-8' + FLAVORED_SERVER_URI = { + 'gcc' => SERVER_URI, + 'atupri' => "druby://localhost:22220", + 'atupri-web' => "druby://localhost:22221", + 'carenaschweiz' => "druby://localhost:22222", + 'desitin' => "druby://localhost:22223", + 'generika' => "druby://localhost:22224", + 'just-medical' => "druby://localhost:22225", + 'konsuminfo' => "druby://localhost:22226", + 'mobile' => "druby://localhost:22227", + 'mymedi' => "druby://localhost:22228", + 'mymigel' => "druby://localhost:22229", + 'oekk' => "druby://localhost:22230", + 'provita' => "druby://localhost:22231", + 'santesuisse' => "druby://localhost:22232", + 'swissmedic' => "druby://localhost:22233", + 'swissmedinfo' => "druby://localhost:22234", + 'anthroposophy' => "druby://localhost:22235", + 'homeopathy' => "druby://localhost:22236", + 'phyto-pharma' => "druby://localhost:22237", + } ## Prices and Durations DOWNLOAD_EXPORT_PRICES = { 'analysis.csv' => 300, -- 1.7.3.4