melissadata 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +46 -16
- data/README.md +50 -2
- data/Rakefile +58 -23
- data/Vagrantfile +12 -12
- data/bin/md_tcp_server +5 -0
- data/bin/md_unix_server +5 -0
- data/chef/cookbooks/apt/README.md +109 -0
- data/chef/cookbooks/apt/files/default/apt-cacher +9 -0
- data/chef/cookbooks/apt/files/default/apt-cacher.conf +144 -0
- data/chef/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
- data/chef/cookbooks/apt/metadata.json +34 -0
- data/chef/cookbooks/apt/metadata.rb +13 -0
- data/chef/cookbooks/apt/providers/repository.rb +72 -0
- data/chef/cookbooks/apt/recipes/cacher-client.rb +37 -0
- data/chef/cookbooks/apt/recipes/cacher.rb +45 -0
- data/chef/cookbooks/apt/recipes/default.rb +33 -0
- data/chef/cookbooks/apt/resources/repository.rb +30 -0
- data/chef/cookbooks/build-essential/README.md +24 -0
- data/chef/cookbooks/build-essential/metadata.json +35 -0
- data/chef/cookbooks/build-essential/metadata.rb +10 -0
- data/chef/cookbooks/build-essential/recipes/default.rb +45 -0
- data/chef/cookbooks/melissadata/attributes/default.rb +5 -0
- data/chef/cookbooks/melissadata/metadata.rb +8 -0
- data/chef/cookbooks/melissadata/recipes/default.rb +37 -0
- data/chef/cookbooks/melissadata/templates/default/Makefile.erb +39 -0
- data/chef/cookbooks/melissadata/templates/default/md_tcp_server.init.erb +82 -0
- data/chef/cookbooks/melissadata/templates/default/md_unix_server.init.erb +81 -0
- data/chef/cookbooks/rvm/recipes/default.rb +1 -0
- data/chef/cookbooks/rvm/recipes/r187.rb +6 -0
- data/chef/cookbooks/rvm/recipes/r192.rb +6 -0
- data/chef/cookbooks/rvm/recipes/system.rb +28 -0
- data/chef/cookbooks/ubuntu/attributes/default.rb +24 -0
- data/chef/cookbooks/ubuntu/metadata.json +36 -0
- data/chef/cookbooks/ubuntu/metadata.rb +8 -0
- data/chef/cookbooks/ubuntu/recipes/default.rb +27 -0
- data/chef/cookbooks/ubuntu/templates/default/sources.list.erb +15 -0
- data/lib/melissadata.rb +1 -2
- data/lib/melissadata/client.rb +8 -0
- data/lib/melissadata/client/base.rb +56 -0
- data/lib/melissadata/client/tcp.rb +28 -0
- data/lib/melissadata/client/unix.rb +22 -0
- data/lib/melissadata/client/vagrant.rb +9 -0
- data/lib/melissadata/command.rb +1 -0
- data/lib/melissadata/command/base.rb +0 -1
- data/lib/melissadata/command/compile.rb +37 -0
- data/lib/melissadata/command/package.rb +32 -73
- data/lib/melissadata/constants.rb +6 -5
- data/lib/melissadata/melissadata.rb +26 -91
- data/lib/melissadata/native_object.rb +0 -8
- data/lib/melissadata/native_object/address.rb +2 -0
- data/lib/melissadata/native_object/base.rb +18 -5
- data/lib/melissadata/native_object/email.rb +2 -0
- data/lib/melissadata/native_object/geo.rb +2 -0
- data/lib/melissadata/native_object/ip_locator.rb +2 -0
- data/lib/melissadata/native_object/name.rb +2 -0
- data/lib/melissadata/native_object/phone.rb +2 -0
- data/lib/melissadata/server.rb +10 -0
- data/lib/melissadata/server/base.rb +145 -0
- data/lib/melissadata/server/tcp.rb +22 -0
- data/lib/melissadata/server/unix.rb +24 -0
- data/lib/melissadata/vagrant_plugin.rb +23 -0
- data/lib/melissadata/vagrant_plugin/actions.rb +9 -0
- data/lib/melissadata/vagrant_plugin/actions/base.rb +60 -0
- data/lib/melissadata/vagrant_plugin/actions/install.rb +78 -0
- data/lib/melissadata/vagrant_plugin/actions/update.rb +22 -0
- data/lib/melissadata/vagrant_plugin/command.rb +21 -0
- data/lib/melissadata/vagrant_plugin/config.rb +18 -0
- data/lib/melissadata/version.rb +1 -1
- data/locales/en.yml +16 -0
- data/melissadata.gemspec +11 -12
- data/pkg/melissadata-0.0.1.gem +0 -0
- data/spec/helpers/vagrant_helpers.rb +17 -0
- data/spec/melissadata/command/package_spec.rb +1 -1
- data/spec/melissadata/vagrant_plugin/actions/install_spec.rb +40 -0
- data/spec/melissadata/vagrant_plugin/config_spec.rb +17 -0
- data/spec/spec_helper.rb +12 -7
- metadata +201 -228
- data/bin/md +0 -4
- data/bin/md-rpc +0 -9
- data/bin/md-server +0 -18
- data/bin/melissadata +0 -4
- data/lib/melissadata/native_object/client.rb +0 -33
- data/lib/melissadata/prev/command_old.rb +0 -80
- data/lib/melissadata/prev/shared_objects.rb +0 -54
- data/lib/melissadata/rpc.rb +0 -39
- data/pkg/melissa-data-0.0.1.gem +0 -0
- data/pkg/melissa-data-0.0.2.gem +0 -0
- data/pkg/melissa-data-0.0.3.gem +0 -0
- data/templates/config.rb +0 -20
- data/templates/locales/en.yml +0 -4
@@ -1,12 +1,11 @@
|
|
1
|
+
require 'active_support/core_ext'
|
1
2
|
module MelissaData::NativeObject
|
2
3
|
class Base
|
3
|
-
attr_reader :obj, :
|
4
|
+
attr_reader :obj, :input, :output, :result_codes, :results_string
|
4
5
|
attr_writer :data_dir
|
5
6
|
|
6
7
|
def initialize(opts={})
|
7
|
-
|
8
|
-
|
9
|
-
unless obj.SetLicenseString(@license)
|
8
|
+
unless obj.SetLicenseString(license)
|
10
9
|
@license = "DEMO"
|
11
10
|
puts "Invalid License: Running in DEMO MODE."
|
12
11
|
end
|
@@ -38,6 +37,20 @@ module MelissaData::NativeObject
|
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
40
|
+
def license
|
41
|
+
@license ||= begin
|
42
|
+
default_filename = '/opt/melissadata/license.txt'
|
43
|
+
|
44
|
+
if File.exists?(default_filename)
|
45
|
+
File.read(default_filename).chomp
|
46
|
+
elsif (env_license = ENV['MELISSADATA_LICENSE'])
|
47
|
+
env_license
|
48
|
+
else
|
49
|
+
'DEMO'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
41
54
|
def parse_input
|
42
55
|
raise "Needs to be overridden"
|
43
56
|
end
|
@@ -73,7 +86,7 @@ module MelissaData::NativeObject
|
|
73
86
|
end
|
74
87
|
|
75
88
|
def data_dir
|
76
|
-
@data_dir ||= '/opt/
|
89
|
+
@data_dir ||= '/opt/melissadata/data'
|
77
90
|
end
|
78
91
|
end
|
79
92
|
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
module MelissaData::Server
|
4
|
+
|
5
|
+
class Base
|
6
|
+
attr_reader :server
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@server = MessagePack::RPC::Server.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
raise 'I should have been overridden'
|
14
|
+
end
|
15
|
+
|
16
|
+
def process(opts={})
|
17
|
+
setup(opts)
|
18
|
+
process_address
|
19
|
+
process_email
|
20
|
+
process_geo
|
21
|
+
process_name
|
22
|
+
process_phone
|
23
|
+
process_ip
|
24
|
+
|
25
|
+
data
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup(opts)
|
29
|
+
@input = opts.dup
|
30
|
+
@data = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def input
|
34
|
+
@input ||= {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def data
|
38
|
+
@data ||= {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def process_address(address=nil, zip=nil, city=nil, state=nil)
|
42
|
+
output = {}
|
43
|
+
input[:address] = address if address.present?
|
44
|
+
input[:zip] = zip if zip.present?
|
45
|
+
input[:city] = city if city.present?
|
46
|
+
input[:state] = state if state.present?
|
47
|
+
|
48
|
+
output = address_object.process(input)
|
49
|
+
output.delete_if{ |k,v| v.to_s.strip == "" }
|
50
|
+
data[:address] = output
|
51
|
+
output
|
52
|
+
end
|
53
|
+
alias_method :address, :process_address
|
54
|
+
|
55
|
+
def process_email(email=nil)
|
56
|
+
output = {}
|
57
|
+
input[:email] = email.to_s if email.present?
|
58
|
+
|
59
|
+
output = email_object.process(input)
|
60
|
+
output.delete_if{ |k,v| v.to_s.strip == "" }
|
61
|
+
data[:email] = output
|
62
|
+
output
|
63
|
+
end
|
64
|
+
alias_method :email, :process_email
|
65
|
+
|
66
|
+
def process_geo(zip=nil, plus4=nil, dpc=nil)
|
67
|
+
output = {}
|
68
|
+
|
69
|
+
input[:zip] = zip.to_s if zip.present?
|
70
|
+
input[:plus4] = plus4.to_s if plus4.present?
|
71
|
+
input[:delivery_point_code] = dpc.to_s if dpc.present?
|
72
|
+
|
73
|
+
output = geo_object.process(input)
|
74
|
+
output.delete_if{ |k,v| v.to_s.strip == "" }
|
75
|
+
data[:geo] = output
|
76
|
+
|
77
|
+
output
|
78
|
+
end
|
79
|
+
alias_method :geo, :process_geo
|
80
|
+
|
81
|
+
def process_name(first_name=nil, last_name=nil)
|
82
|
+
output = {}
|
83
|
+
input[:first_name] = first_name if first_name.present?
|
84
|
+
input[:last_name] = last_name if last_name.present?
|
85
|
+
|
86
|
+
output = name_object.process(input)
|
87
|
+
output.delete_if{ |k,v| v.to_s.strip == "" }
|
88
|
+
data[:name] = output
|
89
|
+
output
|
90
|
+
end
|
91
|
+
alias_method :name, :process_name
|
92
|
+
|
93
|
+
def process_phone(phone=nil, zip=nil)
|
94
|
+
output = {}
|
95
|
+
input[:phone] = phone if phone.present?
|
96
|
+
input[:zip] = zip.to_s if zip.present?
|
97
|
+
|
98
|
+
output = phone_object.process(input)
|
99
|
+
output.delete_if{ |k,v| v.to_s.strip == "" }
|
100
|
+
data[:phone] = output
|
101
|
+
output
|
102
|
+
end
|
103
|
+
alias_method :phone, :process_phone
|
104
|
+
|
105
|
+
def process_ip(ip=nil)
|
106
|
+
output = {}
|
107
|
+
input[:ip] = ip if ip.present?
|
108
|
+
|
109
|
+
output = ip_object.process(input)
|
110
|
+
output.delete_if{ |k,v| v.to_s.strip == "" }
|
111
|
+
data[:ip] = output
|
112
|
+
output
|
113
|
+
end
|
114
|
+
alias_method :ip, :process_ip
|
115
|
+
|
116
|
+
def address_object
|
117
|
+
@address_object ||= MelissaData::NativeObject::Address.new
|
118
|
+
end
|
119
|
+
|
120
|
+
def email_object
|
121
|
+
@email_object ||= MelissaData::NativeObject::Email.new
|
122
|
+
end
|
123
|
+
|
124
|
+
def geo_object
|
125
|
+
@geo_object ||= MelissaData::NativeObject::Geo.new
|
126
|
+
end
|
127
|
+
|
128
|
+
def name_object
|
129
|
+
@name_object ||= MelissaData::NativeObject::Name.new
|
130
|
+
end
|
131
|
+
|
132
|
+
def phone_object
|
133
|
+
@phone_object ||= MelissaData::NativeObject::Phone.new
|
134
|
+
end
|
135
|
+
|
136
|
+
def ip_object
|
137
|
+
@ip_object ||= MelissaData::NativeObject::IpLocator.new
|
138
|
+
end
|
139
|
+
|
140
|
+
def version
|
141
|
+
MelissaData::VERSION
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MelissaData::Server
|
2
|
+
|
3
|
+
class TCP < Base
|
4
|
+
def run
|
5
|
+
trap("INT") { self.stop }
|
6
|
+
trap("TERM") { self.stop }
|
7
|
+
|
8
|
+
host = MelissaData::DEFAULT_TCP_ADDRESS
|
9
|
+
port = MelissaData::DEFAULT_TCP_PORT
|
10
|
+
server.listen(host, port, self)
|
11
|
+
|
12
|
+
puts "== MelissaData TCP server is now listening on #{host}:#{port}"
|
13
|
+
server.run
|
14
|
+
end
|
15
|
+
|
16
|
+
def stop
|
17
|
+
puts "== Stopping MelissaData TCP server"
|
18
|
+
server.stop
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'msgpack/rpc/transport/unix'
|
2
|
+
|
3
|
+
module MelissaData::Server
|
4
|
+
|
5
|
+
class Unix < Base
|
6
|
+
def run
|
7
|
+
trap("INT") { self.stop }
|
8
|
+
trap("TERM") { self.stop }
|
9
|
+
|
10
|
+
@socket_file = MelissaData::DEFAULT_SOCKET_FILE
|
11
|
+
listener = MessagePack::RPC::UNIXServerTransport.new @socket_file
|
12
|
+
server.listen(listener, self)
|
13
|
+
puts "== MelissaData Unix server is running - socket file: #{@socket_file}"
|
14
|
+
server.run
|
15
|
+
end
|
16
|
+
|
17
|
+
def stop
|
18
|
+
puts "== Stopping MelissaData Unix server"
|
19
|
+
server.stop
|
20
|
+
File.delete @socket_file if File.exists? @socket_file
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
|
+
require 'vagrant'
|
3
|
+
|
4
|
+
module MelissaData
|
5
|
+
module VagrantPlugin
|
6
|
+
module_function
|
7
|
+
|
8
|
+
autoload :Config, 'vagrant_plugin/config'
|
9
|
+
autoload :Command, 'vagrant_plugin/command'
|
10
|
+
autoload :Actions, 'vagrant_plugin/actions'
|
11
|
+
|
12
|
+
def load!
|
13
|
+
Config; Command; Actions # due to autoload
|
14
|
+
Vagrant::Action.register(:md_install, Vagrant::Action::Builder.new do
|
15
|
+
use Actions::Install
|
16
|
+
end)
|
17
|
+
|
18
|
+
Vagrant::Action.register(:md_update, Vagrant::Action::Builder.new do
|
19
|
+
use Actions::Update
|
20
|
+
end)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module MelissaData::VagrantPlugin::Actions
|
2
|
+
|
3
|
+
class Base
|
4
|
+
def initialize(app, env)
|
5
|
+
@app = app
|
6
|
+
@env = env
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def copy_file(source_path, dest_subdir='')
|
12
|
+
filename = File.basename(source_path)
|
13
|
+
sub_dir = dest_subdir.empty? ? filename : "#{dest_subdir}/#{filename}"
|
14
|
+
dest_path = File.expand_path(sub_dir, @env['config'].melissadata.target_path)
|
15
|
+
|
16
|
+
if test? "[ -e #{dest_path} ]"
|
17
|
+
# file exists
|
18
|
+
# sudo "rm -f #{dest_path}"
|
19
|
+
@env.ui.info I18n.t("vagrant.plugins.melissadata.file_exists", :filename => dest_path), :prefix => false
|
20
|
+
else
|
21
|
+
@env.ui.info I18n.t("vagrant.plugins.melissadata.copying_file", :file => filename, :path => dest_path), :prefix => false
|
22
|
+
@vm.ssh.upload!(source_path, dest_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
sudo "chmod u+w #{dest_path}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def copy_dir(source_path, dest_subdir = '.', options={})
|
29
|
+
dest_path = File.expand_path(dest_subdir, @env['config'].melissadata.target_path)
|
30
|
+
|
31
|
+
full_dest_path = File.join(dest_path, File.basename(source_path))
|
32
|
+
if options[:overwrite]
|
33
|
+
exec "rm -rf #{full_dest_path}"
|
34
|
+
end
|
35
|
+
|
36
|
+
unless test? "[ -e #{full_dest_path} ]"
|
37
|
+
@env.ui.info I18n.t("vagrant.plugins.melissadata.copying_directory", :source => source_path, :target => dest_path), :prefix => false
|
38
|
+
@vm.ssh.execute do |ssh|
|
39
|
+
scp = Net::SCP.new(ssh.session)
|
40
|
+
scp.upload!(source_path, dest_path, :recursive => true)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test?(command)
|
46
|
+
@vm.ssh.execute do |ssh|
|
47
|
+
return ssh.test?(command)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def exec(command)
|
52
|
+
@vm.ssh.execute{ |ssh| ssh.exec! command }
|
53
|
+
end
|
54
|
+
|
55
|
+
def sudo(command)
|
56
|
+
@vm.ssh.execute{ |ssh| ssh.sudo! command }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module MelissaData::VagrantPlugin::Actions
|
2
|
+
|
3
|
+
# A Vagrant middleware which copies files from MelissaData DVDs to the VM
|
4
|
+
# and then compiles the shared objects
|
5
|
+
class Install < Base
|
6
|
+
def call(env)
|
7
|
+
@vm = env['vm']
|
8
|
+
if @vm.created? && @vm.vm.running?
|
9
|
+
target_root = env['config'].melissadata.target_path
|
10
|
+
env.ui.info I18n.t("vagrant.plugins.melissadata.installing", :path => target_root), :prefix => false
|
11
|
+
|
12
|
+
sudo "mkdir -p #{%w[ src lib data ].map{ |sub| "#{target_root}/#{sub}" }.join(' ')}"
|
13
|
+
sudo "chown -R vagrant:vagrant #{target_root}"
|
14
|
+
|
15
|
+
license_path = '/opt/melissadata/license.txt'
|
16
|
+
unless test? "[ -e #{license_path} ]"
|
17
|
+
license = env.ui.ask "Enter your MelissaData license:"
|
18
|
+
@vm.ssh.upload!(StringIO.new("#{license}\n"), license_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
sudo "gem uninstall melissadata" if test? "ruby -r md -e 'puts MD::VERSION'"
|
22
|
+
gem_filename = "melissadata-#{MelissaData::VERSION}.gem"
|
23
|
+
copy_file "#{File.expand_path("pkg/#{gem_filename}", MelissaData.gem_root)}"
|
24
|
+
sudo "gem install #{target_root}/#{gem_filename} && rm #{target_root}/#{gem_filename}"
|
25
|
+
|
26
|
+
unless source_paths_and_names.empty?
|
27
|
+
source_paths_and_names.each do |source_path,name|
|
28
|
+
Dir["#{source_path}/linux/gcc34_64bit/*.h"].each{ |filename| copy_file filename, 'src' }
|
29
|
+
copy_file "#{source_path}/linux/gcc34_64bit/libmd#{name}.so", 'lib'
|
30
|
+
copy_file "#{source_path}/linux/interfaces/ruby/md#{name}RubyWrapper.cpp", 'src'
|
31
|
+
# Dir["#{source_path}/data/*"].each{ |filename| copy_file filename, 'data' }
|
32
|
+
Dir["#{source_path}/data/*"].each{ |filename| copy_dir filename, 'data' }
|
33
|
+
end
|
34
|
+
|
35
|
+
env.ui.info I18n.t("vagrant.plugins.melissadata.compiling"), :prefix => false
|
36
|
+
exec "cd #{target_root}/src && make #{source_paths_and_names.map{ |path,name| name }.join(' ')}"
|
37
|
+
end
|
38
|
+
|
39
|
+
sudo "chown -R vagrant:vagrant #{target_root}"
|
40
|
+
sudo "/etc/init.d/md_tcp_server start"
|
41
|
+
sudo "/etc/init.d/md_unix_server start"
|
42
|
+
else
|
43
|
+
env.ui.error "Vagrant VM is not running", :prefix => false
|
44
|
+
end
|
45
|
+
|
46
|
+
@app.call(env)
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def source_paths_and_names
|
52
|
+
# Examples:
|
53
|
+
# DQ-DVD-2011-05
|
54
|
+
# GEO-DVD-2011-Q2
|
55
|
+
@paths_and_names ||= Dir['/Volumes/*-DVD-*/**/md*Ref.pdf'].map do |path|
|
56
|
+
dir = File.dirname(path)
|
57
|
+
name = path.match(/md(.*)Ref\.pdf/).captures.first
|
58
|
+
[dir, name]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def package_data
|
63
|
+
# source_paths_and_names.each do |source_path,name|
|
64
|
+
# data_file = "#{dest_dir}/#{obj}.tgz"
|
65
|
+
# inside "#{source_dir}/#{obj}" do
|
66
|
+
# run "tar czf #{data_file} data"
|
67
|
+
# end
|
68
|
+
|
69
|
+
# say_status :upload, "#{obj}.tgz to #{options[:bucket_name]}"
|
70
|
+
# cf = CloudFiles::Connection.new(:username => options[:username], :api_key => options[:api_key])
|
71
|
+
# cont = cf.container options[:bucket_name]
|
72
|
+
# remote_object = cont.create_object "#{obj}.tgz", false
|
73
|
+
# remote_object.load_from_filename data_file
|
74
|
+
# end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|