open_geo_db 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -5
- data/lib/open_geo_db/cli.rb +30 -38
- data/lib/open_geo_db/version.rb +1 -1
- metadata +5 -5
data/README.md
CHANGED
@@ -1,24 +1,35 @@
|
|
1
1
|
# OpenGeoDb
|
2
2
|
|
3
|
-
|
3
|
+
A simple Gem for creating and destroying MySQL databases containing data
|
4
|
+
from the "OpenGeoDB" project (http://opengeodb.giswiki.org/wiki/OpenGeoDB).
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
7
8
|
Add this line to your application's Gemfile:
|
8
9
|
|
9
|
-
|
10
|
+
```ruby
|
11
|
+
gem("open_geo_db")
|
12
|
+
```
|
10
13
|
|
11
14
|
And then execute:
|
12
15
|
|
13
|
-
|
16
|
+
```bash
|
17
|
+
$ bundle
|
18
|
+
```
|
14
19
|
|
15
20
|
Or install it yourself as:
|
16
21
|
|
17
|
-
|
22
|
+
```bash
|
23
|
+
$ gem install open_geo_db
|
24
|
+
```
|
18
25
|
|
19
26
|
## Usage
|
20
27
|
|
21
|
-
|
28
|
+
For detailed usage run:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
$ bundle exec open_geo_db --help
|
32
|
+
```
|
22
33
|
|
23
34
|
## Contributing
|
24
35
|
|
data/lib/open_geo_db/cli.rb
CHANGED
@@ -5,54 +5,39 @@ module OpenGeoDb
|
|
5
5
|
class CLI
|
6
6
|
include Mixlib::CLI
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
:short => "-a ACTION",
|
11
|
-
:long => "--action ACTION",
|
12
|
-
:proc => Proc.new { |l| l.to_sym },
|
13
|
-
:description => "Action to do (`create` or `destroy`)")
|
8
|
+
DEFAULT_CONFIG = {"open_geo_db" =>
|
9
|
+
{"database" => "open_geo_db", "username" => "root", "password" => ""}}
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
def self.action_option(name, description)
|
12
|
+
option(name, :short => "-#{name.to_s[0].chr} config", :long => "--#{name} CONFIG",
|
13
|
+
:description => description)
|
14
|
+
end
|
15
|
+
|
16
|
+
action_option(:create, "Create database with config file CONFIG")
|
17
|
+
action_option(:destroy, "Destroy database with config file CONFIG")
|
18
|
+
action_option(:generate, "Generate config file CONFIG")
|
20
19
|
|
21
|
-
option(:help,
|
22
|
-
:
|
23
|
-
:on => :tail,
|
24
|
-
:short => "-h",
|
25
|
-
:long => "--help",
|
26
|
-
:description => "Show this message",
|
27
|
-
:show_options => true,
|
28
|
-
:exit => 0)
|
20
|
+
option(:help, :boolean => true, :on => :tail, :short => "-h", :long => "--help",
|
21
|
+
:description => "Show this message", :show_options => true, :exit => 0)
|
29
22
|
|
30
23
|
def run
|
31
24
|
parse_options
|
32
|
-
|
33
|
-
if File.exist?(config[:config])
|
34
|
-
yaml = YAML.load_file(config[:config])["open_geo_db"]
|
35
|
-
@database = yaml["database"]
|
36
|
-
@username = yaml["username"]
|
37
|
-
@password = "-p#{yaml["password"]}" if yaml["password"] and yaml["password"].any?
|
38
|
-
end
|
39
|
-
@database ||= "open_geo_db"
|
40
|
-
@username ||= "root"
|
41
|
-
|
42
|
-
action = config[:action]
|
43
|
-
|
44
|
-
case action
|
45
|
-
when :create then create
|
46
|
-
when :destroy then destroy
|
47
|
-
else
|
48
|
-
puts("Unknown action `#{action}`. For usage see `open_geo_db --help`")
|
49
|
-
exit 1
|
50
|
-
end
|
25
|
+
send(config.keys.first)
|
51
26
|
end
|
52
27
|
|
53
28
|
private
|
54
29
|
|
30
|
+
def load_config
|
31
|
+
config_file = config.values.first
|
32
|
+
puts("Using config file #{config_file}")
|
33
|
+
yaml = YAML.load_file(config_file)["open_geo_db"]
|
34
|
+
@database = yaml["database"]
|
35
|
+
@username = yaml["username"]
|
36
|
+
@password = "-p#{yaml["password"]}" if yaml["password"] and yaml["password"].any?
|
37
|
+
end
|
38
|
+
|
55
39
|
def create
|
40
|
+
load_config
|
56
41
|
sh("mysqladmin -u#{@username} #{@password} create #{@database}")
|
57
42
|
%w(opengeodb-begin DE DEhier AT AThier CH CHhier opengeodb-end).each do |basename|
|
58
43
|
file = File.join(File.dirname(__FILE__), %w(.. .. vendor sql), "#{basename}.sql")
|
@@ -61,9 +46,16 @@ module OpenGeoDb
|
|
61
46
|
end
|
62
47
|
|
63
48
|
def destroy
|
49
|
+
load_config
|
64
50
|
sh("mysqladmin -u#{@username} #{@password} drop -f #{@database}")
|
65
51
|
end
|
66
52
|
|
53
|
+
def generate
|
54
|
+
config_file = config.values.first
|
55
|
+
puts("Writing config to #{config_file}")
|
56
|
+
File.open(config_file, "w") { |f| f.write(DEFAULT_CONFIG.to_yaml) }
|
57
|
+
end
|
58
|
+
|
67
59
|
def sh(command)
|
68
60
|
puts(command)
|
69
61
|
%x{#{command}}
|
data/lib/open_geo_db/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_geo_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kostiantyn Kahanskyi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-12 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: mixlib-cli
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
requirements: []
|
106
106
|
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.8.
|
108
|
+
rubygems_version: 1.8.15
|
109
109
|
signing_key:
|
110
110
|
specification_version: 3
|
111
111
|
summary: Create and destroy OpenGeoDb databases
|