drndump 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f360ce69bbbae294a5d10b32486910970402232
4
+ data.tar.gz: b2c1f9925a35b424ce739c5d7086e7c30610a697
5
+ SHA512:
6
+ metadata.gz: 96dfb02da9769cf3be082156bc27759891b8d2e68159ff041604159cd86be170fd6b59819ae494c2f0066b843a17fe4fe98ce015e61c1cc4da36943e38df2954
7
+ data.tar.gz: 34fef0d416a78cdc52861b209bef9ecb0aac8e329e856dc770e9e91a6bd5d5418573d82bcfecb998293dc0b5d918367d62763e8e6d23f0744ff5f0fd8af01b97
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ # -*- ruby -*-
2
+ #
3
+ # Copyright (C) 2014 Droonga Project
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ source "https://rubygems.org"
19
+
20
+ gemspec
21
+
22
+ base_dir = File.dirname(__FILE__)
23
+ local_droonga_client_ruby_dir = File.join(base_dir, "..", "droonga-client-ruby")
24
+ local_droonga_client_ruby_dir = File.expand_path(local_droonga_client_ruby_dir)
25
+ if File.exist?(local_droonga_client_ruby_dir)
26
+ gem "droonga-client", path: local_droonga_client_ruby_dir
27
+ else
28
+ gem "droonga-client", github: "droonga/droonga-client-ruby"
29
+ end
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # README
2
+
3
+ ## Name
4
+
5
+ drndump
6
+
7
+ ## Description
8
+
9
+ Drndump is a tool to dump Droonga database. You can use it for backup.
10
+
11
+ ## Install
12
+
13
+ ```
14
+ % gem install drndump
15
+ ```
16
+
17
+ ## Basic usage
18
+
19
+ TODO
20
+
21
+ ## Mailing list
22
+
23
+ * English: [groonga-talk@lists.sourceforge.net](https://lists.sourceforge.net/lists/listinfo/groonga-talk)
24
+ * Japanese: [groonga-dev@lists.sourceforge.jp](http://lists.sourceforge.jp/mailman/listinfo/groonga-dev)
25
+
26
+ ## Thanks
27
+
28
+ * ...
29
+
30
+ ## Copyright
31
+
32
+ Copyright (c) 2014 Droonga Project
33
+
34
+ ## License
35
+
36
+ GPLv3 or later. See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2014 Droonga Project
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ task :default => :test
19
+
20
+ require "bundler/gem_helper"
21
+ require "packnga"
22
+
23
+ base_dir = File.join(File.dirname(__FILE__))
24
+
25
+ helper = Bundler::GemHelper.new(base_dir)
26
+ def helper.version_tag
27
+ version
28
+ end
29
+
30
+ helper.install
31
+ spec = helper.gemspec
32
+
33
+ Packnga::DocumentTask.new(spec) do |task|
34
+ task.original_language = "en"
35
+ task.translate_languages = ["ja"]
36
+ end
37
+
38
+ desc "Run tests"
39
+ task :test do
40
+ # No test
41
+ # ruby("test/run-test.rb")
42
+ end
data/bin/drndump ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2014 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "drndump/command"
19
+
20
+ exit(Drndump::Command.run(ARGV))
data/doc/text/news.md ADDED
@@ -0,0 +1,5 @@
1
+ # News
2
+
3
+ ## 1.0.0: 2014-05-29
4
+
5
+ The first release!!!
data/drndump.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2014 Droonga Project
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ clean_white_space = lambda do |entry|
19
+ entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
20
+ end
21
+
22
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
23
+ require "drndump/version"
24
+
25
+ Gem::Specification.new do |spec|
26
+ spec.name = "drndump"
27
+ spec.version = Drndump::VERSION
28
+ spec.homepage = "https://github.com/droonga/drndump"
29
+ spec.authors = ["Droonga Project"]
30
+ spec.email = ["droonga@groonga.org"]
31
+ readme = File.read("README.md")
32
+ readme.force_encoding("UTF-8")
33
+ entries = readme.split(/^\#\#\s(.*)$/)
34
+ description = clean_white_space.call(entries[entries.index("Description") + 1])
35
+ spec.summary, spec.description, = description.split(/\n\n+/, 3)
36
+ spec.license = "GPLv3 or later"
37
+ spec.files = ["README.md", "Rakefile", "Gemfile", "#{spec.name}.gemspec"]
38
+ spec.files += Dir.glob("lib/**/*.rb")
39
+ spec.files += Dir.glob("doc/text/**/*.*")
40
+ Dir.chdir("bin") do
41
+ spec.executables = Dir.glob("*")
42
+ end
43
+
44
+ spec.add_runtime_dependency("json")
45
+ spec.add_runtime_dependency("cool.io")
46
+ spec.add_runtime_dependency("droonga-client")
47
+
48
+ spec.add_development_dependency("bundler")
49
+ spec.add_development_dependency("rake")
50
+ spec.add_development_dependency("packnga")
51
+ spec.add_development_dependency("kramdown")
52
+ end
@@ -0,0 +1,243 @@
1
+ # Copyright (C) 2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "socket"
17
+ require "optparse"
18
+ require "json"
19
+
20
+ require "cool.io"
21
+
22
+ require "droonga/client"
23
+
24
+ require "drndump/version"
25
+
26
+ module Drndump
27
+ class Command
28
+ class << self
29
+ def run(argv)
30
+ new.run(argv)
31
+ end
32
+ end
33
+
34
+ def initialize
35
+ @loop = Coolio::Loop.default
36
+ @host = "localhost"
37
+ @port = 10031
38
+ @tag = "droonga"
39
+ @dataset = "Default"
40
+ @receiver_host = Socket.gethostname
41
+ @receiver_port = 0
42
+ end
43
+
44
+ def run(argv)
45
+ parse_command_line_arguments!(argv)
46
+
47
+ error_message = dump
48
+
49
+ if error_message
50
+ $stderr.puts(error_message)
51
+ false
52
+ else
53
+ true
54
+ end
55
+ end
56
+
57
+ private
58
+ def parse_command_line_arguments!(argv)
59
+ parser = create_option_parser
60
+ parser.parse!(argv)
61
+ end
62
+
63
+ def create_option_parser
64
+ parser = OptionParser.new
65
+ parser.version = VERSION
66
+
67
+ parser.separator("")
68
+ parser.separator("Connect:")
69
+ parser.on("--host=HOST",
70
+ "Host name to be connected.",
71
+ "(#{@host})") do |host|
72
+ @host = host
73
+ end
74
+ parser.on("--port=PORT", Integer,
75
+ "Port number to be connected.",
76
+ "(#{@port})") do |port|
77
+ @port = port
78
+ end
79
+ parser.on("--tag=TAG",
80
+ "Tag name to be used to communicate with Droonga system.",
81
+ "(#{@tag})") do |tag|
82
+ @tag = tag
83
+ end
84
+
85
+ parser.separator("")
86
+ parser.separator("Data:")
87
+ parser.on("--dataset=DATASET",
88
+ "Dataset to be dumped.",
89
+ "(#{@dataset})") do |dataset|
90
+ @dataset = dataset
91
+ end
92
+
93
+ parser.separator("")
94
+ parser.separator("Droonga protocol:")
95
+ parser.on("--receiver-host=HOST",
96
+ "Host name to be received a response from Droonga engine.",
97
+ "(#{@receiver_host})") do |host|
98
+ @receiver_host = host
99
+ end
100
+ parser.on("--receiver-port=PORT", Integer,
101
+ "Port number to be received a response from Droonga engine.",
102
+ "(#{@receiver_port})") do |port|
103
+ @receiver_port = port
104
+ end
105
+
106
+ parser
107
+ end
108
+
109
+ def client_options
110
+ {
111
+ :host => @host,
112
+ :port => @port,
113
+ :tag => @tag,
114
+ :protocol => :droonga,
115
+ :receiver_host => @receiver_host,
116
+ :receiver_port => @receiver_port,
117
+ :backend => :coolio,
118
+ :loop => @loop,
119
+ }
120
+ end
121
+
122
+ def dump
123
+ client = Droonga::Client.new(client_options)
124
+
125
+ error_message = nil
126
+ n_dumpers = 0
127
+
128
+ dump_message = {
129
+ "type" => "dump",
130
+ "dataset" => @dataset,
131
+ }
132
+ client.subscribe(dump_message) do |message|
133
+ case message
134
+ when Droonga::Client::Error
135
+ client.close
136
+ error_message = message.to_s
137
+ else
138
+ case message["type"]
139
+ when "dump.result", "dump.error"
140
+ if message["statusCode"] != 200
141
+ client.close
142
+ error = message["body"]
143
+ error_message = "#{error['name']}: #{error['message']}"
144
+ end
145
+ when "dump.table"
146
+ table_create_message = convert_to_table_create_message(message)
147
+ puts(JSON.pretty_generate(table_create_message))
148
+ when "dump.column"
149
+ column_create_message = convert_to_column_create_message(message)
150
+ puts(JSON.pretty_generate(column_create_message))
151
+ when "dump.record"
152
+ add_message = message.dup
153
+ add_message.delete("inReplyTo")
154
+ add_message["type"] = "add"
155
+ puts(JSON.pretty_generate(add_message))
156
+ when "dump.start"
157
+ n_dumpers += 1
158
+ when "dump.end"
159
+ n_dumpers -= 1
160
+ client.close if n_dumpers <= 0
161
+ end
162
+ end
163
+ end
164
+ @loop.run
165
+
166
+ error_message
167
+ end
168
+
169
+ def convert_to_table_create_message(message)
170
+ body = message["body"]
171
+ flags = []
172
+ case body["type"]
173
+ when "Array"
174
+ flags << "TABLE_NO_KEY"
175
+ when "Hash"
176
+ flags << "TABLE_HASH_KEY"
177
+ when "PatriciaTrie"
178
+ flags << "TABLE_PAT_KEY"
179
+ when "DoubleArrayTrie"
180
+ flags << "TABLE_DAT_KEY"
181
+ end
182
+ table_create_message = {
183
+ "type" => "table_create",
184
+ "dataset" => message["dataset"],
185
+ "body" => {
186
+ "name" => body["name"],
187
+ "flags" => flags.join("|"),
188
+ "key_type" => body["keyType"],
189
+ }
190
+ }
191
+
192
+ if body["tokenizer"]
193
+ table_create_message["body"]["default_tokenizer"] = body["tokenizer"]
194
+ end
195
+ if body["normalizer"]
196
+ table_create_message["body"]["normalizer"] = body["normalizer"]
197
+ end
198
+
199
+ table_create_message
200
+ end
201
+
202
+ def convert_to_column_create_message(message)
203
+ body = message["body"]
204
+ column_create_message = {
205
+ "type" => "column_create",
206
+ "dataset" => message["dataset"],
207
+ "body" => {
208
+ "table" => body["table"],
209
+ "name" => body["name"],
210
+ "type" => body["valueType"],
211
+ }
212
+ }
213
+
214
+ flags = []
215
+ case body["type"]
216
+ when "Scalar"
217
+ flags << "COLUMN_SCALAR"
218
+ when "Vector"
219
+ flags << "COLUMN_VECTOR"
220
+ vector_options = body["vectorOptions"] || {}
221
+ flags << "WITH_WEIGHT" if vector_options["weight"]
222
+ when "Index"
223
+ flags << "COLUMN_INDEX"
224
+ index_options = body["indexOptions"] || {}
225
+ flags << "WITH_SECTION" if index_options["section"]
226
+ flags << "WITH_WEIGHT" if index_options["weight"]
227
+ flags << "WITH_POSITION" if index_options["position"]
228
+ end
229
+
230
+ column_create_message["body"]["flags"] = flags.join("|")
231
+
232
+ if body["type"] == "Index"
233
+ index_options = body["indexOptions"] || {}
234
+ sources = index_options["sources"] || []
235
+ unless sources.empty?
236
+ column_create_message["body"]["source"] = sources.join(",")
237
+ end
238
+ end
239
+
240
+ column_create_message
241
+ end
242
+ end
243
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright (C) 2014 Droonga Project
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ module Drndump
17
+ VERSION = "1.0.0"
18
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drndump
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Droonga Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cool.io
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: droonga-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: packnga
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: kramdown
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: ''
112
+ email:
113
+ - droonga@groonga.org
114
+ executables:
115
+ - drndump
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - README.md
120
+ - Rakefile
121
+ - Gemfile
122
+ - drndump.gemspec
123
+ - lib/drndump/version.rb
124
+ - lib/drndump/command.rb
125
+ - doc/text/news.md
126
+ - bin/drndump
127
+ homepage: https://github.com/droonga/drndump
128
+ licenses:
129
+ - GPLv3 or later
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.0.14
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Drndump is a tool to dump Droonga database. You can use it for backup.
151
+ test_files: []
152
+ has_rdoc: