dohruby 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/bin/config.rb +61 -0
- data/bin/create_database.rb +13 -6
- data/bin/gendata.rb +37 -0
- data/bin/migrate.rb +66 -0
- data/bin/{rcov-preprocess-files.rb → rcov_preprocess_files.rb} +1 -1
- data/bin/run_tests.rb +15 -5
- data/bin/update_rdoc.rb +28 -0
- data/dohapp_home +0 -0
- data/lib/doh/app/activate_database.rb +5 -12
- data/lib/doh/app/activate_logger.rb +29 -13
- data/lib/doh/app/config.rb +18 -0
- data/lib/doh/app/home.rb +3 -8
- data/lib/doh/app/init_runnable.rb +39 -8
- data/lib/doh/app/init_script.rb +19 -0
- data/lib/doh/app/init_unit_test.rb +4 -1
- data/lib/doh/app_no_stdio.rb +1 -1
- data/lib/doh/boot/app.rb +2 -0
- data/lib/doh/boot/app_pwd.rb +2 -0
- data/lib/doh/boot/find_dohruby.rb +5 -0
- data/lib/doh/boot/find_dohruby_18.rb +37 -0
- data/lib/doh/boot/find_dohruby_19.rb +58 -0
- data/lib/doh/boot/init_runnable.rb +2 -0
- data/lib/doh/boot/options.rb +2 -0
- data/lib/doh/core/array.rb +10 -0
- data/lib/doh/core/bigdecimal.rb +15 -0
- data/lib/doh/core/date.rb +73 -0
- data/lib/doh/core/deep_dup.rb +12 -0
- data/lib/doh/core/hash.rb +21 -0
- data/lib/doh/core/object.rb +6 -0
- data/lib/doh/core/require_local.rb +5 -0
- data/lib/doh/core/socket.rb +25 -0
- data/lib/doh/core/string.rb +34 -4
- data/lib/doh/core.rb +4 -1
- data/lib/doh/data/basic.rb +24 -19
- data/lib/doh/data/bulk.rb +28 -88
- data/lib/doh/data/catalog.rb +44 -0
- data/lib/doh/data/human.rb +50 -42
- data/lib/doh/data/make_global.rb +3 -0
- data/lib/doh/data/require_datagen.rb +2 -1
- data/lib/doh/home.rb +16 -0
- data/lib/doh/logger/email_acceptor.rb +6 -3
- data/lib/doh/logger/event.rb +19 -6
- data/lib/doh/logger/formatter.rb +22 -16
- data/lib/doh/logger/interface.rb +13 -0
- data/lib/doh/logger/iostream_acceptor.rb +3 -2
- data/lib/doh/logger/null_interface.rb +1 -0
- data/lib/doh/logger/proxy.rb +53 -0
- data/lib/doh/logger/socket_acceptor.rb +53 -0
- data/lib/doh/logger/socket_viewer.rb +64 -0
- data/lib/doh/logger/standard_interface.rb +46 -17
- data/lib/doh/logger/util.rb +18 -0
- data/lib/doh/logger.rb +2 -1
- data/lib/doh/logger_configure.rb +1 -1
- data/lib/doh/merb/db_session.rb +136 -0
- data/lib/doh/merb/form_helpers.rb +16 -0
- data/lib/doh/merb/login.rb +27 -12
- data/lib/doh/merb/merb_dohsession.rb +4 -0
- data/lib/doh/merb/notify_on_exception.rb +1 -1
- data/lib/doh/merb/session.rb +7 -0
- data/lib/doh/merb/source_ip.rb +10 -0
- data/lib/doh/merb.rb +0 -1
- data/lib/doh/mysql/abstract_row.rb +81 -0
- data/lib/doh/mysql/cache_connector.rb +11 -8
- data/lib/doh/mysql/connector_instance.rb +32 -5
- data/lib/doh/mysql/connector_util.rb +1 -0
- data/lib/doh/mysql/convert.rb +18 -0
- data/lib/doh/mysql/database_creator.rb +18 -5
- data/lib/doh/mysql/db_date.rb +2 -2
- data/lib/doh/mysql/default_type_guesser.rb +21 -4
- data/lib/doh/mysql/error.rb +3 -2
- data/lib/doh/mysql/handle.rb +144 -18
- data/lib/doh/mysql/hash_row.rb +13 -0
- data/lib/doh/mysql/load_sql.rb +1 -0
- data/lib/doh/mysql/metadata_util.rb +60 -19
- data/lib/doh/mysql/migrate.rb +122 -0
- data/lib/doh/mysql/migrate_check.rb +139 -0
- data/lib/doh/mysql/parse.rb +2 -0
- data/lib/doh/mysql/readonly_row.rb +11 -48
- data/lib/doh/mysql/require_dbtypes.rb +8 -0
- data/lib/doh/mysql/smart_row.rb +156 -0
- data/lib/doh/mysql/to_sql.rb +12 -0
- data/lib/doh/mysql/typed_row_builder.rb +4 -3
- data/lib/doh/mysql/types.rb +33 -0
- data/lib/doh/mysql/unquoted.rb +8 -0
- data/lib/doh/mysql/version.rb +102 -0
- data/lib/doh/mysql/virtual.rb +17 -0
- data/lib/doh/mysql/writable_row.rb +58 -0
- data/lib/doh/mysql.rb +2 -1
- data/lib/doh/paypal/paypal.rb +20 -0
- data/lib/doh/paypal/pdt.rb +14 -0
- data/lib/doh/paypal.rb +1 -0
- data/lib/doh/rails/form_helpers.rb +53 -0
- data/lib/doh/rails/login.rb +143 -0
- data/lib/doh/test/error_acceptor.rb +1 -1
- data/lib/doh/test/run_tests.rb +48 -43
- data/lib/doh/test/setup_once.rb +15 -0
- data/lib/doh/test/test_result.rb +7 -0
- data/lib/doh/unit_test.rb +6 -0
- data/lib/doh/util/banking_workday.rb +16 -12
- data/lib/doh/util/class_basename.rb +10 -0
- data/lib/doh/util/current_date.rb +18 -41
- data/lib/doh/util/doh_socket.rb +56 -0
- data/lib/doh/util/email.rb +18 -0
- data/lib/doh/util/file_edit.rb +64 -0
- data/lib/doh/util/http_helper.rb +107 -0
- data/lib/doh/util/internal_ip.rb +1 -1
- data/lib/doh/util/jsval.rb +13 -0
- data/lib/doh/util/post_hash.rb +14 -0
- data/lib/doh/util/xml_util.rb +48 -0
- data/test/core/tc_array.rb +12 -0
- data/test/core/tc_date.rb +53 -0
- data/test/core/tc_deep_dup.rb +69 -0
- data/test/core/tc_hash.rb +28 -0
- data/test/core/tc_socket.rb +30 -0
- data/test/core/tc_string.rb +15 -22
- data/test/local_tests.rb +3 -0
- data/test/local_tests_including_slow.rb +4 -0
- data/test/logger/tc_acceptor.rb +23 -6
- data/test/logger/tc_event.rb +1 -1
- data/test/logger/tc_formatter.rb +3 -2
- data/test/logger/tc_socket_viewer_acceptor.rb +48 -0
- data/test/mysql/001_down.sql +1 -0
- data/test/mysql/001_up.sql +4 -0
- data/test/mysql/002_down.sql +1 -0
- data/test/mysql/002_up.sql +1 -0
- data/test/mysql/tc_connector_instance.rb +8 -8
- data/test/mysql/tc_convert.rb +45 -0
- data/test/mysql/tc_handle.rb +94 -2
- data/test/mysql/tc_metadata_util.rb +50 -0
- data/test/mysql/tc_migrate.rb +50 -0
- data/test/mysql/tc_parse.rb +3 -1
- data/test/mysql/tc_readonly_row.rb +14 -10
- data/test/mysql/tc_smart_row.rb +22 -0
- data/test/mysql/tc_to_sql.rb +20 -0
- data/test/mysql/tc_types.rb +32 -0
- data/test/mysql/tc_unquoted.rb +1 -0
- data/test/mysql/tc_writable_row.rb +22 -0
- data/test/ts_core.rb +4 -0
- data/test/ts_logger.rb +4 -0
- data/test/ts_mysql.rb +6 -0
- data/test/ts_util.rb +6 -0
- data/test/util/slow_doh_socket.rb +102 -0
- data/test/util/tc_banking_workday.rb +18 -0
- data/test/util/tc_file_edit.rb +54 -0
- data/test/util/tc_jsval.rb +12 -0
- data/test/util/tc_to_display.rb +14 -0
- data/test/util/tc_xml_util.rb +17 -0
- metadata +130 -39
- data/README +0 -4
- data/lib/doh/merb/post_hash.rb +0 -26
- data/lib/doh/mysql/db_null.rb +0 -24
- data/lib/doh/mysql/hash_util.rb +0 -56
- data/test/mysql/tc_hash_util.rb +0 -23
data/CHANGELOG
CHANGED
@@ -121,3 +121,11 @@
|
|
121
121
|
* added create_database.rb to deploy executables list
|
122
122
|
*0.2.1* (Jun 20th, 2008)
|
123
123
|
* added util/to_display
|
124
|
+
*0.2.2*
|
125
|
+
* simplify Dir related code
|
126
|
+
* doh/mysql - merge hash_util into Handle class
|
127
|
+
* doh/mysql - misc Handle tweaks, enhancements
|
128
|
+
* moved post_hash to doh/util from doh/merb
|
129
|
+
* added get_required_config_value that raises if the value doesn't exist in the config (with description of error)
|
130
|
+
* added xml_util for hash to xml, vice versa, and http_handler
|
131
|
+
|
data/bin/config.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'doh/boot/app_pwd'
|
3
|
+
|
4
|
+
opts = DohApp::Options.new(
|
5
|
+
{'check' => [false, "-c", "--check", "checks for the presence of all listed config keys. exits with non-zero status code if any are missing"] \
|
6
|
+
,'file' => [nil, "-f", "--file <filename>", "filename to read the config key names from"] \
|
7
|
+
,'show' => [false, "-s", "--show", "shows a list of defined config entries"] \
|
8
|
+
,'keys' => [false, "-k", "--keys", "shows a list of defined config keys (useful for generating a file to read from)"] \
|
9
|
+
}, true, 'list of config keys. only used with some options. nested keys are not yet supported, but ultimately will be in path style.')
|
10
|
+
|
11
|
+
class DisplayConfig
|
12
|
+
def self.run
|
13
|
+
DohApp::config.keys.sort.each do |key|
|
14
|
+
nested(key, DohApp::config[key])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def self.nested(top_key, top_obj, tab_level = 0)
|
20
|
+
indent = ' ' * (tab_level * 2)
|
21
|
+
if top_obj.is_a?(Hash)
|
22
|
+
puts "#{indent}#{top_key}:"
|
23
|
+
top_obj.keys.each {|key| nested(key, top_obj[key], tab_level + 1)}
|
24
|
+
else
|
25
|
+
puts "#{indent}#{top_key} -> #{top_obj.inspect}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class CheckConfig
|
31
|
+
def self.run(keys_to_check)
|
32
|
+
missing = []
|
33
|
+
keys_to_check.each do |key|
|
34
|
+
missing.push(key) unless DohApp::config.key?(key)
|
35
|
+
end
|
36
|
+
|
37
|
+
if missing.empty?
|
38
|
+
puts "checked #{keys_to_check.size} keys; all are present"
|
39
|
+
exit 0
|
40
|
+
else
|
41
|
+
puts "failing due to missing keys: #{missing.join(',')}"
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if opts.show
|
48
|
+
DisplayConfig.run
|
49
|
+
elsif opts.keys
|
50
|
+
DohApp::config.keys.sort.each { |key| puts key }
|
51
|
+
elsif opts.check
|
52
|
+
if opts.file
|
53
|
+
keys_to_check = []
|
54
|
+
File.new(opts.file, 'r').each_line { |line| keys_to_check.push(line.chomp) }
|
55
|
+
else
|
56
|
+
keys_to_check = opts.varargs
|
57
|
+
end
|
58
|
+
CheckConfig.run(keys_to_check)
|
59
|
+
else
|
60
|
+
puts opts
|
61
|
+
end
|
data/bin/create_database.rb
CHANGED
@@ -1,20 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'doh/app_pwd'
|
2
|
+
require 'doh/boot/app_pwd'
|
3
3
|
require 'doh/mysql/database_creator'
|
4
4
|
|
5
5
|
opts = DohApp::Options.new(
|
6
|
-
{'drop_first' => [false, "-z", "--drop_first", "if true, will drop the database before creating
|
7
|
-
,'database' => [DohApp::config['primary_database'], "-d", "--database <database>", "name of the database
|
6
|
+
{'drop_first' => [false, "-z", "--drop_first", "if true, will drop the database or tables before creating"] \
|
7
|
+
,'database' => [DohApp::config['primary_database'], "-d", "--database <database>", "name of the source database -- defaults to config['primary_database'], currently '#{DohApp::config['primary_database']}'"] \
|
8
8
|
,'all' => [false, "-a", "--all", "create all databases"] \
|
9
|
+
,'target' => [DohApp::config['target_database'], "-g", "--target <database>", "name of the target database -- defaults to same as source"] \
|
10
|
+
,'tables' => [nil, "-t", "--tables <tables>", "comma-delimited list of tables to create; if specified, no databases are dropped or created"]
|
9
11
|
})
|
10
12
|
|
11
|
-
if opts.database.to_s.empty?
|
12
|
-
puts "You must specify a database (either here with -d or in your config)"
|
13
|
+
if opts.database.to_s.empty? && !opts.all
|
14
|
+
puts "You must specify a database (either here with -d or in your config) or all (with -a)"
|
13
15
|
exit 1
|
14
16
|
end
|
17
|
+
|
15
18
|
db_creator = DohDb::DatabaseCreator.new
|
16
|
-
if opts.
|
19
|
+
if opts.tables
|
20
|
+
db_creator.create_tables(opts.database, opts.drop_first, opts.tables.split(/,/))
|
21
|
+
elsif opts.all
|
17
22
|
db_creator.create_all_databases(opts.drop_first)
|
23
|
+
elsif opts.target
|
24
|
+
db_creator.create_database_copy(opts.target, opts.database, opts.drop_first)
|
18
25
|
else
|
19
26
|
db_creator.create_database(opts.database, opts.drop_first)
|
20
27
|
end
|
data/bin/gendata.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'doh/boot/app_pwd'
|
3
|
+
require 'doh/data/catalog'
|
4
|
+
require 'doh/data/require_datagen'
|
5
|
+
require 'doh/mysql/connector_util'
|
6
|
+
DohData::require_datagen
|
7
|
+
|
8
|
+
opts = DohApp::Options.new(
|
9
|
+
{'target' => [DohApp::config['primary_database'], "-g", "--target <database>", "name of the target database -- defaults to config['primary_database'], currently '#{DohApp::config['primary_database']}'"] \
|
10
|
+
,'count' => [1, "-c", "--count <amount>", "how many to create"] \
|
11
|
+
}, true, 'list of catalog entries to create')
|
12
|
+
|
13
|
+
if opts.varargs.size == 0
|
14
|
+
DohData::catalog_list.each {|elem| puts elem }
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
if opts.target
|
19
|
+
DohDb::reconfigure_connector({'database' => opts.target})
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.varargs.each do |entry|
|
23
|
+
klass = DohData::search_catalog(entry)
|
24
|
+
if klass.nil?
|
25
|
+
puts "unable to find data object matching: #{entry}"
|
26
|
+
else
|
27
|
+
Doh::disable_logging
|
28
|
+
opts.count.to_i.times do
|
29
|
+
begin
|
30
|
+
klass.new.save_to_database
|
31
|
+
# rescue Exception => excpt
|
32
|
+
# puts "ignoring exception: #{excpt.inspect}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/bin/migrate.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'doh/boot/app_pwd'
|
3
|
+
require 'doh/mysql/migrate'
|
4
|
+
require 'doh/mysql/version'
|
5
|
+
require 'doh/mysql/migrate_check'
|
6
|
+
|
7
|
+
opts = DohApp::Options.new(
|
8
|
+
{'database' => [DohApp::config['primary_database'], "-d", "--database <database>", "name of the database to migrate -- defaults to config['primary_database'], currently '#{DohApp::config['primary_database']}'"] \
|
9
|
+
,'all' => [false, "-a", "--all", "operate on all databases"] \
|
10
|
+
,'update' => [true, "-u", "--update", "migrate to the latest version (this is the default action)"] \
|
11
|
+
,'rollback' => [nil, "-r", "--rollback", "rollback one version"] \
|
12
|
+
,'version' => [nil, "-v", "--version <version>", "migrate to a specific version"] \
|
13
|
+
,'check' => [false, "-c", "--check", "check the current unlocked migration for validity (no migrations will take place)"] \
|
14
|
+
,'lock' => [false, "-l", "--lock", "lock the current unlocked migration, if any (no migrations will take place)"] \
|
15
|
+
,'make_new' => [false, "-m", "--make-new", "make a new unlocked migration (or return the filenames of the current one if one already exists)"] \
|
16
|
+
})
|
17
|
+
|
18
|
+
if opts.database.to_s.empty? && !opts.all
|
19
|
+
puts "You must specify a database (either here with -d or in your config) or all (with -a)"
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
if opts.all
|
24
|
+
database_ary = Dir.directories(File.join(DohApp::home, 'database'))
|
25
|
+
else
|
26
|
+
database_ary = [opts.database]
|
27
|
+
end
|
28
|
+
|
29
|
+
database_ary.each do |database|
|
30
|
+
if opts.check || opts.lock || opts.make_new
|
31
|
+
if opts.check
|
32
|
+
success, msg = DohDb::MigrateChecker.new(database).run
|
33
|
+
elsif opts.lock
|
34
|
+
success, msg = DohDb::update_locked_file(database)
|
35
|
+
elsif opts.make_new
|
36
|
+
success, msg = DohDb::DatabaseMigrator.new(database).get_unlocked_migration
|
37
|
+
end
|
38
|
+
|
39
|
+
if success
|
40
|
+
puts "'#{database}': succcess - " + msg
|
41
|
+
else
|
42
|
+
puts "***************** FAILURE for '#{database}' **********************"
|
43
|
+
puts msg
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
|
47
|
+
next
|
48
|
+
end
|
49
|
+
|
50
|
+
dbmigrator = DohDb::DatabaseMigrator.new(database)
|
51
|
+
fret = if opts.version
|
52
|
+
dbmigrator.make_version(opts.version.to_i)
|
53
|
+
elsif opts.rollback
|
54
|
+
dbmigrator.rollback
|
55
|
+
else
|
56
|
+
dbmigrator.update
|
57
|
+
end
|
58
|
+
|
59
|
+
if fret.nil?
|
60
|
+
dohlog.info("'#{database}': no migration occurred")
|
61
|
+
else
|
62
|
+
msg = "'#{database}': version migrated from #{fret.first} to #{fret.last}"
|
63
|
+
dohlog.notify(msg)
|
64
|
+
puts msg
|
65
|
+
end
|
66
|
+
end
|
data/bin/run_tests.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'doh/
|
2
|
+
require 'doh/boot/options'
|
3
3
|
|
4
4
|
opts = DohApp::Options.new(
|
5
5
|
{'filter' => [nil, "-f", "--filter <name>", "name or partial name of test method(s) to execute."] \
|
6
6
|
,'force_production' => [false, "-p", "--force_production", "override config to run only production (p, q) tests."] \
|
7
|
-
,'force_development' => [false, "-d", "--force_development", "override config to run only dev (d, p
|
7
|
+
,'force_development' => [false, "-d", "--force_development", "override config to run only dev (d, p) tests."] \
|
8
|
+
,'run_slow_tests' => [false, "-s", "--run_slow_tests", "runs slow tests."] \
|
8
9
|
,'repeat' => [1, "-r", "--repeat <times>", "number of times to repeat the tests."] \
|
10
|
+
,'growl_notify' => [false, "-g", "--growl", "notifies via growl if something fails"] \
|
11
|
+
,'seed' => [(Time.new.to_f * 1000).to_i, "-v", "--seed <seed_value>", "random seed"] \
|
9
12
|
}, true, 'Files or directories may be specified to run tests on. Directories will be treated recursively. Defaults to the current directory.')
|
10
13
|
|
11
14
|
def get_args_without_repeat(argv)
|
@@ -41,11 +44,18 @@ if repeat_count > 1
|
|
41
44
|
end
|
42
45
|
else
|
43
46
|
require 'doh/app/init_unit_test'
|
44
|
-
require 'doh/test/run_tests'
|
45
47
|
DohApp::init_unit_test(start_dir)
|
48
|
+
require 'doh/test/run_tests'
|
49
|
+
dohlog.info("*******Using seed: #{opts.seed} for this test run")
|
50
|
+
srand(opts.seed.to_i)
|
51
|
+
|
46
52
|
prod_flag = (DohApp::config['include_production_tests'] || opts.force_production) && !opts.force_development
|
53
|
+
ran_tests = false
|
47
54
|
args.each do |arg|
|
48
|
-
DohTest::run_tests(arg, prod_flag, opts.filter)
|
55
|
+
ran_tests = DohTest::run_tests(arg, prod_flag, opts.run_slow_tests, opts.filter, opts.growl_notify) || ran_tests
|
56
|
+
end
|
57
|
+
if !ran_tests
|
58
|
+
puts "No files were loaded."
|
59
|
+
exit(1)
|
49
60
|
end
|
50
61
|
end
|
51
|
-
|
data/bin/update_rdoc.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'doh/boot/app_pwd'
|
3
|
+
require 'doh/core/dir'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
class UpdateRdoc
|
7
|
+
def run
|
8
|
+
do_subdir('lib')
|
9
|
+
apps_dir = File.join(DohApp::home, 'apps')
|
10
|
+
if File.directory?(apps_dir)
|
11
|
+
Dir.directories(apps_dir).each { |elem| do_subdir('apps/' + elem) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def do_subdir(dest_subdir, src_subdir = nil)
|
17
|
+
src_dir = File.join(DohApp::home, src_subdir || dest_subdir)
|
18
|
+
return unless File.directory?(src_dir)
|
19
|
+
FileUtils::cd(src_dir)
|
20
|
+
|
21
|
+
dest_dir = File.join(DohApp::home, 'doc/source', dest_subdir)
|
22
|
+
cmd = "rdoc -aq -S --op #{dest_dir}"
|
23
|
+
dohlog.debug("executing: #{cmd}")
|
24
|
+
`#{cmd}`
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
UpdateRdoc.new.run
|
data/dohapp_home
ADDED
File without changes
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'doh/app/config'
|
2
|
-
require 'doh/mysql'
|
3
2
|
|
4
3
|
module DohApp
|
5
4
|
|
@@ -9,19 +8,13 @@ def self.activate_database
|
|
9
8
|
return unless root_cfg.key?('database')
|
10
9
|
db_cfg = root_cfg['database']
|
11
10
|
require 'doh/mysql'
|
11
|
+
require 'doh/mysql/require_dbtypes'
|
12
12
|
conn = DohDb::CacheConnector.new(db_cfg['host'], db_cfg['username'], db_cfg['password'], db_cfg['database'] || root_cfg['primary_database'])
|
13
|
-
|
14
|
-
if
|
15
|
-
|
16
|
-
elsif row_builder == 'typed'
|
17
|
-
require 'doh/mysql/typed_row_builder'
|
18
|
-
conn.row_builder = DohDb::TypedRowBuilder
|
19
|
-
elsif row_builder == 'raw'
|
20
|
-
# that's the default for the CacheConnector, don't need to do anything
|
21
|
-
else
|
22
|
-
raise "unrecognized database row_builder: #{row_builder.inspect}"
|
23
|
-
end
|
13
|
+
conn.port = db_cfg['port']
|
14
|
+
conn.timeout = db_cfg['timeout'].to_i if db_cfg['timeout']
|
15
|
+
conn.row_builder = db_cfg['row_builder'] || root_cfg['row_builder']
|
24
16
|
DohDb::set_connector_instance(conn)
|
17
|
+
DohDb::require_dbtypes
|
25
18
|
end
|
26
19
|
|
27
20
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'doh/app/config'
|
2
2
|
require 'doh/logger/severity'
|
3
|
+
require 'doh/logger/socket_acceptor'
|
3
4
|
|
4
5
|
module DohApp
|
5
6
|
|
@@ -25,39 +26,54 @@ def self.activate_logger
|
|
25
26
|
|
26
27
|
# initialize logfile_name here, so it can be used later in the email acceptors below
|
27
28
|
logfile_name = 'none'
|
28
|
-
if
|
29
|
-
|
29
|
+
if logger_cfg['enable_file_acceptor']
|
30
|
+
acceptor_cfg = logger_cfg['file_acceptor']
|
31
|
+
logfile_name = acceptor_cfg['filename']
|
32
|
+
if !logfile_name.nil?
|
33
|
+
# don't set it
|
34
|
+
elsif acceptor_cfg.fetch('unique_filename', false)
|
30
35
|
logfile_name = File.basename($PROGRAM_NAME, '.rb') + ".#{Process.pid}" + '.log'
|
31
36
|
else
|
32
37
|
logfile_name = File.basename($PROGRAM_NAME, '.rb') + '.log'
|
33
38
|
end
|
39
|
+
logfile_name = File.join(acceptor_cfg['log_directory'], logfile_name) if acceptor_cfg['log_directory']
|
34
40
|
logfile = File.new(logfile_name, "w+")
|
35
41
|
logfile.sync = true if acceptor_cfg.fetch('flush', false)
|
36
42
|
file_acceptor = DohLogger::IOStreamAcceptor.new(logfile)
|
37
43
|
file_acceptor.flush_always if acceptor_cfg.fetch('flush', false)
|
38
|
-
Doh::log.add_acceptor(translate_logger_level(acceptor_cfg.fetch('severity', 'debug')), file_acceptor)
|
44
|
+
Doh::log.add_acceptor(translate_logger_level(acceptor_cfg.fetch('severity', 'debug')), file_acceptor, nil, acceptor_cfg['locations_to_exclude'], acceptor_cfg['include_only_locations'])
|
39
45
|
end
|
40
46
|
|
41
|
-
if
|
42
|
-
|
47
|
+
if logger_cfg['enable_socket_acceptor']
|
48
|
+
acceptor_cfg = logger_cfg['socket_acceptor']
|
49
|
+
socket_acceptor = DohLogger::SocketAcceptor.new(acceptor_cfg.fetch('ip_addr', '127.0.0.1'), acceptor_cfg.fetch('port', DohLogger::SocketAcceptor::default_port))
|
50
|
+
Doh::log.add_acceptor(translate_logger_level(acceptor_cfg.fetch('severity', 'debug')), socket_acceptor, nil, acceptor_cfg['locations_to_exclude'], acceptor_cfg['include_only_locations'])
|
43
51
|
end
|
44
52
|
|
45
|
-
if
|
53
|
+
if logger_cfg['enable_stdout_acceptor']
|
54
|
+
acceptor_cfg = logger_cfg['stdout_acceptor']
|
55
|
+
locations_to_exclude = acceptor_cfg.key?('locations_to_exclude') ? acceptor_cfg['locations_to_exclude'] : ['DohDb']
|
56
|
+
Doh::log.add_acceptor(translate_logger_level(acceptor_cfg.fetch('severity', 'debug')), DohLogger::IOStreamAcceptor.new, nil, locations_to_exclude, acceptor_cfg['include_only_locations'])
|
57
|
+
end
|
58
|
+
|
59
|
+
if logger_cfg['enable_notify_acceptor']
|
60
|
+
acceptor_cfg = logger_cfg['notify_acceptor']
|
46
61
|
require 'doh/logger/email_acceptor'
|
47
|
-
mail_server = root_cfg['mail_server'] || 'mail.' +
|
48
|
-
from_address = acceptor_cfg['from_address'] || 'notify@' +
|
62
|
+
mail_server = root_cfg['mail_server'] || 'mail.' + get_required_config_value('domain_name', 'mail_server or domain_name required for mail server')
|
63
|
+
from_address = acceptor_cfg['from_address'] || 'notify@' + get_required_config_value('domain_name', 'from_address or domain_name required for notification email address')
|
49
64
|
to_address_list = acceptor_cfg['to_address_list'] || ['root@localhost']
|
50
65
|
notify_acceptor = DohLogger::EmailAcceptor.new(mail_server, from_address, to_address_list, logfile_name, nil, DohLogger::exceptionless_email_format)
|
51
|
-
Doh::log.add_acceptor(DohLogger::NOTIFY, notify_acceptor, true)
|
66
|
+
Doh::log.add_acceptor(DohLogger::NOTIFY, notify_acceptor, true, acceptor_cfg['locations_to_exclude'], acceptor_cfg['include_only_locations'])
|
52
67
|
end
|
53
68
|
|
54
|
-
if
|
69
|
+
if logger_cfg['enable_error_acceptor']
|
70
|
+
acceptor_cfg = logger_cfg['error_acceptor']
|
55
71
|
require 'doh/logger/email_acceptor'
|
56
|
-
mail_server = root_cfg['mail_server'] || 'mail.' +
|
57
|
-
from_address = acceptor_cfg['from_address'] || 'error@' +
|
72
|
+
mail_server = root_cfg['mail_server'] || 'mail.' + get_required_config_value('domain_name', 'mail_server or domain_name required for mail server')
|
73
|
+
from_address = acceptor_cfg['from_address'] || 'error@' + get_required_config_value('domain_name', 'from_address or domain_name required for notification email address')
|
58
74
|
to_address_list = acceptor_cfg['to_address_list'] || ['root@localhost']
|
59
75
|
error_acceptor = DohLogger::EmailAcceptor.new(mail_server, from_address, to_address_list, logfile_name)
|
60
|
-
Doh::log.add_acceptor(DohLogger::ERROR, error_acceptor)
|
76
|
+
Doh::log.add_acceptor(DohLogger::ERROR, error_acceptor, nil, acceptor_cfg['locations_to_exclude'], acceptor_cfg['include_only_locations'])
|
61
77
|
end
|
62
78
|
end
|
63
79
|
|
data/lib/doh/app/config.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'doh/app/home'
|
2
|
+
require 'doh/logger/socket_acceptor'
|
2
3
|
|
3
4
|
module DohApp
|
4
5
|
|
@@ -13,4 +14,21 @@ def self.config
|
|
13
14
|
@@config
|
14
15
|
end
|
15
16
|
|
17
|
+
def self.get_required_config_value(value, desc)
|
18
|
+
raise "Attempt to get configuration value: #{value.inspect}, but none exists. #{desc}" if !config.key?(value)
|
19
|
+
config[value]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.enable_notifies
|
23
|
+
logger_cfg = @@config['logger']
|
24
|
+
logger_cfg['enable_notify_acceptor'] = true
|
25
|
+
logger_cfg['enable_error_acceptor'] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.enable_socket_acceptor(port = DohLogger::SocketAcceptor::default_port)
|
29
|
+
logger_cfg = @@config['logger']
|
30
|
+
logger_cfg['enable_socket_acceptor'] = true
|
31
|
+
logger_cfg['socket_acceptor']['port'] = port
|
32
|
+
end
|
33
|
+
|
16
34
|
end
|
data/lib/doh/app/home.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'doh/home'
|
2
|
+
|
1
3
|
module DohApp
|
2
4
|
|
3
5
|
def self.home
|
@@ -6,14 +8,7 @@ def self.home
|
|
6
8
|
end
|
7
9
|
|
8
10
|
def self.find_home(dir, max_tries = 20)
|
9
|
-
|
10
|
-
raise "unable to find a DohApp home" if (path == '/') || (max_tries <= 0)
|
11
|
-
|
12
|
-
if File.exist?(File.join(path, 'dohapp_home'))
|
13
|
-
@@home = path
|
14
|
-
else
|
15
|
-
find_home(File.join(path, '..'), max_tries - 1)
|
16
|
-
end
|
11
|
+
@@home = Doh::find_file_in_parents(dir, 'dohapp_home', max_tries = 20)
|
17
12
|
end
|
18
13
|
|
19
14
|
end
|
@@ -6,12 +6,25 @@ module DohApp
|
|
6
6
|
|
7
7
|
def self.use_default_runnable_production_config
|
8
8
|
root_cfg = DohApp::config
|
9
|
-
|
9
|
+
logger_cfg = {}
|
10
|
+
|
11
|
+
logger_cfg['file_acceptor'] = {'unique_filename' => true, 'flush' => false, 'severity' => 'debug'}
|
12
|
+
logger_cfg['enable_file_acceptor'] = true
|
13
|
+
|
10
14
|
email_acceptor_cfg = {'to_address_list' => ["notify@#{DohApp::config['domain_name']}"]}
|
11
|
-
logger_cfg
|
15
|
+
logger_cfg['notify_acceptor'] = email_acceptor_cfg
|
16
|
+
logger_cfg['error_acceptor'] = email_acceptor_cfg.dup
|
17
|
+
logger_cfg['enable_notify_acceptor'] = true
|
18
|
+
logger_cfg['enable_error_acceptor'] = true
|
19
|
+
logger_cfg['stdout_acceptor'] = {'severity' => 'debug'}
|
20
|
+
logger_cfg['enable_stdout_acceptor'] = false
|
21
|
+
logger_cfg['socket_acceptor'] = {'severity' => 'info'}
|
22
|
+
logger_cfg['enable_socket_acceptor'] = false
|
23
|
+
|
12
24
|
root_cfg['logger'] = logger_cfg
|
13
25
|
root_cfg['enable_logger'] = true
|
14
26
|
root_cfg['host_files_directory'] = '/etc'
|
27
|
+
root_cfg['environment'] = 'production'
|
15
28
|
|
16
29
|
require 'doh/util/internal_ip'
|
17
30
|
Doh::set_source_ip(Doh::internal_ip)
|
@@ -19,14 +32,27 @@ end
|
|
19
32
|
|
20
33
|
def self.use_default_runnable_development_config
|
21
34
|
root_cfg = DohApp::config
|
22
|
-
|
23
|
-
|
24
|
-
logger_cfg = {'
|
35
|
+
logger_cfg = {}
|
36
|
+
|
37
|
+
logger_cfg['file_acceptor'] = {'unique_filename' => false, 'flush' => true, 'severity' => 'debug'}
|
38
|
+
logger_cfg['enable_file_acceptor'] = true
|
39
|
+
|
40
|
+
email_acceptor_cfg = {'to_address_list' => ['root@localhost']}
|
41
|
+
logger_cfg['notify_acceptor'] = email_acceptor_cfg
|
42
|
+
logger_cfg['error_acceptor'] = email_acceptor_cfg.dup
|
43
|
+
logger_cfg['enable_notify_acceptor'] = false
|
44
|
+
logger_cfg['enable_error_acceptor'] = false
|
45
|
+
logger_cfg['stdout_acceptor'] = {'severity' => 'debug'}
|
46
|
+
logger_cfg['enable_stdout_acceptor'] = true
|
47
|
+
logger_cfg['socket_acceptor'] = {'severity' => 'debug'}
|
48
|
+
logger_cfg['enable_socket_acceptor'] = false
|
49
|
+
|
25
50
|
root_cfg['logger'] = logger_cfg
|
26
51
|
root_cfg['enable_logger'] = true
|
27
52
|
root_cfg['host_files_directory'] = '~/.dohruby'
|
28
53
|
root_cfg['mail_server'] = 'localhost'
|
29
54
|
root_cfg['database'] = {'username' => 'root', 'host' => 'localhost'}
|
55
|
+
root_cfg['environment'] = 'development'
|
30
56
|
|
31
57
|
Doh::set_source_ip('127.0.0.1')
|
32
58
|
end
|
@@ -40,7 +66,13 @@ def self.init_runnable(file_or_directory, block = nil)
|
|
40
66
|
end
|
41
67
|
block.call(DohApp::config) if block
|
42
68
|
DohApp::activate_logger
|
43
|
-
DohApp::
|
69
|
+
unless DohApp::config['dont_activate_database']
|
70
|
+
DohApp::activate_database
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.init_runnable_dir(file_or_directory, &block)
|
75
|
+
DohApp::init_runnable(file_or_directory, block)
|
44
76
|
end
|
45
77
|
|
46
78
|
def self.init_runnable_prog(&block)
|
@@ -48,8 +80,7 @@ def self.init_runnable_prog(&block)
|
|
48
80
|
end
|
49
81
|
|
50
82
|
def self.init_runnable_pwd(&block)
|
51
|
-
|
52
|
-
init_runnable(FileUtils::pwd, block)
|
83
|
+
init_runnable(Dir.pwd, block)
|
53
84
|
end
|
54
85
|
|
55
86
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#this is for non-database applications that want logging
|
2
|
+
#in order to enable database, call DohApp::activate_database
|
3
|
+
|
4
|
+
require 'doh/app/init_runnable'
|
5
|
+
require 'doh/app/options'
|
6
|
+
home = ENV['DOH_HOME'] || '/etc/doh'
|
7
|
+
homefile = File.join(home, 'dohapp_home')
|
8
|
+
if !File.exists?(homefile)
|
9
|
+
raise "a file: '#{homefile}' must exist in a directory where you can create configuration information -- the file can be empty"
|
10
|
+
end
|
11
|
+
logdir = ENV['DOH_LOG_DIR'] || File.join(home, 'logs')
|
12
|
+
if !File.exists?(logdir)
|
13
|
+
raise "a directory: '#{logdir}' must exist for logs"
|
14
|
+
end
|
15
|
+
|
16
|
+
DohApp::init_runnable_dir(home) do |config|
|
17
|
+
config['logger']['file_acceptor']['log_directory'] = logdir
|
18
|
+
config['dont_activate_database'] = true
|
19
|
+
end
|
@@ -5,10 +5,12 @@ module DohApp
|
|
5
5
|
def self.use_default_unit_test_development_config
|
6
6
|
DohApp::config['database'] = {'username' => 'root', 'host' => 'localhost'}
|
7
7
|
DohApp::config['include_production_tests'] = false
|
8
|
+
DohApp::config['environment'] = 'development'
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.use_default_unit_test_production_config
|
11
|
-
|
12
|
+
DohApp::config['include_production_tests'] = true
|
13
|
+
DohApp::config['environment'] = 'production'
|
12
14
|
end
|
13
15
|
|
14
16
|
def self.init_unit_test(file_or_directory)
|
@@ -18,6 +20,7 @@ def self.init_unit_test(file_or_directory)
|
|
18
20
|
DohApp::use_default_unit_test_development_config
|
19
21
|
end
|
20
22
|
end
|
23
|
+
DohApp::config['testing'] = true
|
21
24
|
end
|
22
25
|
|
23
26
|
end
|
data/lib/doh/app_no_stdio.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'doh/app/init_runnable'
|
2
|
-
DohApp::init_runnable_prog {|cfg| cfg['logger']
|
2
|
+
DohApp::init_runnable_prog { |cfg| cfg['logger']['enable_stdout_acceptor'] = false }
|
data/lib/doh/boot/app.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module DohBoot
|
2
|
+
|
3
|
+
@@start_path = nil
|
4
|
+
#we want to start looking for dohruby at the first non-require file after we've seen doh/boot
|
5
|
+
current_caller = caller
|
6
|
+
seen_doh_boot = false
|
7
|
+
current_caller.each_with_index do |path, index|
|
8
|
+
seen_doh_boot ||= (path =~ /doh\/boot/)
|
9
|
+
current_caller[index] =~ /^([^:]*):/
|
10
|
+
currentfile = $1
|
11
|
+
current_caller[index+1] =~ /^([^:]*):/
|
12
|
+
nextfile = $1
|
13
|
+
if !@@start_path && seen_doh_boot && path =~ /require\.rb\:\d+\:in \`require\'$/ && (nextfile != currentfile) && (current_caller[index+1] =~ /.*\d+$/)
|
14
|
+
@@start_path = nextfile
|
15
|
+
break
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find_dohruby_in_parents(dir, max_tries = 20)
|
20
|
+
path = File.expand_path(dir)
|
21
|
+
raise "unable to find dohruby" if (path == '/') || (max_tries <= 0)
|
22
|
+
|
23
|
+
if File.exist?(File.join(path, 'dohruby'))
|
24
|
+
return File.join(path, 'dohruby')
|
25
|
+
else
|
26
|
+
return find_dohruby_in_parents(File.join(path, '..'), max_tries - 1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if !$LOAD_PATH.find {|dir| dir =~ /dohruby\/lib/}
|
31
|
+
dohruby_path = DohBoot::find_dohruby_in_parents(File.dirname(@@start_path))
|
32
|
+
if File.exist?(dohruby_path)
|
33
|
+
$LOAD_PATH.push(File.join(dohruby_path, 'lib'))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|