squeezem 0.1.4 → 0.1.5

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.
Files changed (4) hide show
  1. data/README +4 -0
  2. data/bin/squeezem +2 -0
  3. data/lib/squeezem.rb +23 -4
  4. metadata +4 -4
data/README CHANGED
@@ -10,6 +10,10 @@ On Mac:
10
10
 
11
11
  sudo port install pngcrush jpeg
12
12
 
13
+ On Ubuntu:
14
+
15
+ sudo apt-get install pngcrush libjpeg-progs
16
+
13
17
  Install
14
18
 
15
19
  sudo gem install squeezem
data/bin/squeezem CHANGED
@@ -8,6 +8,7 @@ def parse_options
8
8
  options = OpenStruct.new
9
9
  options.squeezem = false
10
10
  options.ignorecache = false
11
+ options.verbose = false
11
12
 
12
13
  opts = OptionParser.new do |opts|
13
14
  opts.banner = <<BANNER
@@ -20,6 +21,7 @@ Options:
20
21
  BANNER
21
22
  opts.on("-s", "--squeezem", "Squeeze files") { options.squeezem = true }
22
23
  opts.on("-i", "--ignore-cache", "Ignore file cache") { options.ignorecache = true }
24
+ opts.on("-v", "--verbose", "Verbose output") { options.verbose = true }
23
25
  opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
24
26
  end
25
27
  begin
data/lib/squeezem.rb CHANGED
@@ -55,19 +55,24 @@ class Squeezem
55
55
  end
56
56
 
57
57
  def squeeze(path)
58
+ log("Considering #{path}")
58
59
  file_type = get_file_type(path)
59
60
  unless valid_file_type?(file_type)
61
+ log("Ignoring, #{file_type} not a valid file type")
60
62
  @files_ignored += 1
61
63
  return
62
64
  end
63
65
  @files_seen += 1
64
66
  @path = path
65
67
  @size = File.size(path)
68
+ log("File size #{@size}")
66
69
  canonical_path = File.expand_path(path)
67
70
  unless @options.ignorecache
68
71
  cache = @files[canonical_path]
72
+ log("Read cache #{cache}")
69
73
  if cache && cache.size == @size
70
74
  unless @options.squeezem && cache.saving > 0
75
+ log("Skipping file, already processed")
71
76
  record_saving(cache.saving)
72
77
  return
73
78
  end
@@ -77,7 +82,7 @@ class Squeezem
77
82
  if File.exist?(@output_path)
78
83
  new_size = File.size(@output_path)
79
84
  if new_size == 0
80
- $stderr.puts "Empty output for #{path}"
85
+ report_error(path, output)
81
86
  return
82
87
  end
83
88
  saving = @size - new_size
@@ -92,10 +97,15 @@ class Squeezem
92
97
  end
93
98
  @files[canonical_path] = OpenStruct.new(:size => cache_size, :saving => cache_saving)
94
99
  else
95
- $stderr.puts "Error processing #{path}:", output
100
+ report_error(path, output)
96
101
  end
97
102
  end
98
103
 
104
+ def report_error(path, output)
105
+ $stderr.print "Error processing #{path}"
106
+ $stderr.puts ": #{output}" if output
107
+ end
108
+
99
109
  def get_file_type(path)
100
110
  extension = File.extname(path).sub('.', '')
101
111
  if extension.empty?
@@ -113,12 +123,17 @@ class Squeezem
113
123
  output = ''
114
124
  case file_type
115
125
  when :png
116
- Open3.popen3('pngcrush', '-quiet', '-rem', 'alla', '-reduce', '-brute', path, @output_path) do |stdin, stdout, stderr|
126
+ cmd = ['pngcrush', '-quiet', '-rem', 'alla', '-reduce', '-brute', path, @output_path]
127
+ log("Calling #{cmd.join(' ')}")
128
+ Open3.popen3(*cmd) do |stdin, stdout, stderr|
117
129
  output = stdout.read
130
+ output += stderr.read
118
131
  end
119
132
  when :jpg
120
133
  File.open(@output_path, "w") do |out|
121
- Open3.popen3('jpegtran', '-copy', 'none', '-optimize', '-perfect', path) do |stdin, stdout, stderr|
134
+ cmd = ['jpegtran', '-copy', 'none', '-optimize', '-perfect', path]
135
+ log("Calling #{cmd.join(' ')}")
136
+ Open3.popen3(*cmd) do |stdin, stdout, stderr|
122
137
  out.write(stdout.read)
123
138
  output = stderr.read
124
139
  end
@@ -172,4 +187,8 @@ class Squeezem
172
187
  f.puts Marshal.dump(@files)
173
188
  end
174
189
  end
190
+
191
+ def log(message)
192
+ puts message if @options.verbose
193
+ end
175
194
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squeezem
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steve Woodcock
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-24 00:00:00 +01:00
18
+ date: 2010-08-29 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21