rarity 0.1.0 → 0.1.1
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/README.md +10 -0
- data/lib/rarity/optimiser.rb +7 -7
- data/lib/rarity/runner.rb +2 -0
- data/lib/rarity/tracker.rb +9 -4
- data/lib/rarity/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -14,6 +14,12 @@ Rarity makes use of:
|
|
14
14
|
|
15
15
|
You will need to install these prior to running rarity.
|
16
16
|
|
17
|
+
Additionally, the sqlite3 gem is used for the tracking database. This has the following package dependencies on Ubuntu:
|
18
|
+
|
19
|
+
* libsqlite3-dev
|
20
|
+
|
21
|
+
Gem dependencies are installed automatically when installing rarity.
|
22
|
+
|
17
23
|
## Installation
|
18
24
|
|
19
25
|
Add this line to your application's Gemfile:
|
@@ -49,3 +55,7 @@ You can find more help with:
|
|
49
55
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
50
56
|
4. Push to the branch (`git push origin my-new-feature`)
|
51
57
|
5. Create new Pull Request
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
See the LICENSE file. Long story short, MIT, go crazy.
|
data/lib/rarity/optimiser.rb
CHANGED
@@ -21,7 +21,7 @@ class Rarity::Optimiser
|
|
21
21
|
if ext == ".png"
|
22
22
|
`#{png_cmd} "#{path}"`
|
23
23
|
type = :png
|
24
|
-
@tracker.mark_done(path, @options)
|
24
|
+
@tracker.mark_done(path, @options, {:before=>start_size, :after=>File.size(path), :filetype=>type, :time=>(Time.now-start)})
|
25
25
|
elsif ext == ".gif"
|
26
26
|
type = :gif
|
27
27
|
# ooh, okay, so if we're a gif, are we animated?
|
@@ -32,7 +32,7 @@ class Rarity::Optimiser
|
|
32
32
|
if (fc.split(":")[1].to_i rescue 1) > 0
|
33
33
|
# We have more than one frame! We're animated or strange. gifsicle.
|
34
34
|
`#{gif_cmd} "#{path}"`
|
35
|
-
@tracker.mark_done(path, @options)
|
35
|
+
@tracker.mark_done(path, @options, {:before=>start_size, :after=>File.size(path), :filetype=>type, :time=>(Time.now-start)})
|
36
36
|
else
|
37
37
|
# We're single frame, PNG probably does better
|
38
38
|
opo = `#{png_cmd} "#{path}"`
|
@@ -42,12 +42,12 @@ class Rarity::Optimiser
|
|
42
42
|
File.delete(path)
|
43
43
|
# Changed format, so update path
|
44
44
|
path = pngpath
|
45
|
-
@tracker.mark_done(path, @options)
|
45
|
+
@tracker.mark_done(path, @options, {:before=>start_size, :after=>File.size(path), :filetype=>type, :time=>(Time.now-start)})
|
46
46
|
else
|
47
47
|
# Clean up the PNG we tried and gifsicle it.
|
48
48
|
File.delete(path.gsub(File.extname(path),".png"))
|
49
49
|
`#{gif_cmd} "#{path}"`
|
50
|
-
@tracker.mark_done(path, @options)
|
50
|
+
@tracker.mark_done(path, @options, {:before=>start_size, :after=>File.size(path), :filetype=>type, :time=>(Time.now-start)})
|
51
51
|
end
|
52
52
|
end
|
53
53
|
else
|
@@ -59,18 +59,18 @@ class Rarity::Optimiser
|
|
59
59
|
File.delete(path)
|
60
60
|
# Changed format, so update path
|
61
61
|
path = pngpath
|
62
|
-
@tracker.mark_done(path, @options)
|
62
|
+
@tracker.mark_done(path, @options, {:before=>start_size, :after=>File.size(path), :filetype=>type, :time=>(Time.now-start)})
|
63
63
|
else
|
64
64
|
# Clean up the PNG we tried and gifsicle it.
|
65
65
|
File.delete(path.gsub(File.extname(path),".png"))
|
66
66
|
`#{gif_cmd} "#{path}"`
|
67
|
-
@tracker.mark_done(path, @options)
|
67
|
+
@tracker.mark_done(path, @options, {:before=>start_size, :after=>File.size(path), :filetype=>type, :time=>(Time.now-start)})
|
68
68
|
end
|
69
69
|
end
|
70
70
|
elsif ext == ".jpg" or ext == ".jpeg"
|
71
71
|
type = :jpg
|
72
72
|
`#{jpg_cmd} "#{path}"`
|
73
|
-
@tracker.mark_done(path, @options)
|
73
|
+
@tracker.mark_done(path, @options, {:before=>start_size, :after=>File.size(path), :filetype=>type, :time=>(Time.now-start)})
|
74
74
|
else
|
75
75
|
puts "Skipped file, not a recognised file type"
|
76
76
|
end
|
data/lib/rarity/runner.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
class Rarity::Runner
|
2
|
+
# Initialises a new runner
|
2
3
|
def initialize(options)
|
3
4
|
@directory = options[:directory]
|
4
5
|
@tracker = Rarity::Tracker.new
|
5
6
|
@optimiser = Rarity::Optimiser.new(@tracker, {:png_o_level => options[:pnglevel]})
|
6
7
|
end
|
8
|
+
# Runs optimisations recursively.
|
7
9
|
def run
|
8
10
|
recursively_optimise(@directory)
|
9
11
|
end
|
data/lib/rarity/tracker.rb
CHANGED
@@ -2,7 +2,7 @@ require 'sequel'
|
|
2
2
|
class Rarity::Tracker
|
3
3
|
|
4
4
|
def initialize
|
5
|
-
@db_path = File.expand_path("~/.
|
5
|
+
@db_path = File.expand_path("~/.rarity.sqlite")
|
6
6
|
@first_run = !File.exists?(@db_path)
|
7
7
|
@db = Sequel.sqlite(@db_path)
|
8
8
|
if @first_run
|
@@ -10,8 +10,13 @@ class Rarity::Tracker
|
|
10
10
|
primary_key :id
|
11
11
|
String :path
|
12
12
|
Integer :png_o_level
|
13
|
+
Integer :before_bytes
|
14
|
+
Integer :after_bytes
|
15
|
+
String :filetype
|
16
|
+
Float :time_taken
|
13
17
|
end
|
14
18
|
end
|
19
|
+
puts "Tracker initialised with a total of #{@db[:images].count} records"
|
15
20
|
end
|
16
21
|
def import_from_old_format
|
17
22
|
@path = File.expand_path("~/.optimdone.dat")
|
@@ -22,13 +27,13 @@ class Rarity::Tracker
|
|
22
27
|
end
|
23
28
|
puts "Imported #{@done.size} entries that we have already optimised from the old land, you can now delete ~/.optimdone.dat"
|
24
29
|
end
|
25
|
-
def mark_done(path, options)
|
30
|
+
def mark_done(path, options, results)
|
26
31
|
cleanpath = path.gsub("\n","").gsub("\r","").chomp
|
27
32
|
if !is_done?(path, options)
|
28
33
|
if @db[:images][:path=>cleanpath]
|
29
|
-
@db[:images][:path=>cleanpath] = {:png_o_level => options[:png_o_level]}
|
34
|
+
@db[:images][:path=>cleanpath] = {:png_o_level => options[:png_o_level], :after_bytes=>results[:after], :time_taken=>(results[:time]+ @db[:images][:path=>cleanpath].time_taken)}
|
30
35
|
else
|
31
|
-
@db[:images].insert(:path=>cleanpath, :png_o_level=>options[:png_o_level])
|
36
|
+
@db[:images].insert(:path=>cleanpath, :png_o_level=>options[:png_o_level], :before_bytes=>results[:before], :after_bytes=>results[:after], :filetype=>results[:filetype].to_s, :time_taken=>results[:time])
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
data/lib/rarity/version.rb
CHANGED