geoffrey 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +5 -5
- data/README.md +4 -4
- data/geoffrey.gemspec +1 -1
- data/lib/geoffrey/package.rb +28 -18
- data/lib/geoffrey/version.rb +1 -1
- data/spec/package_spec.rb +21 -0
- data/spec/static/test.error.dmg +1 -0
- data/spec/static/test.error.gz +1 -0
- data/spec/static/test.error.tar.gz +1 -0
- data/spec/static/test.error.zip +1 -0
- metadata +19 -6
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
geoffrey (0.0.
|
4
|
+
geoffrey (0.0.5)
|
5
5
|
plist4r
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
bluecloth (2.0.7)
|
11
|
-
haml (3.0.
|
11
|
+
haml (3.0.18)
|
12
12
|
libxml-ruby (1.1.4)
|
13
13
|
libxml4r (0.2.6)
|
14
14
|
libxml-ruby (>= 1.1.3)
|
15
15
|
mocha (0.9.8)
|
16
16
|
rake
|
17
|
-
plist4r (1.1.
|
17
|
+
plist4r (1.1.5)
|
18
18
|
haml
|
19
19
|
libxml-ruby
|
20
20
|
libxml4r
|
21
21
|
rake (0.8.7)
|
22
22
|
rspec (1.3.0)
|
23
|
-
yard (0.
|
23
|
+
yard (0.6.0)
|
24
24
|
|
25
25
|
PLATFORMS
|
26
26
|
ruby
|
@@ -32,4 +32,4 @@ DEPENDENCIES
|
|
32
32
|
mocha (~> 0.9.8)
|
33
33
|
plist4r
|
34
34
|
rspec (~> 1.3.0)
|
35
|
-
yard (~> 0.
|
35
|
+
yard (~> 0.6.0)
|
data/README.md
CHANGED
@@ -4,12 +4,12 @@ geoffrey
|
|
4
4
|
## ALERT!
|
5
5
|
|
6
6
|
This is very early alpha code, use with precaution. It's a spinoff of myself willing to
|
7
|
-
improve my [dotfiles project](http://github.com/
|
7
|
+
improve my [dotfiles project](http://github.com/mrsimo/dotfiles) a step further. All
|
8
8
|
code examples in this README come from it.
|
9
9
|
|
10
10
|
## Links
|
11
11
|
|
12
|
-
* [Documentation](http://
|
12
|
+
* [Documentation](http://rubydoc.info/gems/geoffrey/frames) (this README is better viewed there ;)
|
13
13
|
|
14
14
|
## Introduction
|
15
15
|
|
@@ -60,7 +60,7 @@ up and running with Pro scheme, Menlo Font 14pt, and a size 520x100.
|
|
60
60
|
options["Default Window Settings"] = "Pro"
|
61
61
|
options["Startup Window Settings"] = "Pro"
|
62
62
|
options["HasMigratedDefaults"] = true
|
63
|
-
options["Window Settings"]["Pro"]["Font"] = "bplist00\xD4\x01\x02\x03\x04\x05\x06\x18\x19X$
|
63
|
+
options["Window Settings"]["Pro"]["Font"] = "bplist00\xD4\x01\x02\x03\x04\x05\x06\x18\x19X$version(..)"
|
64
64
|
options["Window Settings"]["Pro"]["Font"].blob = true
|
65
65
|
options["Window Settings"]["Pro"]["columnCount"] = 520
|
66
66
|
options["Window Settings"]["Pro"]["rowCount"] = 100
|
@@ -71,6 +71,6 @@ See {Geoffrey::plist} for extended documentation.
|
|
71
71
|
## A few words
|
72
72
|
|
73
73
|
This is work done in my free hours, it's not yet finished. The code is dirty and mainly undocumented. It all started on #whyday,
|
74
|
-
but I'm so lazy that I've needed a lot of time to do just this.
|
74
|
+
but I'm so lazy that I've needed a lot of time to do just this.
|
75
75
|
|
76
76
|
Thanks!
|
data/geoffrey.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_development_dependency "bundler", "~> 1.0.0.rc.5"
|
18
18
|
s.add_development_dependency "rspec", "~> 1.3.0"
|
19
19
|
s.add_development_dependency "mocha", "~> 0.9.8"
|
20
|
-
s.add_development_dependency "yard", "~> 0.
|
20
|
+
s.add_development_dependency "yard", "~> 0.6.0"
|
21
21
|
s.add_development_dependency "bluecloth", "~> 2.0.7"
|
22
22
|
|
23
23
|
s.add_dependency 'plist4r'
|
data/lib/geoffrey/package.rb
CHANGED
@@ -5,9 +5,10 @@ require 'fileutils'
|
|
5
5
|
|
6
6
|
module Geoffrey
|
7
7
|
|
8
|
+
class NotFoundError < Exception; end
|
9
|
+
class DecompressionError < Exception; end
|
10
|
+
|
8
11
|
# This class helps installing packages and other apps into your system.
|
9
|
-
#--
|
10
|
-
# TODO add support for .dmg files would be great
|
11
12
|
class Package
|
12
13
|
attr_accessor :url, :options, :format, :filename, :dir, :file
|
13
14
|
|
@@ -29,30 +30,35 @@ module Geoffrey
|
|
29
30
|
# Uses the url provided to download the file.
|
30
31
|
# Checks the options first to see if it shouldn't be done.
|
31
32
|
#--
|
32
|
-
# TODO raise some error if the file can't be found or something
|
33
33
|
# TODO add some option to define the file name for weird url's
|
34
34
|
def download_and_decompress
|
35
35
|
return unless should_install
|
36
36
|
|
37
|
-
|
38
|
-
unless @url.nil?
|
39
|
-
get_format
|
40
|
-
|
37
|
+
begin
|
41
38
|
@file = Tempfile.new("geoffrey")
|
42
39
|
@file.write open(@url).read
|
43
40
|
@file.close
|
44
41
|
|
42
|
+
@filename = @url.split("/").last
|
43
|
+
get_format
|
44
|
+
|
45
|
+
|
45
46
|
@dir = "#{Dir.tmpdir}/#{filename}"
|
46
47
|
FileUtils.rm_rf dir if File.exist?(dir)
|
47
48
|
FileUtils.mkdir_p dir
|
48
|
-
|
49
|
-
|
49
|
+
rescue
|
50
|
+
raise NotFoundError
|
50
51
|
end
|
52
|
+
|
53
|
+
decompress
|
51
54
|
end
|
52
55
|
|
53
56
|
# Does the actual installing of the package
|
57
|
+
# For .pkg files it executes installer.
|
58
|
+
# For .app files it just moves it to /Applications
|
54
59
|
#--
|
55
|
-
# TODO add
|
60
|
+
# TODO maybe add more customization options
|
61
|
+
# TODO investigate other possible extensions.
|
56
62
|
def install
|
57
63
|
return unless should_install
|
58
64
|
|
@@ -66,8 +72,6 @@ module Geoffrey
|
|
66
72
|
|
67
73
|
# If it was specified through options, then get that, otherwise
|
68
74
|
# get the first file with .pkg extension
|
69
|
-
#--
|
70
|
-
# TODO Also use .app when support is added
|
71
75
|
def file_to_install
|
72
76
|
return @file_to_install if defined?(@file_to_install)
|
73
77
|
@file_to_install = if @options[:file]
|
@@ -98,7 +102,7 @@ module Geoffrey
|
|
98
102
|
if String === command
|
99
103
|
opts = @options.merge(opts)
|
100
104
|
command = "sudo #{command}" if opts[:sudo]
|
101
|
-
|
105
|
+
command = "#{command} > /dev/null 2>&1" unless opts[:verbose]
|
102
106
|
`#{command}`
|
103
107
|
end
|
104
108
|
end
|
@@ -117,11 +121,15 @@ module Geoffrey
|
|
117
121
|
# Actual decompressing of the file. Does so into a directory we created in
|
118
122
|
# +#{Dir.tmpdir}/#{filename}+
|
119
123
|
#--
|
120
|
-
# TODO
|
124
|
+
# TODO control errors. Maybe it's .zip but just doesn't work.
|
125
|
+
# TODO better isolate each download inside the tmpdir? When debugging it's
|
126
|
+
# misleading to have a folder with the file name and extension.
|
127
|
+
# * Timestamp if clash?
|
128
|
+
# * Random string?
|
121
129
|
def decompress
|
122
130
|
command = case format
|
123
131
|
when :zip
|
124
|
-
execute "unzip -o #{file.path} -d #{dir}
|
132
|
+
execute "unzip -o #{file.path} -d #{dir}", :sudo => false
|
125
133
|
when :tar
|
126
134
|
execute "tar xf #{file.path} -C #{dir}", :sudo => false
|
127
135
|
when :tgz
|
@@ -133,14 +141,16 @@ module Geoffrey
|
|
133
141
|
when :dmg
|
134
142
|
extract_from_dmg
|
135
143
|
end
|
136
|
-
end
|
137
144
|
|
145
|
+
# Might be that the decompression failed
|
146
|
+
raise DecompressionError unless $?.success?
|
147
|
+
end
|
138
148
|
|
139
149
|
# Mount the dmg file, copy contents to tmpdir, unmount, remove dmg
|
140
150
|
def extract_from_dmg
|
141
151
|
execute("mv #{file.path} #{dir}.dmg")
|
142
|
-
str = execute("hdiutil attach #{dir}.dmg")
|
143
|
-
|
152
|
+
str = execute("hdiutil attach #{dir}.dmg 2> /dev/null", :verbose => true)
|
153
|
+
if $?.success?
|
144
154
|
info = str.split("\t")
|
145
155
|
dmg_dir = info.last.chomp
|
146
156
|
device = info.first.strip.split("/").last
|
data/lib/geoffrey/version.rb
CHANGED
data/spec/package_spec.rb
CHANGED
@@ -18,10 +18,17 @@ describe Geoffrey::Package do
|
|
18
18
|
context "package installation" do
|
19
19
|
|
20
20
|
# No idea how to test this
|
21
|
+
# TODO find a way
|
22
|
+
# Ideas:
|
23
|
+
# * Just suppose that the instruction is executed
|
21
24
|
it "installs basic package stuff" do
|
22
25
|
end
|
23
26
|
|
24
27
|
# No idea how to test this either
|
28
|
+
# TODO find a way
|
29
|
+
# Ideas:
|
30
|
+
# * Have an "install directory" which is different in test environment
|
31
|
+
# * Then check that files are inside and with proper permissions
|
25
32
|
it "installs .app stuff" do
|
26
33
|
end
|
27
34
|
|
@@ -47,6 +54,20 @@ describe Geoffrey::Package do
|
|
47
54
|
# method should return where it is.
|
48
55
|
context 'package downloading/uncompressing' do
|
49
56
|
|
57
|
+
it "raises an error if the file can't be found/read" do
|
58
|
+
package = Geoffrey::Package.new
|
59
|
+
package.url 'really/impossible/to/exist.dmg'
|
60
|
+
lambda { package.download_and_decompress}.should raise_exception(Geoffrey::NotFoundError)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "raises an error if the file has bad format" do
|
64
|
+
["zip","tar.gz","gz","dmg"].each do |extension|
|
65
|
+
package = Geoffrey::Package.new
|
66
|
+
package.url(File.dirname(__FILE__) + "/static/test.error.#{extension}")
|
67
|
+
lambda { package.download_and_decompress }.should raise_exception(Geoffrey::DecompressionError)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
50
71
|
it "doesn't do anything if it's an unknown format" do
|
51
72
|
package = Geoffrey::Package.new
|
52
73
|
package.url(File.dirname(__FILE__) + "/static/test.txt")
|
@@ -0,0 +1 @@
|
|
1
|
+
foo
|
@@ -0,0 +1 @@
|
|
1
|
+
foo
|
@@ -0,0 +1 @@
|
|
1
|
+
foo
|
@@ -0,0 +1 @@
|
|
1
|
+
foo
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoffrey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Albert Llop
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-31 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 15424063
|
28
30
|
segments:
|
29
31
|
- 1
|
30
32
|
- 0
|
@@ -42,6 +44,7 @@ dependencies:
|
|
42
44
|
requirements:
|
43
45
|
- - ~>
|
44
46
|
- !ruby/object:Gem::Version
|
47
|
+
hash: 27
|
45
48
|
segments:
|
46
49
|
- 1
|
47
50
|
- 3
|
@@ -57,6 +60,7 @@ dependencies:
|
|
57
60
|
requirements:
|
58
61
|
- - ~>
|
59
62
|
- !ruby/object:Gem::Version
|
63
|
+
hash: 43
|
60
64
|
segments:
|
61
65
|
- 0
|
62
66
|
- 9
|
@@ -72,11 +76,12 @@ dependencies:
|
|
72
76
|
requirements:
|
73
77
|
- - ~>
|
74
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 7
|
75
80
|
segments:
|
76
81
|
- 0
|
77
|
-
-
|
78
|
-
-
|
79
|
-
version: 0.
|
82
|
+
- 6
|
83
|
+
- 0
|
84
|
+
version: 0.6.0
|
80
85
|
type: :development
|
81
86
|
version_requirements: *id004
|
82
87
|
- !ruby/object:Gem::Dependency
|
@@ -87,6 +92,7 @@ dependencies:
|
|
87
92
|
requirements:
|
88
93
|
- - ~>
|
89
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 1
|
90
96
|
segments:
|
91
97
|
- 2
|
92
98
|
- 0
|
@@ -102,6 +108,7 @@ dependencies:
|
|
102
108
|
requirements:
|
103
109
|
- - ">="
|
104
110
|
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
105
112
|
segments:
|
106
113
|
- 0
|
107
114
|
version: "0"
|
@@ -133,6 +140,10 @@ files:
|
|
133
140
|
- spec/spec_helper.rb
|
134
141
|
- spec/static/example.plist
|
135
142
|
- spec/static/test.dmg
|
143
|
+
- spec/static/test.error.dmg
|
144
|
+
- spec/static/test.error.gz
|
145
|
+
- spec/static/test.error.tar.gz
|
146
|
+
- spec/static/test.error.zip
|
136
147
|
- spec/static/test.tar.gz
|
137
148
|
- spec/static/test.tgz
|
138
149
|
- spec/static/test.txt
|
@@ -152,6 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
163
|
requirements:
|
153
164
|
- - ">="
|
154
165
|
- !ruby/object:Gem::Version
|
166
|
+
hash: 3
|
155
167
|
segments:
|
156
168
|
- 0
|
157
169
|
version: "0"
|
@@ -160,6 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
172
|
requirements:
|
161
173
|
- - ">="
|
162
174
|
- !ruby/object:Gem::Version
|
175
|
+
hash: 23
|
163
176
|
segments:
|
164
177
|
- 1
|
165
178
|
- 3
|