worlddb 0.0.1
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/History.markdown +4 -0
- data/Manifest.txt +10 -0
- data/README.markdown +23 -0
- data/Rakefile +25 -0
- data/bin/worlddb +7 -0
- data/lib/worlddb/cli/opts.rb +56 -0
- data/lib/worlddb/cli/runner.rb +128 -0
- data/lib/worlddb/schema.rb +28 -0
- data/lib/worlddb/version.rb +4 -0
- data/lib/worlddb.rb +44 -0
- metadata +119 -0
data/History.markdown
ADDED
data/Manifest.txt
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# worlddb
|
2
|
+
|
3
|
+
world.db Command Line Tool in Ruby
|
4
|
+
|
5
|
+
* [geraldb.github.com/world.db](http://geraldb.github.com/world.db)
|
6
|
+
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
TBD
|
11
|
+
|
12
|
+
|
13
|
+
## Install
|
14
|
+
|
15
|
+
Just install the gem:
|
16
|
+
|
17
|
+
$ gem install worlddb
|
18
|
+
|
19
|
+
|
20
|
+
## License
|
21
|
+
|
22
|
+
The `worlddb` scripts are dedicated to the public domain.
|
23
|
+
Use it as you please with no restrictions whatsoever.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/worlddb/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'worlddb' do
|
5
|
+
|
6
|
+
self.version = WorldDB::VERSION
|
7
|
+
|
8
|
+
self.summary = 'worlddb - world.db command line tool'
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = ['http://geraldb.github.com/world.db']
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'opensport@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.markdown'
|
18
|
+
self.history_file = 'History.markdown'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
['activerecord', '~> 3.2'] # NB: will include activesupport,etc.
|
22
|
+
### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
|
23
|
+
]
|
24
|
+
|
25
|
+
end
|
data/bin/worlddb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module WorldDB
|
2
|
+
|
3
|
+
class Opts
|
4
|
+
|
5
|
+
def create=(boolean)
|
6
|
+
@create = boolean
|
7
|
+
end
|
8
|
+
|
9
|
+
def create?
|
10
|
+
return false if @create.nil? # default create flag is false
|
11
|
+
@create == true
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def delete=(boolean)
|
16
|
+
@delete = boolean
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete?
|
20
|
+
return false if @delete.nil? # default create flag is false
|
21
|
+
@delete == true
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# use loader? (that is, built-in seed data)
|
26
|
+
def load=(boolean)
|
27
|
+
@load = boolean
|
28
|
+
end
|
29
|
+
|
30
|
+
def load?
|
31
|
+
return false if @load.nil? # default create flag is false
|
32
|
+
@load == true
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def output_path=(value)
|
37
|
+
@output_path = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def output_path
|
41
|
+
@output_path || '.'
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def data_path=(value)
|
46
|
+
@data_path = value
|
47
|
+
end
|
48
|
+
|
49
|
+
def data_path
|
50
|
+
@data_path || '.'
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end # class Opts
|
55
|
+
|
56
|
+
end # module WorldDB
|
@@ -0,0 +1,128 @@
|
|
1
|
+
|
2
|
+
module WorldDB
|
3
|
+
|
4
|
+
class Runner
|
5
|
+
|
6
|
+
|
7
|
+
### include WorldDB::Models
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@logger = Logger.new(STDOUT)
|
11
|
+
@logger.level = Logger::INFO
|
12
|
+
|
13
|
+
@opts = Opts.new
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :logger, :opts
|
17
|
+
|
18
|
+
|
19
|
+
def run( args )
|
20
|
+
opt=OptionParser.new do |cmd|
|
21
|
+
|
22
|
+
cmd.banner = "Usage: worlddb [options]"
|
23
|
+
|
24
|
+
## todo: change to different flag?? use -c/--config ???
|
25
|
+
cmd.on( '-c', '--create', 'Create DB Schema' ) { opts.create = true }
|
26
|
+
|
27
|
+
cmd.on( '--delete', 'Delete all records' ) { opts.delete = true }
|
28
|
+
|
29
|
+
cmd.on( '--load', 'Use Loader for Builtin World Data' ) { opts.load = true }
|
30
|
+
|
31
|
+
### todo: in future allow multiple search path??
|
32
|
+
cmd.on( '-i', '--include PATH', "Data Path (default is #{opts.data_path})" ) { |path| opts.data_path = path }
|
33
|
+
|
34
|
+
cmd.on( '-v', '--version', "Show version" ) do
|
35
|
+
puts WorldDB.banner
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
|
39
|
+
cmd.on( "--verbose", "Show debug trace" ) do
|
40
|
+
logger.datetime_format = "%H:%H:%S"
|
41
|
+
logger.level = Logger::DEBUG
|
42
|
+
|
43
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
44
|
+
end
|
45
|
+
|
46
|
+
cmd.on_tail( "-h", "--help", "Show this message" ) do
|
47
|
+
puts <<EOS
|
48
|
+
|
49
|
+
worlddb - world.db command line tool, version #{VERSION}
|
50
|
+
|
51
|
+
#{cmd.help}
|
52
|
+
|
53
|
+
Examples:
|
54
|
+
worlddb at # import austrian regions n cities
|
55
|
+
worlddb -c # create database schema
|
56
|
+
|
57
|
+
More Examples:
|
58
|
+
worlddb # show stats (table counts, table props)
|
59
|
+
|
60
|
+
Further information:
|
61
|
+
http://geraldb.github.com/world.db
|
62
|
+
|
63
|
+
EOS
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
opt.parse!( args )
|
69
|
+
|
70
|
+
puts WorldDB.banner
|
71
|
+
|
72
|
+
puts "working directory: #{Dir.pwd}"
|
73
|
+
|
74
|
+
db_config = {
|
75
|
+
:adapter => 'sqlite3',
|
76
|
+
:database => "#{opts.output_path}/world.db"
|
77
|
+
}
|
78
|
+
|
79
|
+
puts "Connecting to db using settings: "
|
80
|
+
pp db_config
|
81
|
+
|
82
|
+
ActiveRecord::Base.establish_connection( db_config )
|
83
|
+
|
84
|
+
if opts.create?
|
85
|
+
CreateDB.up
|
86
|
+
end
|
87
|
+
|
88
|
+
if opts.delete?
|
89
|
+
# tbd
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
args.each do |arg|
|
94
|
+
name = arg # File.basename( arg, '.*' )
|
95
|
+
|
96
|
+
# tbd
|
97
|
+
end
|
98
|
+
|
99
|
+
dump_stats
|
100
|
+
dump_props
|
101
|
+
|
102
|
+
puts 'Done.'
|
103
|
+
|
104
|
+
end # method run
|
105
|
+
|
106
|
+
|
107
|
+
def dump_stats
|
108
|
+
# todo: use %5d or similar to format string
|
109
|
+
=begin
|
110
|
+
puts "Stats:"
|
111
|
+
puts " #{Country.count} countries"
|
112
|
+
=end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
def dump_props
|
117
|
+
|
118
|
+
=begin
|
119
|
+
# todo: use %5 or similar to format string
|
120
|
+
puts "Props:"
|
121
|
+
Prop.order( 'created_at asc' ).all.each do |prop|
|
122
|
+
puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
|
123
|
+
end
|
124
|
+
=end
|
125
|
+
end
|
126
|
+
|
127
|
+
end # class Runner
|
128
|
+
end # module WorldDB
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
module WorldDB
|
3
|
+
|
4
|
+
class CreateDB
|
5
|
+
|
6
|
+
## include WorldDB::Models
|
7
|
+
|
8
|
+
|
9
|
+
def self.up
|
10
|
+
|
11
|
+
ActiveRecord::Schema.define do
|
12
|
+
|
13
|
+
create_table :countries do |t|
|
14
|
+
t.string :title, :null => false
|
15
|
+
t.string :tag, :null => false # short three letter tag
|
16
|
+
t.string :key, :null => false
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
|
20
|
+
end # block Schema.define
|
21
|
+
|
22
|
+
## Prop.create!( key: 'db.schema.version', value: BeerDB::VERSION )
|
23
|
+
|
24
|
+
end # method up
|
25
|
+
|
26
|
+
end # class CreateDB
|
27
|
+
|
28
|
+
end # module WorldDB
|
data/lib/worlddb.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
###
|
2
|
+
# NB: for local testing run like:
|
3
|
+
#
|
4
|
+
# 1.9.x: ruby -Ilib lib/worlddb.rb
|
5
|
+
|
6
|
+
# core and stlibs
|
7
|
+
|
8
|
+
require 'yaml'
|
9
|
+
require 'pp'
|
10
|
+
require 'logger'
|
11
|
+
require 'optparse'
|
12
|
+
require 'fileutils'
|
13
|
+
require 'erb'
|
14
|
+
|
15
|
+
# rubygems
|
16
|
+
|
17
|
+
require 'active_record' ## todo: add sqlite3? etc.
|
18
|
+
|
19
|
+
|
20
|
+
# our own code
|
21
|
+
|
22
|
+
require 'worlddb/schema' # NB: requires worlddb/models (include WorldDB::Models)
|
23
|
+
require 'worlddb/version'
|
24
|
+
require 'worlddb/cli/opts'
|
25
|
+
require 'worlddb/cli/runner'
|
26
|
+
|
27
|
+
module WorldDB
|
28
|
+
|
29
|
+
def self.banner
|
30
|
+
"worlddb #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.root
|
34
|
+
"#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.main
|
38
|
+
Runner.new.run(ARGV)
|
39
|
+
end
|
40
|
+
|
41
|
+
end # module WorldDB
|
42
|
+
|
43
|
+
|
44
|
+
WorldDB.main if __FILE__ == $0
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: worlddb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Gerald Bauer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-11-05 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activerecord
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 2
|
32
|
+
version: "3.2"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rdoc
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 19
|
44
|
+
segments:
|
45
|
+
- 3
|
46
|
+
- 10
|
47
|
+
version: "3.10"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: hoe
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 7
|
59
|
+
segments:
|
60
|
+
- 3
|
61
|
+
- 0
|
62
|
+
version: "3.0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
description: worlddb - world.db command line tool
|
66
|
+
email: opensport@googlegroups.com
|
67
|
+
executables:
|
68
|
+
- worlddb
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- Manifest.txt
|
73
|
+
files:
|
74
|
+
- History.markdown
|
75
|
+
- Manifest.txt
|
76
|
+
- README.markdown
|
77
|
+
- Rakefile
|
78
|
+
- bin/worlddb
|
79
|
+
- lib/worlddb.rb
|
80
|
+
- lib/worlddb/cli/opts.rb
|
81
|
+
- lib/worlddb/cli/runner.rb
|
82
|
+
- lib/worlddb/schema.rb
|
83
|
+
- lib/worlddb/version.rb
|
84
|
+
homepage: http://geraldb.github.com/world.db
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options:
|
89
|
+
- --main
|
90
|
+
- README.markdown
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project: worlddb
|
114
|
+
rubygems_version: 1.8.24
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: worlddb - world.db command line tool
|
118
|
+
test_files: []
|
119
|
+
|