terrimporter 0.7.3 → 0.7.4
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/Gemfile.lock +1 -1
- data/README.rdoc +4 -0
- data/config/schema.yml +10 -0
- data/config/terrimporter.yml +5 -1
- data/lib/terrimporter/app_logger.rb +14 -11
- data/lib/terrimporter/array_monkeypatch.rb +1 -1
- data/lib/terrimporter/configuration.rb +60 -87
- data/lib/terrimporter/configuration_helper.rb +31 -22
- data/lib/terrimporter/configuration_loader.rb +85 -0
- data/lib/terrimporter/download_helper.rb +1 -1
- data/lib/terrimporter/downloader.rb +19 -10
- data/lib/terrimporter/error.rb +10 -0
- data/lib/terrimporter/importer.rb +57 -49
- data/lib/terrimporter/statistic.rb +37 -0
- data/lib/terrimporter/stylesheet_importer.rb +56 -0
- data/lib/terrimporter/version.rb +2 -2
- data/lib/terrimporter.rb +12 -2
- data/test/fixtures/invalid.config.yml +1 -0
- data/test/fixtures/js/dynplugin.js +1 -0
- data/test/fixtures/minimal.test.config.yml +1 -0
- data/test/fixtures/test.config.yml +3 -0
- data/test/unit/test_arraymonkeypatch.rb +1 -1
- data/test/unit/test_configuration.rb +14 -107
- data/test/unit/{test_config_helper.rb → test_configuration_helper.rb} +7 -6
- data/test/unit/test_configuration_loader.rb +86 -0
- data/test/unit/test_downloader.rb +16 -5
- data/test/unit/test_importer.rb +3 -1
- data/test/unit/test_statistics.rb +44 -0
- metadata +16 -6
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
This package contains terrimporter, a simple command line utility to help import terrific (http://www.terrifically.org/)
|
4
4
|
files such as javascripts, stylesheets, images and modules into your web project.
|
5
5
|
|
6
|
+
terrimporter is compatible and has been tested against terrific 0.5.
|
7
|
+
Backwards compatibility cannot be guaranteed!
|
8
|
+
It will be updated to support newer terrific versions, especially the next 0.6 release with big api changes.
|
9
|
+
|
6
10
|
terrimporter has the following features:
|
7
11
|
|
8
12
|
* Import the generated base.js file
|
data/config/schema.yml
CHANGED
@@ -8,6 +8,10 @@ mapping:
|
|
8
8
|
type: str
|
9
9
|
required: yes
|
10
10
|
pattern: /\/.*/
|
11
|
+
"plugins_server_path":
|
12
|
+
type: str
|
13
|
+
required: yes
|
14
|
+
pattern: /\/.*/
|
11
15
|
"image_server_path":
|
12
16
|
type: str
|
13
17
|
required: yes
|
@@ -60,6 +64,12 @@ mapping:
|
|
60
64
|
"libraries_destination_path":
|
61
65
|
type: str
|
62
66
|
required: no
|
67
|
+
"dynamic_plugins":
|
68
|
+
type: str
|
69
|
+
required: no
|
70
|
+
"plugins_destination_path":
|
71
|
+
type: str
|
72
|
+
required: no
|
63
73
|
"images":
|
64
74
|
type: seq
|
65
75
|
required: no
|
data/config/terrimporter.yml
CHANGED
@@ -34,6 +34,9 @@ javascripts:
|
|
34
34
|
# dynamic_libraries: foo_lib.js bar_lib.js
|
35
35
|
# Destination path of the dynamic libraries (relative)
|
36
36
|
# libraries_destination_path: public/javascripts/libraries/
|
37
|
+
# Destination path of the dynamic plugins
|
38
|
+
# dynamic_plugins: dynamic.js
|
39
|
+
# plugins_destination_path: public/javascript/plugins/
|
37
40
|
|
38
41
|
# IMAGES - multiple entries allowed
|
39
42
|
images:
|
@@ -58,8 +61,9 @@ export_settings:
|
|
58
61
|
cache: false # You most probably won't have to change this
|
59
62
|
layout: project # You most probably won't have to change this
|
60
63
|
|
61
|
-
# The server side
|
64
|
+
# The server side libraries and plugins source path for the dynamic libraries and dynamic plugins
|
62
65
|
libraries_server_path: /js/libraries/dynamic
|
66
|
+
plugins_server_path: /js/plugins/dynamic
|
63
67
|
|
64
68
|
# The server side image base path
|
65
69
|
image_server_path: /img
|
@@ -1,5 +1,8 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
|
1
4
|
class Logger
|
2
|
-
attr_accessor :level
|
5
|
+
attr_accessor :level, :log_format
|
3
6
|
|
4
7
|
LOG_LEVELS = {:debug => 0, :info => 1, :warn => 2, :error=> 3, :fatal => 4}
|
5
8
|
LOG_COLORS = {:debug =>'33', :info =>'32', :warn =>'33', :error=>'31', :fatal =>'31'}
|
@@ -11,13 +14,18 @@ class Logger
|
|
11
14
|
#\033[033m Yellow
|
12
15
|
#\033[031m Red
|
13
16
|
#\033[037m White
|
14
|
-
|
15
17
|
# %s => [datetime], %s => color, %-5s => severity, %s => message
|
16
|
-
|
18
|
+
LOG_FORMAT_UNIX = "\033[0;37m %s \033[0m[\033[%sm%-5s\033[0m]: %s \n"
|
19
|
+
LOG_FORMAT_WINDOWS = "%s %s[%-5s]: %s \n"
|
17
20
|
TIME_FORMAT = "%H:%M:%S"
|
18
21
|
|
22
|
+
def is_windows
|
23
|
+
!((Config::CONFIG['host_os'] =~ /mswin|mingw/).nil?)
|
24
|
+
end
|
25
|
+
|
19
26
|
def initialize
|
20
27
|
self.level = :debug
|
28
|
+
self.log_format = is_windows ? LOG_FORMAT_WINDOWS : LOG_FORMAT_UNIX
|
21
29
|
end
|
22
30
|
|
23
31
|
def error(message)
|
@@ -34,19 +42,14 @@ class Logger
|
|
34
42
|
|
35
43
|
def log(severity, message)
|
36
44
|
return if LOG_LEVELS[severity] < LOG_LEVELS[self.level]
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
$stderr.puts(LOG_FORMAT % [format_datetime(Time.now), color, severity.to_s.upcase, message])
|
41
|
-
else
|
42
|
-
$stdout.puts(LOG_FORMAT % [format_datetime(Time.now), color, severity.to_s.upcase, message])
|
43
|
-
end
|
45
|
+
color = is_windows ? '' : LOG_COLORS[severity]
|
46
|
+
out = LOG_LEVELS[severity] >= LOG_LEVELS[:error] ? $stderr : $stdout
|
47
|
+
out.puts(self.log_format % [format_datetime(Time.now), color, severity.to_s.upcase, message])
|
44
48
|
end
|
45
49
|
|
46
50
|
def format_datetime(time)
|
47
51
|
time.strftime(TIME_FORMAT)
|
48
52
|
end
|
49
|
-
|
50
53
|
end
|
51
54
|
|
52
55
|
LOG = Logger.new
|
@@ -1,120 +1,77 @@
|
|
1
|
-
#require 'etc'
|
2
|
-
#require 'kwalify'
|
3
|
-
|
4
1
|
module TerrImporter
|
5
2
|
class Application
|
6
3
|
class Configuration < Hash
|
7
|
-
include ConfigurationHelper
|
8
|
-
|
9
|
-
attr_accessor :validations, :config_file
|
10
4
|
|
11
|
-
|
12
|
-
self.config_file = config_file unless config_file.nil?
|
5
|
+
attr_accessor :validations
|
13
6
|
|
7
|
+
def application_url
|
8
|
+
self['application_url']
|
14
9
|
end
|
15
10
|
|
16
|
-
def
|
17
|
-
|
18
|
-
LOG.debug "Configuration file located, load from #{config_file_path}"
|
19
|
-
validate_and_load_config(config_file_path)
|
11
|
+
def css_export_path
|
12
|
+
self['css_export_path']
|
20
13
|
end
|
21
14
|
|
22
|
-
def
|
23
|
-
|
24
|
-
return self.config_file
|
25
|
-
end
|
26
|
-
|
27
|
-
valid_config_paths.each do |path|
|
28
|
-
file_path = File.join path, config_default_name
|
29
|
-
return file_path if File.exists?(file_path) and not file_path.include?(File.join('terrimporter', 'config')) #default config NOT valid
|
30
|
-
end
|
31
|
-
|
32
|
-
raise ConfigurationError, %Q{config file #{config_default_name} not found in search paths. Search paths are:
|
33
|
-
#{valid_config_paths.join "\n"} \n If this is a new project, run with the option --init}
|
15
|
+
def js_export_path
|
16
|
+
self['js_export_path']
|
34
17
|
end
|
35
18
|
|
36
|
-
def
|
37
|
-
[
|
38
|
-
Dir.pwd,
|
39
|
-
File.join(Dir.pwd, 'config'),
|
40
|
-
File.join(Dir.pwd, '.config'),
|
41
|
-
]
|
19
|
+
def stylesheets_destination
|
20
|
+
self['stylesheets']['destination_path']
|
42
21
|
end
|
43
22
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
parser = Kwalify::Yaml::Parser.new(load_validator)
|
48
|
-
document = parser.parse_file(file)
|
49
|
-
|
50
|
-
errors = parser.errors()
|
51
|
-
if errors && !errors.empty?
|
52
|
-
error_message = errors.inject("") { |result, e| result << "#{e.linenum}:#{e.column} [#{e.path}] #{e.message}\n" }
|
53
|
-
raise ConfigurationError, error_message
|
54
|
-
end
|
55
|
-
self.merge! document
|
56
|
-
|
23
|
+
def stylesheet_replace_strings
|
24
|
+
self['stylesheets']['replace_strings']
|
57
25
|
end
|
58
26
|
|
59
|
-
def
|
60
|
-
|
61
|
-
schema = Kwalify::Yaml.load_file(schema_file_path)
|
62
|
-
Kwalify::Validator.new(schema)
|
27
|
+
def javascripts_destination
|
28
|
+
self['javascripts']['destination_path']
|
63
29
|
end
|
64
30
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
31
|
+
def stylesheets
|
32
|
+
stylesheet_list = ["base.css"]
|
33
|
+
if has_stylesheets?
|
34
|
+
stylesheet_list = stylesheet_list + self['stylesheets']['styles'].to_s.robust_split
|
68
35
|
else
|
69
|
-
|
36
|
+
LOG.debug "No additional stylesheets defined in configuration file."
|
70
37
|
end
|
38
|
+
stylesheet_list.add_missing_extension!('.css')
|
71
39
|
end
|
72
40
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
raise ConfigurationError, "Unable to extract css information from application url, content is: #{raw_html}" if css_result.nil? or css_result.size < 5
|
77
|
-
raise ConfigurationError, "Unable to extract javascript information from application url, content is: #{raw_html}" if js_result.nil? or js_result.size < 5
|
78
|
-
|
79
|
-
css_export_path = css_result[0]
|
80
|
-
js_export_path = js_result[0]
|
81
|
-
terrific_version = css_result[1]
|
82
|
-
application = css_result[3]
|
41
|
+
def images
|
42
|
+
self['images']
|
43
|
+
end
|
83
44
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
raise ConfigurationError, "Unable to determine application path" if application.nil?
|
45
|
+
def modules
|
46
|
+
self['modules']
|
47
|
+
end
|
88
48
|
|
89
|
-
|
90
|
-
|
91
|
-
|
49
|
+
def images_server_path
|
50
|
+
self['image_server_path']
|
51
|
+
end
|
92
52
|
|
93
|
-
|
94
|
-
self['
|
95
|
-
self['export_settings']['application'] = application
|
96
|
-
self['export_path'] = {'css' => css_export_path, 'js' => js_export_path}
|
53
|
+
def libraries_server_path
|
54
|
+
self['libraries_server_path']
|
97
55
|
end
|
98
56
|
|
99
|
-
def
|
100
|
-
|
101
|
-
if additional_stylesheets?
|
102
|
-
stylesheets = stylesheets + self['stylesheets']['styles'].to_s.robust_split
|
103
|
-
else
|
104
|
-
LOG.debug "No additional stylesheets defined."
|
105
|
-
end
|
106
|
-
stylesheets.add_if_missing!('.css')
|
57
|
+
def plugins_server_path
|
58
|
+
self['plugins_server_path']
|
107
59
|
end
|
108
60
|
|
109
61
|
def dynamic_libraries
|
110
62
|
libraries = self['javascripts']['dynamic_libraries'].robust_split
|
111
|
-
libraries.
|
63
|
+
libraries.add_missing_extension!('.js')
|
64
|
+
end
|
65
|
+
|
66
|
+
def dynamic_plugins
|
67
|
+
libraries = self['javascripts']['dynamic_plugins'].robust_split
|
68
|
+
libraries.add_missing_extension!('.js')
|
112
69
|
end
|
113
70
|
|
114
71
|
def replace_style_strings?
|
115
72
|
!self['stylesheets'].nil? and
|
116
|
-
|
117
|
-
|
73
|
+
!self['stylesheets']['replace_strings'].nil? and
|
74
|
+
!self['stylesheets']['replace_strings'].first.nil?
|
118
75
|
end
|
119
76
|
|
120
77
|
def libraries_destination_path
|
@@ -125,19 +82,35 @@ module TerrImporter
|
|
125
82
|
end
|
126
83
|
end
|
127
84
|
|
128
|
-
def
|
85
|
+
def plugins_destination_path
|
86
|
+
if !self['javascripts']['plugins_destination_path'].nil?
|
87
|
+
File.join(self['javascripts']['plugins_destination_path'])
|
88
|
+
else
|
89
|
+
File.join(self['javascripts']['destination_path'])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def export_settings
|
94
|
+
self['export_settings']
|
95
|
+
end
|
96
|
+
|
97
|
+
def has_stylesheets?
|
129
98
|
!self['stylesheets'].nil? and !self['stylesheets']['styles'].nil?
|
130
99
|
end
|
131
100
|
|
132
|
-
def
|
101
|
+
def has_dynamic_javascripts?
|
133
102
|
!self['javascripts'].nil? and !self['javascripts']['dynamic_libraries'].nil?
|
134
103
|
end
|
135
104
|
|
136
|
-
def
|
105
|
+
def has_dynamic_plugins?
|
106
|
+
!self['javascripts'].nil? and !self['javascripts']['dynamic_plugins'].nil?
|
107
|
+
end
|
108
|
+
|
109
|
+
def has_images?
|
137
110
|
!self['images'].nil?
|
138
111
|
end
|
139
112
|
|
140
|
-
def
|
113
|
+
def has_modules?
|
141
114
|
!self['modules'].nil?
|
142
115
|
end
|
143
116
|
|
@@ -1,5 +1,28 @@
|
|
1
1
|
module ConfigurationHelper
|
2
2
|
|
3
|
+
def backup_config_file
|
4
|
+
LOG.debug "Backing up old configuration file to #{config_working_directory_path}.bak"
|
5
|
+
FileUtils.mv(config_working_directory_path, config_working_directory_path + '.bak')
|
6
|
+
end
|
7
|
+
|
8
|
+
def remove_config_file
|
9
|
+
LOG.debug "Removing old configuration file"
|
10
|
+
FileUtils.rm_f(config_working_directory_path) if File.exists? config_working_directory_path
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_config_file(application_url = nil)
|
14
|
+
LOG.info "Creating configuration file..."
|
15
|
+
FileUtils.cp(config_example_path, config_working_directory_path)
|
16
|
+
|
17
|
+
unless application_url.nil?
|
18
|
+
configuration = File.read(config_working_directory_path)
|
19
|
+
configuration.gsub!(/application_url:.*$/, "application_url: #{application_url}")
|
20
|
+
File.open(config_working_directory_path, 'w') { |f| f.write(configuration) }
|
21
|
+
end
|
22
|
+
|
23
|
+
LOG.info "done! You should take a look an edit it to your needs..."
|
24
|
+
end
|
25
|
+
|
3
26
|
def config_default_name
|
4
27
|
'terrimporter.yml'
|
5
28
|
end
|
@@ -8,6 +31,14 @@ module ConfigurationHelper
|
|
8
31
|
'schema.yml'
|
9
32
|
end
|
10
33
|
|
34
|
+
def config_search_paths
|
35
|
+
[
|
36
|
+
Dir.pwd,
|
37
|
+
File.join(Dir.pwd, 'config'),
|
38
|
+
File.join(Dir.pwd, '.config'),
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
11
42
|
def config_working_directory_path
|
12
43
|
File.expand_path config_default_name
|
13
44
|
end
|
@@ -24,28 +55,6 @@ module ConfigurationHelper
|
|
24
55
|
File.join(base_config_path, schema_default_name)
|
25
56
|
end
|
26
57
|
|
27
|
-
def create_config_file(backup_or_replace = nil, application_url = nil)
|
28
|
-
LOG.info "Creating configuration file..."
|
29
|
-
case backup_or_replace
|
30
|
-
when :backup
|
31
|
-
LOG.debug "Backing up old configuration file to #{config_working_directory_path}.bak"
|
32
|
-
FileUtils.mv(config_working_directory_path, config_working_directory_path + '.bak')
|
33
|
-
when :replace
|
34
|
-
LOG.debug "Replacing old configuration file"
|
35
|
-
FileUtils.rm_f(config_working_directory_path) if File.exists? config_working_directory_path
|
36
|
-
end
|
37
|
-
FileUtils.cp(config_example_path, config_working_directory_path)
|
38
|
-
|
39
|
-
unless application_url.nil?
|
40
|
-
configuration = File.read(config_working_directory_path)
|
41
|
-
configuration.gsub!(/application_url:.*$/, "application_url: #{application_url}")
|
42
|
-
File.open(config_working_directory_path, 'w') { |f| f.write(configuration) }
|
43
|
-
end
|
44
|
-
|
45
|
-
LOG.info "done! You should take a look an edit it to your needs..."
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
58
|
def base_config_path
|
50
59
|
File.join(File.dirname(__FILE__), '..', '..', 'config')
|
51
60
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module TerrImporter
|
2
|
+
class Application
|
3
|
+
class ConfigurationLoader
|
4
|
+
include ConfigurationHelper
|
5
|
+
|
6
|
+
attr_accessor :config_file
|
7
|
+
|
8
|
+
def initialize(config_file = nil)
|
9
|
+
self.config_file = config_file unless config_file.nil?
|
10
|
+
end
|
11
|
+
|
12
|
+
#todo also complete missing values here, after this step everything should work...
|
13
|
+
def load_configuration
|
14
|
+
config_file_path = determine_config_file_path
|
15
|
+
LOG.debug "Configuration file located, load from #{config_file_path}"
|
16
|
+
c = Configuration.new
|
17
|
+
c.merge!(validate_and_load_config(config_file_path))
|
18
|
+
c['version'], c['export_settings']['application'], c['css_export_path'], c['js_export_path'] = determine_configuration_values_from_html(Downloader.new(c['application_url']).download(''))
|
19
|
+
c
|
20
|
+
end
|
21
|
+
|
22
|
+
def determine_config_file_path
|
23
|
+
return self.config_file unless self.config_file.nil?
|
24
|
+
|
25
|
+
config_search_paths.each do |path|
|
26
|
+
file_path = File.join(path, config_default_name)
|
27
|
+
#default config supplied with terrimporter NOT valid
|
28
|
+
return file_path if File.exists?(file_path) and not file_path.include?(File.join('terrimporter', 'config'))
|
29
|
+
end
|
30
|
+
|
31
|
+
raise ConfigurationError, %Q{Configuration file #{config_default_name} not found in search paths. Search paths are:
|
32
|
+
#{config_search_paths.join "\n"} \n If this is a new project, run with the option --init}
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_and_load_config(file)
|
36
|
+
LOG.debug "Validate configuration file"
|
37
|
+
parser = Kwalify::Yaml::Parser.new(load_validator)
|
38
|
+
document = parser.parse_file(file)
|
39
|
+
errors = parser.errors()
|
40
|
+
|
41
|
+
if errors && !errors.empty?
|
42
|
+
error_message = errors.inject("") { |result, e| result << "#{e.linenum}:#{e.column} [#{e.path}] #{e.message}\n" }
|
43
|
+
raise ConfigurationError, error_message
|
44
|
+
end
|
45
|
+
document
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_validator
|
49
|
+
LOG.debug "Loading configuration file validator from #{schema_file_path}"
|
50
|
+
schema = Kwalify::Yaml.load_file(schema_file_path)
|
51
|
+
Kwalify::Validator.new(schema)
|
52
|
+
end
|
53
|
+
|
54
|
+
def determine_configuration_values_from_html(raw_html)
|
55
|
+
css_result, js_result = raw_html.scan(/(\/terrific\/base\/(.*?)\/public\/.*base.(css|js).php)\?.*application=(.*?)(&|&)/)
|
56
|
+
|
57
|
+
raise ConfigurationError, "Unable to extract css information from application url, content is: #{raw_html}" if css_result.nil? or css_result.size < 5
|
58
|
+
raise ConfigurationError, "Unable to extract javascript information from application url, content is: #{raw_html}" if js_result.nil? or js_result.size < 5
|
59
|
+
|
60
|
+
css_export_path = css_result[0]
|
61
|
+
js_export_path = js_result[0]
|
62
|
+
terrific_version = css_result[1]
|
63
|
+
application = css_result[3]
|
64
|
+
|
65
|
+
raise ConfigurationError, "Unable to determine css export path" if css_export_path.nil?
|
66
|
+
raise ConfigurationError, "Unable to determine js export path " if js_export_path.nil?
|
67
|
+
raise ConfigurationError, "Unable to determine terrific version" if terrific_version.nil?
|
68
|
+
raise ConfigurationError, "Unable to determine application path" if application.nil?
|
69
|
+
|
70
|
+
LOG.info "Determined the following configuration values:\n" +
|
71
|
+
"terrific version: #{terrific_version} \n" +
|
72
|
+
"application path: #{application}"
|
73
|
+
|
74
|
+
#self['version'] = terrific_version
|
75
|
+
#self['export_settings'] ||= {}
|
76
|
+
#self['export_settings']['application'] = application
|
77
|
+
#self['css_export_path'] = css_export_path
|
78
|
+
#self['js_export_path'] = js_export_path
|
79
|
+
[terrific_version, application, css_export_path, js_export_path]
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -15,23 +15,32 @@ module TerrImporter
|
|
15
15
|
remote_url = url(remote_path)
|
16
16
|
begin
|
17
17
|
if local_path.nil? #download to buffer
|
18
|
-
|
19
|
-
data = StringIO.new
|
20
|
-
remote_url.open { |io| data = io.read }
|
21
|
-
data.to_s
|
18
|
+
download_to_buffer(remote_url)
|
22
19
|
else
|
23
|
-
|
24
|
-
|
25
|
-
open(local_path, "wb") { |file| file.write(remote_url.open.read) }
|
20
|
+
download_to_file(remote_url, local_path)
|
21
|
+
STAT.add(:download, 1)
|
26
22
|
end
|
27
|
-
rescue
|
28
|
-
raise DefaultError, "Error opening url #{remote_url}
|
23
|
+
rescue Exception => e
|
24
|
+
raise DefaultError, "Error opening url: #{remote_url}"
|
29
25
|
end
|
30
26
|
end
|
31
27
|
|
28
|
+
def download_to_buffer(remote_url)
|
29
|
+
LOG.debug "Download #{remote_url} to buffer"
|
30
|
+
data = StringIO.new
|
31
|
+
remote_url.open { |io| data = io.read }
|
32
|
+
data.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
def download_to_file(remote_url, local_path)
|
36
|
+
LOG.info "Download #{remote_url} to local path #{local_path}"
|
37
|
+
create_directory File.dirname(local_path)
|
38
|
+
open(local_path, "wb") { |file| file.write(remote_url.open.read) }
|
39
|
+
end
|
40
|
+
|
32
41
|
def batch_download(remote_path, local_path, type_filter = "")
|
33
42
|
source_path = url(remote_path)
|
34
|
-
|
43
|
+
create_directory local_path
|
35
44
|
LOG.debug "Download multiple files from #{source_path} to #{local_path} #{"allowed extensions: " + type_filter unless type_filter.empty?}"
|
36
45
|
|
37
46
|
files = html_directory_list(source_path)
|