jetel 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +34 -0
  3. data/README.md +14 -7
  4. data/Rakefile +11 -0
  5. data/bin/jetel +20 -0
  6. data/lib/jetel.rb +20 -0
  7. data/lib/jetel/cli/app.rb +20 -0
  8. data/lib/jetel/cli/cli.rb +20 -0
  9. data/lib/jetel/cli/cmd/config_cmd.rb +20 -0
  10. data/lib/jetel/cli/cmd/downloaders_cmd.rb +20 -0
  11. data/lib/jetel/cli/cmd/loaders_cmd.rb +20 -0
  12. data/lib/jetel/cli/cmd/modules_cmd.rb +31 -0
  13. data/lib/jetel/cli/cmd/version_cmd.rb +20 -0
  14. data/lib/jetel/cli/shared.rb +20 -0
  15. data/lib/jetel/config/config.rb +20 -0
  16. data/lib/jetel/downloaders/base_downloader.rb +20 -0
  17. data/lib/jetel/downloaders/downloader.rb +20 -0
  18. data/lib/jetel/downloaders/downloaders.rb +22 -0
  19. data/lib/jetel/helpers/general_helper.rb +20 -0
  20. data/lib/jetel/helpers/helpers.rb +19 -3
  21. data/lib/jetel/helpers/os_helper.rb +22 -0
  22. data/lib/jetel/lib.rb +20 -0
  23. data/lib/jetel/loaders/couchbase/couchbase.rb +42 -4
  24. data/lib/jetel/loaders/elasticsearch/elasticsearch.rb +22 -0
  25. data/lib/jetel/loaders/loader.rb +22 -0
  26. data/lib/jetel/loaders/loaders.rb +22 -0
  27. data/lib/jetel/loaders/pg/pg.rb +22 -0
  28. data/lib/jetel/loaders/pg/sql/copy.sql.erb +20 -0
  29. data/lib/jetel/loaders/pg/sql/create_table.sql.erb +20 -0
  30. data/lib/jetel/loaders/pg/sql/drop_table.sql.erb +20 -0
  31. data/lib/jetel/loaders/pg/sql/header.sql.erb +20 -0
  32. data/lib/jetel/loaders/pg/sql/schema.sql.erb +20 -0
  33. data/lib/jetel/loaders/pg/sql/truncate_table.sql.erb +20 -0
  34. data/lib/jetel/modules/alexa/alexa.rb +19 -0
  35. data/lib/jetel/modules/gadm/gadm.rb +5 -1
  36. data/lib/jetel/modules/geolite/geolite.rb +19 -0
  37. data/lib/jetel/modules/ip/ip.rb +20 -0
  38. data/lib/jetel/modules/iso3166/iso3166.rb +20 -0
  39. data/lib/jetel/modules/module.rb +46 -4
  40. data/lib/jetel/modules/modules.rb +22 -0
  41. data/lib/jetel/modules/nga/nga.rb +20 -0
  42. data/lib/jetel/modules/sfpd/sfpd.rb +20 -0
  43. data/lib/jetel/modules/tiger/tiger.rb +113 -0
  44. data/lib/jetel/modules/wifileaks/wifileaks.rb +21 -1
  45. data/lib/jetel/version.rb +21 -1
  46. data/spec/helpers/general_helper_spec.rb +16 -0
  47. data/spec/modules/alexa_spec.rb +0 -0
  48. data/{test → spec}/spec_helper.rb +0 -0
  49. metadata +10 -5
  50. data/Gemfile.lock +0 -156
@@ -1,2 +1,22 @@
1
+ -- Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
2
+
3
+ -- Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ -- of this software and associated documentation files (the "Software"), to deal
5
+ -- in the Software without restriction, including without limitation the rights
6
+ -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ -- copies of the Software, and to permit persons to whom the Software is
8
+ -- furnished to do so, subject to the following conditions:
9
+ --
10
+ -- The above copyright notice and this permission notice shall be included in
11
+ -- all copies or substantial portions of the Software.
12
+ --
13
+ -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ -- THE SOFTWARE.
20
+
1
21
  TRUNCATE "<%= ctx[:table] %>";
2
22
 
@@ -1,5 +1,24 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
3
22
  require 'pmap'
4
23
  require 'pty'
5
24
 
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+
4
+
3
5
  require 'pmap'
4
6
 
5
7
  require_relative '../../config/config'
@@ -24,7 +26,9 @@ module Jetel
24
26
  {
25
27
  name: name,
26
28
  url: "http://biogeo.ucdavis.edu/data/gadm2.8/shp/#{filename}",
27
- filename_downloaded: filename
29
+ filename_downloaded: filename,
30
+ flat: true,
31
+ filename_transformed: "#{name}_adm?.topo.json"
28
32
  }
29
33
  end
30
34
 
@@ -1,5 +1,24 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
3
22
  require 'pmap'
4
23
 
5
24
  require_relative '../../config/config'
@@ -1,5 +1,25 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
3
23
  require 'pmap'
4
24
  require 'csv'
5
25
 
@@ -1,5 +1,25 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
3
23
  require 'nokogiri'
4
24
  require 'open-uri'
5
25
  require 'pmap'
@@ -1,5 +1,27 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'multi_json'
24
+ require 'pp'
3
25
  require 'zip'
4
26
 
5
27
  require_relative '../downloaders/downloader'
@@ -14,7 +36,7 @@ module Jetel
14
36
  def target_dir(modul, source, dir, *path)
15
37
  klass = modul.class.name.split('::').last
16
38
  source_name = Helper.sanitize(source[:name])
17
- File.join(dir.kind_of?(String) ? dir : dir['download_dir'] || Config[:DATA_DIRECTORY], klass, source_name, path)
39
+ File.join(dir.kind_of?(Hash) ? dir['download_dir'] : dir || Config[:DATA_DIRECTORY], klass, source[:flat] ? '' : source_name, path)
18
40
  end
19
41
 
20
42
  def download_dir(modul, source, opts)
@@ -47,7 +69,11 @@ module Jetel
47
69
  end
48
70
 
49
71
  def download_source(source, opts)
50
- downloader.download(source[:url], {:dir => download_dir(source, opts), :filename => source[:filename_downloaded]})
72
+ downloaded_file = downloaded_file(source, opts)
73
+
74
+ unless File.exists?(downloaded_file)
75
+ downloader.download(source[:url], {:dir => download_dir(source, opts), :filename => source[:filename_downloaded]})
76
+ end
51
77
  end
52
78
 
53
79
  def target_dir(source, opts, *path)
@@ -87,17 +113,33 @@ module Jetel
87
113
  end
88
114
  end
89
115
 
90
- sources.pmap(8) do |source|
116
+ sources.map do |source|
91
117
  opts = global_options.merge(options)
92
118
 
93
119
  transformed_file = transformed_file(source, opts)
94
120
 
95
121
  loader = Helper.get_loader(opts['data_loader'])
96
122
 
97
- loader.load(self, source, transformed_file, opts)
123
+ Dir.glob(transformed_file).each do |one_file|
124
+ puts "Loading file #{one_file}"
125
+ loader.load(self, source, one_file, opts)
126
+ end
98
127
  end
99
128
  end
100
129
 
130
+ def sources(global_options, options, _args)
131
+ opts = global_options.merge(options)
132
+
133
+ res = self.class.sources
134
+
135
+ if opts['format'] == 'json'
136
+ puts MultiJson.dump(res, :pretty => true)
137
+ else
138
+ pp res
139
+ end
140
+
141
+ end
142
+
101
143
  def unzip(source, options = {})
102
144
  downloaded_file = downloaded_file(source, options)
103
145
  dest_dir = extract_dir(source, options)
@@ -1,3 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
1
23
  require 'active_support/inflector'
2
24
  require_relative '../extensions/extensions'
3
25
 
@@ -1,5 +1,25 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
3
23
  require 'pmap'
4
24
 
5
25
  require_relative '../../modules/module'
@@ -1,5 +1,25 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
3
23
  require 'pmap'
4
24
 
5
25
  require_relative '../../config/config'
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'pmap'
24
+
25
+ require_relative '../../config/config'
26
+ require_relative '../../modules/module'
27
+
28
+ require 'nokogiri'
29
+ require 'open-uri'
30
+
31
+ module Jetel
32
+ module Modules
33
+ class Tiger < Module
34
+ BASE_URL = 'http://www2.census.gov/geo/tiger/TIGER2015'
35
+ CSS_SELECTOR = '#innerPage > table > tr > td > a'
36
+
37
+ class << self
38
+ def sub_sources(base_url)
39
+ page = Nokogiri::HTML(open(base_url))
40
+
41
+ links = page.css(CSS_SELECTOR)
42
+
43
+ links[1..-1].map do |link|
44
+ next unless link
45
+ name = base_url.split('/').last # link.text.gsub('/', '')
46
+ href = link.attr('href')
47
+
48
+ {
49
+ name: name,
50
+ url: "#{base_url}#{href}".gsub('http://www2', 'ftp://ftp'),
51
+ filename_downloaded: href,
52
+ # flat: true,
53
+ # filename_transformed: "#{name}_adm?.topo.json"
54
+ }
55
+ end
56
+ end
57
+
58
+ def sources
59
+ page = Nokogiri::HTML(open(BASE_URL))
60
+
61
+ links = page.css(CSS_SELECTOR)
62
+
63
+ res = links[2..-1].pmap(8) do |link|
64
+ next unless link
65
+ href = link.attr('href')
66
+ url = "#{BASE_URL}/#{href}"
67
+
68
+ puts "Processing #{url}"
69
+ tmp = sub_sources(url)
70
+ end
71
+
72
+ res.flatten
73
+ end
74
+ end
75
+
76
+ def download(global_options, options, args)
77
+ self.class.sources.pmap(16) do |source|
78
+ download_source(source, global_options.merge(options))
79
+ end
80
+ end
81
+
82
+ def extract(global_options, options, args)
83
+ self.class.sources.map do |source|
84
+ unzip(source, global_options.merge(options))
85
+ end
86
+ end
87
+
88
+ def transform(global_options, options, args)
89
+ self.class.sources.pmap(8) do |source|
90
+ extracted_file = extracted_file(source, global_options.merge(options))
91
+ transformed_file = transformed_file(source, global_options.merge(options))
92
+ dest_dir = transform_dir(source, global_options.merge(options))
93
+ FileUtils.mkdir_p(dest_dir)
94
+
95
+ extracted_dir = extract_dir(source, global_options.merge(options))
96
+ Dir.glob("#{extracted_dir}/*.shp") do |shapefile|
97
+ puts "Transforming #{shapefile}"
98
+
99
+ # "topojson data/Gadm/AFG/extracted/AFG_adm0.shp -o data/Gadm/AFG/transformed/AFG_adm0.topo.json"
100
+ cmd = "topojson #{shapefile} -o #{shapefile.gsub(extracted_dir, dest_dir).gsub('.shp', '.topo.json')}"
101
+ puts cmd
102
+ PTY.spawn(cmd) do |stdout, stdin, pid|
103
+ begin
104
+ # Do stuff with the output here. Just printing to show it works
105
+ stdout.each { |line| print line }
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -1,5 +1,26 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # Copyright (c) 2015, Tomas Korcak <korczis@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'fileutils'
3
24
  require 'pmap'
4
25
 
5
26
  require_relative '../../config/config'
@@ -72,7 +93,6 @@ module Jetel
72
93
  res = super(global_options, options.merge({:delimiter => "\t"}), args)
73
94
  res
74
95
  end
75
-
76
96
  end
77
97
  end
78
98
  end