terrimporter 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,12 @@ require 'fileutils'
19
19
  require 'yaml'
20
20
  require 'uri'
21
21
 
22
+ STAT.add_message(:download, "total files downloaded")
23
+ STAT.add_message(:css, "stylesheets downloaded")
24
+ STAT.add_message(:js, "javascripts downloaded")
25
+ STAT.add_message(:image, "images downloaded")
26
+ STAT.add_message(:module, "html modules downloaded")
27
+
22
28
  module TerrImporter
23
29
  class Application
24
30
  class << self
@@ -52,30 +52,36 @@ module TerrImporter
52
52
  end
53
53
 
54
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=(.*?)(&amp;|&)/)
55
+ #todo this regex does it wrong, it extracts all references and can't decide between js and css. also the version is wrongly extracted if the base path isn't correct
56
+ results = raw_html.scan(/(\/terrific\/base\/(.*?)\/public\/.*base.(css|js).php)\?.*application=(.*?)(&amp;|&)/)
57
+ results.uniq!
58
+
59
+ css_result =results.select{|v| v[2] == "css"}.first
60
+ js_result =results.select{|v| v[2] == "js"}.first
61
+
56
62
 
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
63
  raise ConfigurationError, "Unable to extract javascript information from application url, content is: #{raw_html}" if js_result.nil? or js_result.size < 5
59
64
 
60
65
  css_export_path = css_result[0]
61
66
  js_export_path = js_result[0]
62
- terrific_version = css_result[1]
67
+ terrific_version = css_result[1] #todo: if it looks like this tags/0.4.0 -> extract number, remove everything before and inclusive /
63
68
  application = css_result[3]
64
69
 
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?
70
+ case nil
71
+ when css_export_path
72
+ raise ConfigurationError, "Unable to determine css export path"
73
+ when js_export_path
74
+ raise ConfigurationError, "Unable to determine js export path"
75
+ when terrific_version
76
+ raise ConfigurationError, "Unable to determine terrific version"
77
+ when application
78
+ raise ConfigurationError, "Unable to determine application path"
79
+ end
69
80
 
70
81
  LOG.info "Determined the following configuration values:\n" +
71
82
  "terrific version: #{terrific_version} \n" +
72
83
  "application path: #{application}"
73
84
 
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
85
  [terrific_version, application, css_export_path, js_export_path]
80
86
  end
81
87
 
@@ -18,10 +18,10 @@ module TerrImporter
18
18
  download_to_buffer(remote_url)
19
19
  else
20
20
  download_to_file(remote_url, local_path)
21
- STAT.add(:download, 1)
21
+ STAT.add(:download)
22
22
  end
23
23
  rescue Exception => e
24
- raise DefaultError, "Error opening url: #{remote_url}"
24
+ raise DefaultError, "Error opening url: #{remote_url}, message: #{e.message}"
25
25
  end
26
26
  end
27
27
 
@@ -38,7 +38,7 @@ module TerrImporter
38
38
  open(local_path, "wb") { |file| file.write(remote_url.open.read) }
39
39
  end
40
40
 
41
- def batch_download(remote_path, local_path, type_filter = "")
41
+ def batch_download(remote_path, local_path, type_filter = "", statistics_key = nil)
42
42
  source_path = url(remote_path)
43
43
  create_directory local_path
44
44
  LOG.debug "Download multiple files from #{source_path} to #{local_path} #{"allowed extensions: " + type_filter unless type_filter.empty?}"
@@ -54,6 +54,7 @@ module TerrImporter
54
54
  files.each do |file|
55
55
  local_file_path = File.join(local_path.to_s, file)
56
56
  self.download(File.join(source_path.to_s, file), local_file_path)
57
+ STAT.add(statistics_key) unless statistics_key.nil?
57
58
  end
58
59
  end
59
60
 
@@ -55,7 +55,7 @@ module TerrImporter
55
55
  unclean_file_path = file_path + unclean_suffix;
56
56
  constructed_file_path = (config.replace_style_strings? ? unclean_file_path : file_path)
57
57
  @downloader.download(source_url, constructed_file_path)
58
-
58
+ STAT.add(:css)
59
59
  if file_contains_valid_css?(constructed_file_path)
60
60
  if config.replace_style_strings?
61
61
  LOG.info "CSS line replacements"
@@ -88,7 +88,7 @@ module TerrImporter
88
88
  js_source_url = export_path(:js)
89
89
  LOG.debug "Import base.js from #{js_source_url} to #{file_path}"
90
90
  @downloader.download(js_source_url, file_path)
91
-
91
+ STAT.add(:js)
92
92
  if config.has_dynamic_javascripts?
93
93
  if config.libraries_server_path.nil?
94
94
  LOG.info "Define 'libraries_server_path' in configuration file"
@@ -98,6 +98,7 @@ module TerrImporter
98
98
  js_libraries = config.dynamic_libraries
99
99
  js_libraries.each do |lib|
100
100
  @downloader.download(File.join(config.libraries_server_path, lib), File.join(libraries_file_path, lib))
101
+ STAT.add(:js)
101
102
  end
102
103
  end
103
104
  end
@@ -111,6 +112,7 @@ module TerrImporter
111
112
  js_plugins = config.dynamic_plugins
112
113
  js_plugins.each do |lib|
113
114
  @downloader.download(File.join(config.plugins_server_path, lib), File.join(plugins_file_path, lib))
115
+ STAT.add(:js)
114
116
  end
115
117
  end
116
118
  end
@@ -122,7 +124,7 @@ module TerrImporter
122
124
  LOG.info "Import images"
123
125
  config.images.each do |image|
124
126
  image_source_path = File.join(config.images_server_path, image['server_path'])
125
- @downloader.batch_download(image_source_path, image['destination_path'], image['file_types'])
127
+ @downloader.batch_download(image_source_path, image['destination_path'], image['file_types'], :image)
126
128
  end
127
129
  else
128
130
  LOG.debug "Skipping image import"
@@ -140,6 +142,7 @@ module TerrImporter
140
142
  filename = name.clone
141
143
  filename << "_#{skin}" unless skin.to_s.strip.length == 0
142
144
  @downloader.download(module_source_url, File.join(mod['destination_path'], filename + '.html'))
145
+ STAT.add(:module)
143
146
  end
144
147
  else
145
148
  LOG.debug "Skipping module import"
@@ -163,7 +166,7 @@ module TerrImporter
163
166
  export_settings.merge!(options)
164
167
  export_settings['appbaseurl'] = "" if for_what == :css
165
168
 
166
- export_path = for_what == :js ? config.js_export_path.clone : config.css_export_path.clone
169
+ export_path = (for_what == :js) ? config.js_export_path.clone : config.css_export_path.clone
167
170
  export_path << '?' << export_settings.map { |k, v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join("&")
168
171
  export_path
169
172
  end
@@ -2,25 +2,22 @@ class Statistic
2
2
  attr_accessor :statistics, :times
3
3
 
4
4
  def initialize
5
- @header = ["-------------------------------",
6
- " SUMMARY ",
7
- "-------------------------------"]
8
-
9
- self.statistics = {
10
- :download => {:count => 0, :message => ""},
11
- :js => {:count => 0, :message => ""},
12
- :css => {:count => 0, :message => ""},
13
- :image => {:count => 0, :message => ""},
14
- :error => {:count => 0, :message => ""}
15
- }
5
+ @header = ["---SUMMARY Date: #{Time.now.strftime("%d.%m.%Y %H:%M:%S")}" ]
6
+ self.statistics = {}
16
7
  end
17
8
 
18
9
  def add_message(type, message)
10
+ init_data(type)
19
11
  self.statistics[type][:message] = message
20
12
  end
21
13
 
22
- def add(type, count)
23
- self.statistics[type][:count] += count
14
+ def add(type)
15
+ init_data(type)
16
+ self.statistics[type][:count] += 1
17
+ end
18
+
19
+ def init_data(type)
20
+ self.statistics[type] = {:count => 0, :message => ""} if self.statistics[type].nil?
24
21
  end
25
22
 
26
23
  def print_summary
@@ -28,7 +25,8 @@ class Statistic
28
25
  puts h
29
26
  end
30
27
  self.statistics.each do |key, value|
31
- puts "#{key.to_s.upcase}: [#{value[:count]}] #{value[:message]}" unless value[:count] == 0
28
+
29
+ puts "* %3s : %s" % [value[:count], value[:message]] unless value[:count] == 0
32
30
  end
33
31
  end
34
32
 
@@ -1,4 +1,4 @@
1
- #Generated by rake task, last bump: minor7patch4major0
1
+ #Generated by rake task, last bump: minor7patch5major0
2
2
  module TerrImporter
3
- VERSION = "0.7.4"
3
+ VERSION = "0.7.5"
4
4
  end
@@ -7,13 +7,13 @@ class StatisticTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  should 'add an entry to the statistic' do
10
- @stat.add(:download, 1)
10
+ @stat.add(:download)
11
11
  assert @stat.statistics[:download][:count] == 1
12
12
  end
13
13
 
14
14
  should 'update an entry in the statistics' do
15
- @stat.add(:download, 1)
16
- @stat.add(:download, 1)
15
+ @stat.add(:download)
16
+ @stat.add(:download)
17
17
  assert @stat.statistics[:download][:count] == 2
18
18
  end
19
19
 
@@ -30,9 +30,9 @@ end
30
30
 
31
31
  should 'output the messages added' do
32
32
  @stat.add_message(:download, "Downloads")
33
- @stat.add(:download, 1)
33
+ @stat.add(:download)
34
34
  @stat.add_message(:css, "CSS")
35
- @stat.add(:css, 1)
35
+ @stat.add(:css)
36
36
 
37
37
  out = capture_stdout do
38
38
  @stat.print_summary
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terrimporter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 4
10
- version: 0.7.4
9
+ - 5
10
+ version: 0.7.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Kummer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-29 00:00:00 Z
18
+ date: 2011-09-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: kwalify