geoffrey 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geoffrey (0.0.2)
4
+ geoffrey (0.0.4)
5
5
  plist4r
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -7,6 +7,10 @@ This is very early alpha code, use with precaution. It's a spinoff of myself wil
7
7
  improve my [dotfiles project](http://github.com/albertllop/dotfiles) a step further. All
8
8
  code examples in this README come from it.
9
9
 
10
+ ## Links
11
+
12
+ * [Documentation](http://rdoc.info/projects/albertllop/geoffrey) (this README is better viewed there ;)
13
+
10
14
  ## Introduction
11
15
 
12
16
  Geoffrey's your little helper, that who just wants to makes your life easier.
@@ -39,7 +43,7 @@ what a pain it is to install them every time. Now you can do so with the next pi
39
43
  options :sudo => true, :unless => Proc.new{ File.exists?("/Library/LaunchAgents/net.culater.SIMBL.Agent.plist") }
40
44
  end
41
45
 
42
- Check the [documentation](http://rdoc.info/albertllop/geoffrey) for more detailed documentation.
46
+ See {Geoffrey::package} for extended documentation.
43
47
 
44
48
  ## Application Configuration
45
49
 
@@ -62,7 +66,7 @@ up and running with Pro scheme, Menlo Font 14pt, and a size 520x100.
62
66
  options["Window Settings"]["Pro"]["rowCount"] = 100
63
67
  end
64
68
 
65
- Check the [documentation](http://rdoc.info/albertllop/geoffrey) for more detailed documentation.
69
+ See {Geoffrey::plist} for extended documentation.
66
70
 
67
71
  ## A few words
68
72
 
data/lib/geoffrey.rb CHANGED
@@ -7,7 +7,7 @@ module Geoffrey
7
7
 
8
8
  # Define a package installation from the URL specified. It will download
9
9
  # the file, and if it's compressed, it will decompress it.It currently
10
- # supports zip, tar.gz and .gz files. Once extracted it will look for a .pkg
10
+ # supports zip, tar.gz, .gz and .dmg files. Once extracted it will look for a .pkg
11
11
  # file and try to install it.
12
12
  #
13
13
  # Some options can be defined:
@@ -31,7 +31,6 @@ module Geoffrey
31
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
- # TODO ensure you can still download uncompressed files, right?
35
34
  def download_and_decompress
36
35
  return nil if shouldnt_install
37
36
 
@@ -55,7 +54,7 @@ module Geoffrey
55
54
 
56
55
  # Does the actual installing of the package
57
56
  #--
58
- # TODO add support for .dmg files
57
+ # TODO add support for .app files
59
58
  def install
60
59
  return nil if shouldnt_install
61
60
 
@@ -69,7 +68,7 @@ module Geoffrey
69
68
  # If it was specified through options, then get that, otherwise
70
69
  # get the first file with .pkg extension
71
70
  #--
72
- # TODO Also use .dmg when support is added
71
+ # TODO Also use .app when support is added
73
72
  def file_to_install
74
73
  return @file_to_install if defined?(@file_to_install)
75
74
  @file_to_install = if @options[:file]
@@ -98,7 +97,7 @@ module Geoffrey
98
97
  options = @options.merge(options)
99
98
  command = "sudo #{command}" if options[:sudo]
100
99
  puts "Executing: #{command}" if $verbose
101
- system command
100
+ `#{command}`
102
101
  end
103
102
 
104
103
  def get_format
@@ -108,6 +107,7 @@ module Geoffrey
108
107
  when '.tgz' then :tgz
109
108
  when '.gz'
110
109
  @filename =~ /\.tar\.gz/ ? :tgz : :gz
110
+ when '.dmg' then :dmg
111
111
  else
112
112
  :unknown
113
113
  end
@@ -117,7 +117,6 @@ module Geoffrey
117
117
  # +#{Dir.tmpdir}/#{filename}+
118
118
  #--
119
119
  # TODO better isolate each download inside the tmpdir?
120
- # TODO have gzips actually work
121
120
  def decompress(file,target)
122
121
  command = case @format
123
122
  when :zip
@@ -130,8 +129,25 @@ module Geoffrey
130
129
  "cp #{file.path} #{target}/#{filename}.gz; gunzip #{target}/*"
131
130
  when :unknown
132
131
  "cp #{file.path} #{target}/#{filename}"
132
+ when :dmg
133
+ extract_from_dmg(file,target)
134
+ nil
135
+ end
136
+ execute command, :sudo => false if command
137
+ end
138
+
139
+
140
+ def extract_from_dmg(file,target)
141
+ execute("mv #{file.path} #{target}.dmg")
142
+ str = execute("hdiutil attach #{target}.dmg")
143
+ unless $?.exitstatus > 0
144
+ info = str.split("\t")
145
+ dmg_dir = info.last.chomp
146
+ device = info.first.strip.split("/").last
147
+ execute("cp -r #{dmg_dir}/** #{target}")
148
+ execute("hdiutil detach #{device}")
149
+ execute("rm -f #{target}.dmg")
133
150
  end
134
- execute command, :sudo => false
135
151
  end
136
152
 
137
153
  end
@@ -1,3 +1,3 @@
1
1
  module Geoffrey
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/package_spec.rb CHANGED
@@ -17,9 +17,14 @@ describe Geoffrey::Package do
17
17
 
18
18
  context "package installation" do
19
19
 
20
+ # No idea how to test this
20
21
  it "installs basic package stuff" do
21
22
  end
22
23
 
24
+ # No idea how to test this either
25
+ it "installs .app stuff" do
26
+ end
27
+
23
28
  it "doesnt install the thing if a :unless option is provided" do
24
29
  package = Geoffrey::Package.new
25
30
  package.url("whatever")
@@ -69,5 +74,13 @@ describe Geoffrey::Package do
69
74
  package.download_and_decompress
70
75
  File.read(package.file_to_install).chomp.should == "foo"
71
76
  end
77
+
78
+ it "also supports .dmg files" do
79
+ package = Geoffrey::Package.new
80
+ package.url(File.dirname(__FILE__) + "/static/test.dmg")
81
+ package.download_and_decompress
82
+ File.read(package.file_to_install).chomp.should == "foo"
83
+ end
84
+
72
85
  end
73
86
  end
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Albert Llop
@@ -131,6 +131,7 @@ files:
131
131
  - spec/plist_spec.rb
132
132
  - spec/spec_helper.rb
133
133
  - spec/static/example.plist
134
+ - spec/static/test.dmg
134
135
  - spec/static/test.tar.gz
135
136
  - spec/static/test.tgz
136
137
  - spec/static/test.txt