rsence 2.0.0.0.pre → 2.0.0.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/conf/default.rb CHANGED
@@ -12,6 +12,10 @@ require 'rubygems'
12
12
  require 'rack'
13
13
  require 'yaml'
14
14
 
15
+ if RUBY_VERSION.to_f >= 1.9
16
+ Encoding.default_external = Encoding::ASCII_8BIT
17
+ end
18
+
15
19
  # Legacy:
16
20
  LIB_PATHS = []
17
21
  PIDPATH = File.join(SERVER_PATH,'var','run')
@@ -20,8 +24,6 @@ def load_legacy( local_config_file_path )
20
24
  require local_config_file_path[0..-4]
21
25
  end
22
26
 
23
- module RSence
24
-
25
27
  class Configuration
26
28
  def array_merge( target, source )
27
29
  source.each do |item|
@@ -55,10 +57,21 @@ class Configuration
55
57
  end
56
58
  end
57
59
  end
58
- def initialize
60
+ def wizard
61
+ puts "Please answer the following questions, blank lines equal to the default in brackets:"
62
+ require 'conf/wizard'
63
+ if File.directory?( File.join( Dir.pwd, 'conf' ) )
64
+ wizard_conf_file = File.join( Dir.pwd, 'conf', 'local_conf.yaml' )
65
+ else
66
+ wizard_conf_file = File.join( SERVER_PATH, 'conf', 'local_conf.yaml' )
67
+ end
68
+ wizard_config_data = ConfigWizard.new(config).run( wizard_conf_file )
69
+ config.merge!( wizard_config_data )
70
+ end
71
+ def initialize(args)
59
72
  ## Paths for log and pid files
60
- pidpath = File.join(SERVER_PATH,'var','run')
61
- logpath = File.join(SERVER_PATH,'var','log')
73
+ pidpath = File.join( args[:env_path], 'run' )
74
+ logpath = File.join( args[:env_path], 'log' )
62
75
 
63
76
  yaml_conf_path = File.join( SERVER_PATH, 'conf', 'default_conf.yaml' )
64
77
 
@@ -69,8 +82,9 @@ class Configuration
69
82
  config = YAML.load( File.read( yaml_conf_path ) )
70
83
  config[:transporter_conf][:messages] = strings[:messages][:transporter]
71
84
 
72
- default_plugins_path = File.join( SERVER_PATH, 'plugins' )
85
+ config[:client_pkg][:src_dirs].unshift( File.join( SERVER_PATH, 'js' ) )
73
86
 
87
+ default_plugins_path = File.join( SERVER_PATH, 'plugins' )
74
88
  unless config[:plugin_paths].include? default_plugins_path
75
89
  config[:plugin_paths].push( default_plugins_path )
76
90
  end
@@ -84,28 +98,31 @@ class Configuration
84
98
  ## Create default local configuratation override file, if it does not exist:
85
99
  local_config_file_paths = [
86
100
  File.join(SERVER_PATH,'conf','local_conf.yaml'),
101
+ '/etc/rsence/config.yaml',
102
+ File.expand_path('~/.rsence/config.yaml'),
87
103
  File.join( File.split( SERVER_PATH )[0], 'conf', 'local_conf.yaml' ),
88
- File.join( Dir.pwd, 'conf', 'local_conf.yaml' ),
104
+ # File.join( Dir.pwd, 'conf', 'local_conf.yaml' ),
89
105
  File.join(SERVER_PATH,'conf','local_conf.rb'),
90
- File.join( File.split( SERVER_PATH )[0], 'conf', 'local_conf.rb' ),
91
- File.join( Dir.pwd, 'conf', 'local_conf.rb' )
106
+ # File.join( File.split( SERVER_PATH )[0], 'conf', 'local_conf.rb' ),
107
+ # File.join( Dir.pwd, 'conf', 'local_conf.rb' )
92
108
  ]
93
- if ARGV.include?('--config')
94
- argv_conf_file = ARGV[ARGV.index('--config')+1]
95
- if not argv_conf_file.begin_with? '/'
96
- argv_conf_file = File.join( Dir.pwd, conf_file )
97
- end
98
- local_config_file_paths.push( argv_conf_file )
109
+
110
+ args[:conf_files].each do |conf_file|
111
+ local_config_file_paths.push( conf_file )
99
112
  end
100
113
 
101
- local_config_file_path_found = false
102
114
  local_config_file_paths.each do |local_config_file_path|
103
115
  if File.exists? local_config_file_path and File.file? local_config_file_path
104
116
  if local_config_file_path.end_with? '.yaml'
117
+ puts "loading config file: #{local_config_file_path}" if args[:verbose]
105
118
  local_conf = YAML.load( File.read( local_config_file_path ) )
119
+ unless local_conf.class == Hash
120
+ warn "invalid configuration file: #{local_config_file_path.inspect}"
121
+ next
122
+ end
106
123
  hash_merge( config, local_conf )
107
- local_config_file_path_found = true
108
124
  elsif local_config_file_path.end_with? '.rb'
125
+ warn "WARNING: '.rb' configuration files are deprecated!"
109
126
  # Legacy work-arounds
110
127
  prev_pidpath = PIDPATH
111
128
  prev_logpath = LOGPATH
@@ -115,47 +132,35 @@ class Configuration
115
132
  pidpath = PIDPATH if PIDPATH != prev_pidpath
116
133
  logpath = LOGPATH if LOGPATH != prev_logpath
117
134
  # /Legacy work-arounds
118
- local_config_file_path_found = true
119
135
  else
120
136
  warn "Only Yaml and Ruby configuration files are allowed at this time."
121
137
  end
122
138
  end
123
139
  end
124
140
 
125
- if not local_config_file_path_found or ARGV.include? '--run-wizard'
126
- puts "NOTE: No local configuration file found, running the, configuration wizard." unless ARGV.include? '--run-wizard'
127
- puts "Please answer the following questions, blank lines equal to the default in brackets:"
128
- require 'conf/wizard'
129
- if File.directory?( File.join( Dir.pwd, 'conf' ) )
130
- wizard_conf_file = File.join( Dir.pwd, 'conf', 'local_conf.yaml' )
131
- else
132
- wizard_conf_file = File.join( SERVER_PATH, 'conf', 'local_conf.yaml' )
133
- end
134
- wizard_config_data = ConfigWizard.new(config).run( wizard_conf_file )
135
- config.merge!( wizard_config_data )
136
- end
137
-
138
- if not config[:database].has_key?( :ses_db ) and config[:database].has_key?( :auth_setup )
139
- warn "WARNING: The database is not configured with a :ses_db url."
140
- warn " You are advised to convert the :root_setup and :auth_setup keys of"
141
- warn " config[:database] to the new url format."
142
- db_auth = config[:database][:auth_setup]
143
- config[:database][:ses_db] = "mysql://#{db_auth[:user]}:#{db_auth[:pass]}@#{db_auth[:host]}:#{db_auth[:port]}/#{db_auth[:db]}"
144
- warn " -> Performed automatic conversion of :auth_setup as"
145
- warn " config[:database][:ses_db] = #{config[:database][:ses_db].inspect}"
141
+ env_plugins_path = File.join( args[:env_path], 'plugins' )
142
+ unless config[:plugin_paths].include? env_plugins_path
143
+ config[:plugin_paths].push( env_plugins_path )
146
144
  end
147
145
 
146
+ config[:trace] = true if args[:trace_js]
147
+ config[:debug_mode] = true if args[:debug]
148
+ config[:http_server][:latency] = args[:latency]
149
+ config[:http_server][:port] = args[:port] if args[:port]
150
+ config[:http_server][:bind_address] = args[:addr] if args[:addr]
151
+ config[:http_server][:rack_require] = args[:server] if args[:server]
152
+ config[:session_conf][:reset_sessions] = true if args[:reset_ses]
148
153
 
149
- config[:trace] = true if ARGV.include?('--trace-js')
150
- config[:debug_mode] = true if ARGV.include?('-d') or ARGV.include?('--debug')
151
- config[:http_server][:latency] = ARGV[ARGV.index('--latency')+1].to_i if ARGV.include?('--latency')
152
- config[:http_server][:port] = ARGV[ARGV.index('--port')+1].to_i if ARGV.include?('--port')
153
- config[:http_server][:bind_address] = ARGV[ARGV.index('--addr')+1] if ARGV.include?('--addr')
154
- config[:http_server][:rack_require] = ARGV[ARGV.index('--server')+1] if ARGV.include?('--server')
155
- config[:session_conf][:reset_sessions] = true if ARGV.include?('--reset-sessions=true') or ARGV.include?('--reset-sessions')
156
154
  config[:daemon][:pid_fn] = File.join(pidpath, "rsence.pid") unless config[:daemon].has_key?(:pid_fn)
157
155
  config[:daemon][:log_fn] = File.join(logpath, "rsence") unless config[:daemon].has_key?(:log_fn)
158
156
 
157
+ if config[:database][:ses_db].start_with?('sqlite://')
158
+ db_url = config[:database][:ses_db].split('sqlite://')[1]
159
+ unless db_url.start_with?('/')
160
+ db_url = File.join( args[:env_path], db_url )
161
+ config[:database][:ses_db] = "sqlite://#{db_url}"
162
+ end
163
+ end
159
164
 
160
165
  ## Broker configuration
161
166
  [ ## POST-requests
@@ -210,11 +215,5 @@ class Configuration
210
215
  end
211
216
  attr_reader :config
212
217
  end
213
- @@config = Configuration.new.config
214
- def self.config
215
- @@config
216
- end
217
-
218
- end
219
218
 
220
219