geoffrey 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ .yardoc
5
+ doc
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geoffrey (0.0.0)
4
+ geoffrey (0.0.2)
5
5
  plist4r
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- awesome_print (0.2.1)
10
+ bluecloth (2.0.7)
11
11
  haml (3.0.17)
12
12
  libxml-ruby (1.1.4)
13
13
  libxml4r (0.2.6)
@@ -20,14 +20,16 @@ GEM
20
20
  libxml4r
21
21
  rake (0.8.7)
22
22
  rspec (1.3.0)
23
+ yard (0.5.8)
23
24
 
24
25
  PLATFORMS
25
26
  ruby
26
27
 
27
28
  DEPENDENCIES
28
- awesome_print
29
+ bluecloth (~> 2.0.7)
29
30
  bundler (~> 1.0.0.rc.5)
30
31
  geoffrey!
31
- mocha (= 0.9.8)
32
+ mocha (~> 0.9.8)
32
33
  plist4r
33
- rspec (= 1.3.0)
34
+ rspec (~> 1.3.0)
35
+ yard (~> 0.5.8)
data/Rakefile CHANGED
@@ -3,5 +3,10 @@ Bundler::GemHelper.install_tasks
3
3
 
4
4
  desc "Execute specs"
5
5
  task :spec do
6
- puts `bundle exec rspec spec`
6
+ puts `bundle exec spec spec`
7
+ end
8
+
9
+ desc "Generate docs"
10
+ task :docs do
11
+ puts `bundle exec yardoc 'lib/**/*.rb'`
7
12
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Albert Llop"]
10
10
  s.email = ["mrsimo@gmail.com"]
11
- s.summary = "Geoffrey is a little helper to aid in the installation of packages and configuration of various Mac OSX applications."
12
- s.description = File.read(File.dirname(__FILE__) + "/README.md")
11
+ s.summary = "Help methods to install packages and configure applications for OSX"
12
+ s.description = "Geoffrey is a little helper to aid in the installation of packages and configuration of various Mac OSX applications."
13
13
 
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "geoffrey"
@@ -17,6 +17,8 @@ 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.5.8"
21
+ s.add_development_dependency "bluecloth", "~> 2.0.7"
20
22
 
21
23
  s.add_dependency 'plist4r'
22
24
 
@@ -5,6 +5,37 @@ module Geoffrey
5
5
 
6
6
  class << self
7
7
 
8
+ # Define a package installation from the URL specified. It will download
9
+ # the file, and if it's compressed, it will decompress it.It currently
10
+ # supports zip and tar.gz files. Once extracted it will look for a .pkg
11
+ # file and try to install it.
12
+ #
13
+ # Some options can be defined:
14
+ #
15
+ # * +:sudo+ if it has to be executed as sudo.
16
+ # * +:unless+ a Proc defining if it doesn't have to try to install it.
17
+ # * +:file+ what file has to be installed from all of the ones that came in
18
+ # the compressed file.
19
+ #
20
+ # If you don't want to install a .pkg but do something else, you can just
21
+ # override the install method. See the examples
22
+ #
23
+ # @example
24
+ # Geoffrey.package do
25
+ # url 'http://www.culater.net/dl/files/SIMBL-0.9.7a.zip'
26
+ # options :sudo => true, :unless => Proc.new{ File.exists?("/Library/LaunchAgents/net.culater.SIMBL.Agent.plist") }
27
+ # end
28
+ #
29
+ # @example
30
+ # Geoffrey.package do
31
+ # url "http://github.com/dabeeeenster/terminaltabswitching/raw/master/TerminalTabSwitching.bundle.zip"
32
+ # options :file => "TerminalTabSwitching.bundle"
33
+ # def install
34
+ # plugins_dir = "#{ENV["HOME"]}/Library/Application Support/SIMBL/Plugins"
35
+ # FileUtils.mkdir_p plugins_dir
36
+ # FileUtils.mv file_to_install, plugins_dir, :force => true
37
+ # end
38
+ # end
8
39
  def package(&block)
9
40
  package = Package.new
10
41
  package.instance_eval &block
@@ -12,6 +43,30 @@ module Geoffrey
12
43
  package.install
13
44
  end
14
45
 
46
+ # Help you configure an application editing its +.plist+ file.
47
+ #
48
+ # You specify the file and then act on it through +options+ as if it were a
49
+ # simple hash.
50
+ #
51
+ # Some OSX applications dump their settings into the plist file when they
52
+ # quit, so you might want to stop them before applying changes. Geoffrey
53
+ # can do it for you with +affects+.
54
+ #
55
+ # @see Geoffrey::Plist::FILES A list of known config files.
56
+ #
57
+ # @example
58
+ # Geoffrey.plist do
59
+ # file :terminal
60
+ # affects "/Applications/Utilities/Terminal.app"
61
+ #
62
+ # options["Default Window Settings"] = "Pro"
63
+ # options["Startup Window Settings"] = "Pro"
64
+ # options["HasMigratedDefaults"] = true
65
+ # options["Window Settings"]["Pro"]["Font"] = "bplist00\xD4\x01\x02\x03\x04\x05\x06\x18\x19X$versionX$objectsY$archiverT$top\x12\x00\x01\x86\xA0\xA4\a\b\x11\x12U$null\xD4\t\n\v\f\r\x0E\x0F\x10V$classVNSNameVNSSizeXNSfFlags\x80\x03\x80\x02\#@,\x00\x00\x00\x00\x00\x00\x10\x10]Menlo-Regular\xD2\x13\x14\x15\x16Z$classnameX$classesVNSFont\xA2\x15\x17XNSObject_\x10\x0FNSKeyedArchiver\xD1\x1A\eTroot\x80\x01\b\x11\x1A#-27<BKRY`ikmvx\x86\x8B\x96\x9F\xA6\xA9\xB2\xC4\xC7\xCC\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x1C\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xCE"
66
+ # options["Window Settings"]["Pro"]["Font"].blob = true
67
+ # options["Window Settings"]["Pro"]["columnCount"] = 520
68
+ # options["Window Settings"]["Pro"]["rowCount"] = 100
69
+ # end
15
70
  def plist(&block)
16
71
  plist = Plist.new
17
72
  plist.instance_eval &block
@@ -4,6 +4,10 @@ require 'open-uri'
4
4
  require 'fileutils'
5
5
 
6
6
  module Geoffrey
7
+
8
+ # This class helps installing packages and other apps into your system.
9
+ #--
10
+ # TODO add support for .dmg files would be great
7
11
  class Package
8
12
  attr_accessor :url, :options, :format, :filename, :dir
9
13
 
@@ -11,6 +15,7 @@ module Geoffrey
11
15
  @options = {}
12
16
  end
13
17
 
18
+ # Accepts anything parseable by URI
14
19
  def url(val = nil)
15
20
  @url = val if val
16
21
  @url
@@ -21,6 +26,12 @@ module Geoffrey
21
26
  @options
22
27
  end
23
28
 
29
+ # Uses the url provided to download the file.
30
+ # Checks the options first to see if it shouldn't be done.
31
+ #--
32
+ # TODO raise some error if the file can't be found or something
33
+ # TODO add some option to define the file name for weird url's
34
+ # TODO ensure you can still download uncompressed files, right?
24
35
  def download_and_decompress
25
36
  return nil if shouldnt_install
26
37
 
@@ -42,6 +53,9 @@ module Geoffrey
42
53
  end
43
54
  end
44
55
 
56
+ # Does the actual installing of the package
57
+ #--
58
+ # TODO add support for .dmg files
45
59
  def install
46
60
  return nil if shouldnt_install
47
61
 
@@ -58,6 +72,8 @@ module Geoffrey
58
72
  @options[:unless] && @options[:unless].respond_to?(:call) && @options[:unless].call
59
73
  end
60
74
 
75
+ # Simple wrapper to execute things, using sudo or not as per defiend in the
76
+ # options. Useful for debugging too :)
61
77
  def execute(command, options = {})
62
78
  options = @options.merge(options)
63
79
  command = "sudo #{command}" if options[:sudo]
@@ -67,6 +83,8 @@ module Geoffrey
67
83
 
68
84
  # If it was specified through options, then get that, otherwise
69
85
  # get the first file with .pkg extension
86
+ #--
87
+ # TODO Also use .dmg when support is added
70
88
  def file_to_install
71
89
  if @options[:file]
72
90
  "#{@dir}/#{@options[:file]}"
@@ -90,6 +108,11 @@ module Geoffrey
90
108
  end
91
109
  end
92
110
 
111
+ # Actual decompressing of the file. Does so into a directory we created in
112
+ # +#{Dir.tmpdir}/#{filename}+
113
+ #--
114
+ # TODO better isolate each download inside the tmpdir?
115
+ # TODO have gzips actually work
93
116
  def decompress(file,target)
94
117
  command = case @format
95
118
  when :zip
@@ -1,6 +1,8 @@
1
1
  require 'plist4r'
2
2
 
3
3
  module Geoffrey
4
+
5
+ # This class helps you configure your Applications
4
6
  class Plist
5
7
 
6
8
  FILES = {
@@ -10,6 +12,8 @@ module Geoffrey
10
12
 
11
13
  attr_accessor :data, :file, :process
12
14
 
15
+ # Set the file you'll edit. if you pass a symbol then it'll use the file
16
+ # defined in the FILES hash.
13
17
  def file(file = nil)
14
18
  if file
15
19
  file = FILES[file] if Symbol === file
@@ -20,6 +24,7 @@ module Geoffrey
20
24
  @file
21
25
  end
22
26
 
27
+ # If a process must be killed before we change settings
23
28
  def affects(value)
24
29
  @process = value
25
30
  end
@@ -36,6 +41,9 @@ module Geoffrey
36
41
  data[key] = value
37
42
  end
38
43
 
44
+ # Saves the changes defined into the file.
45
+ #--
46
+ # TODO don't reopen the process if it wasn't opened to begin with
39
47
  def save
40
48
  kill
41
49
  data.save
@@ -1,3 +1,3 @@
1
1
  module Geoffrey
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Albert Llop
@@ -65,9 +65,39 @@ dependencies:
65
65
  type: :development
66
66
  version_requirements: *id003
67
67
  - !ruby/object:Gem::Dependency
68
- name: plist4r
68
+ name: yard
69
69
  prerelease: false
70
70
  requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ - 5
78
+ - 8
79
+ version: 0.5.8
80
+ type: :development
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: bluecloth
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 2
92
+ - 0
93
+ - 7
94
+ version: 2.0.7
95
+ type: :development
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: plist4r
99
+ prerelease: false
100
+ requirement: &id006 !ruby/object:Gem::Requirement
71
101
  none: false
72
102
  requirements:
73
103
  - - ">="
@@ -76,56 +106,8 @@ dependencies:
76
106
  - 0
77
107
  version: "0"
78
108
  type: :runtime
79
- version_requirements: *id004
80
- description: "geoffrey\n\
81
- ========\n\n\
82
- ## ALERT!\n\n\
83
- This is very early alpha code, use with precaution. It's a spinoff of myself willing to\n\
84
- improve my [dotfiles project](http://github.com/albertllop/dotfiles) a step further. All\n\
85
- code examples in this README come from it.\n\n\
86
- ## Introduction\n\n\
87
- Geoffrey's your little helper, that who just wants to makes your life easier.\n\n\
88
- It aims to help you create little scripts to setup your OSX the way you like.\n\
89
- If, like me, you use different computers at work, home, or even when travelling,\n\
90
- you'll know it's a pain in the ass to keep everything up to date.\n\n\
91
- Inspired in the numerous dotfiles projects, specially\n\
92
- [holman's](http://github.com/holman/dotfiles),\n\
93
- the intention is to bring customization to a bigger extend.\n\n\
94
- ## Installation\n\n $ [sudo] gem install geoffrey\n\n\
95
- Geoffrey's Talents\n\
96
- ==================\n\n\
97
- Geoffrey has many talents, and thus you'll find he can help you in one of these areas:\n\n\
98
- ## Packages\n\n\
99
- If you ever used [Ciar\xC3\xA1n Walsh's](http://ciaranwal.sh) SIMBL plugins, you'll remember\n\
100
- what a pain it is to install them every time. Now you can do so with the next piece of code:\n\n require 'geoffrey'\n Geoffrey.package do\n url 'http://www.culater.net/dl/files/SIMBL-0.9.7a.zip'\n options :sudo => true, :unless => Proc.new{ File.exists?(\"/Library/LaunchAgents/net.culater.SIMBL.Agent.plist\") }\n end\n\n\
101
- Geoffrey will take care of downloading the zip file, and install whatever .pkg\n\
102
- file is in the zip. The possible options are:\n\n\
103
- * `:sudo` => in case it needs to be executed as sudo to install (it does if the installer would ever ask for your password)\n\
104
- * `:unless` => in order to make running this idempotent.\n\
105
- * `:file` => specify which of the files contained in the zip has to be installed. If it's not specified it uses the first .pkg it finds.\n\n\
106
- With that you'll have SIMBL installed and working. Now suppose you want to install a bundle.\n\
107
- You'd have to download a file, and move it to a directory. Geoffrey can help you a little,\n\
108
- basically downloading and uncompressing the zip, and you just have to define the install\n\
109
- method.\n\n require 'geoffrey'\n Geoffrey.package do\n url \"http://github.com/dabeeeenster/terminaltabswitching/raw/master/TerminalTabSwitching.bundle.zip\"\n options :file => \"TerminalTabSwitching.bundle\"\n\n def install\n plugins_dir = \"#{ENV[\"HOME\"]}/Library/Application Support/SIMBL/Plugins\"\n FileUtils.mkdir_p plugins_dir\n FileUtils.mv file_to_install, plugins_dir, :force => true\n end\n\n end\n\n\
110
- `file_to_install` is provided by geoffrey poiting to the automatically downloaded/uncompressed file.\n\n\
111
- ## Application Configuration\n\n\
112
- Everything in OSX seems to work around `.plist` files. This takes a little bit of work to figure out,\n\
113
- but once you do, you can have your favourite apps the way you like. This is my script to get Terminal.app\n\
114
- up and running with Pro scheme, Menlo Font 14pt, and a size 520x100.\n\n require 'geoffrey'\n\n Geoffrey.plist do\n file :terminal\n affects \"/Applications/Utilities/Terminal.app\"\n\n options[\"Default Window Settings\"] = \"Pro\"\n options[\"Startup Window Settings\"] = \"Pro\"\n options[\"HasMigratedDefaults\"] = true\n options[\"Window Settings\"][\"Pro\"][\"Font\"] = \"bplist00\\xD4\\x01\\x02\\x03\\x04\\x05\\x06\\x18\\x19X$versionX$objectsY$archiverT$top\\x12\\x00\\x01\\x86\\xA0\\xA4\\a\\b\\x11\\x12U$null\\xD4\\t\\n\\v\\f\\r\\x0E\\x0F\\x10V$classVNSNameVNSSizeXNSfFlags\\x80\\x03\\x80\\x02\\#@,\\x00\\x00\\x00\\x00\\x00\\x00\\x10\\x10]Menlo-Regular\\xD2\\x13\\x14\\x15\\x16Z$classnameX$classesVNSFont\\xA2\\x15\\x17XNSObject_\\x10\\x0FNSKeyedArchiver\\xD1\\x1A\\eTroot\\x80\\x01\\b\\x11\\x1A#-27<BKRY`ikmvx\\x86\\x8B\\x96\\x9F\\xA6\\xA9\\xB2\\xC4\\xC7\\xCC\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x1C\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xCE\"\n options[\"Window Settings\"][\"Pro\"][\"Font\"].blob = true\n options[\"Window Settings\"][\"Pro\"][\"columnCount\"] = 520\n options[\"Window Settings\"][\"Pro\"][\"rowCount\"] = 100\n end\n\n\
115
- * `file` => Geoffrey knows of a few files in your system you can specify with symbols. If you want to work with a different one, just write the full path.\n\
116
- * `affects` => When you close Terminal.app, it'll dump its otions into the plist. So you have to stop it, change the plist file, then reopen it. Geoffrey does this automatically if you tell him what must be rebooted.\n\
117
- * `options` => Its the plist has per se. Using the fantastic [plist4r](http://github.com/dreamcat4/plist4r) gem, you can modify it.\n\n\
118
- You might have seen something peculiar:\n\n options[\"Window Settings\"][\"Pro\"][\"Font\"].blob = true\n\n\
119
- Some values in plist files are of type \"Data\", which is just binary stuff. Plist4r handles\n\
120
- these as strings with a special flag.\n\n\
121
- The best way to know what to put in every value, is to just go to the file and take a\n\
122
- look. They all tend to make sense. For data values, however, you might have more work. The\n\
123
- way I do it is opening the file with Plist4r, and reading the value:\n\n require 'plist4r'\n plist = Plist4r.open(\"the/file.plist\")\n plist[\"whatever\"][\"option\"] # => copy whatever it returns\n\n\
124
- Just make sure that when you set it in your geoffrey you put the flag blog true. Otherwise you might see some really weird system errors.\n\n\
125
- ## A few words\n\n\
126
- 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,\n\
127
- but I'm so lazy that I've needed a lot of time to do just this. \n\n\
128
- Thanks!\n"
109
+ version_requirements: *id006
110
+ description: Geoffrey is a little helper to aid in the installation of packages and configuration of various Mac OSX applications.
129
111
  email:
130
112
  - mrsimo@gmail.com
131
113
  executables: []
@@ -144,7 +126,6 @@ files:
144
126
  - lib/geoffrey.rb
145
127
  - lib/geoffrey/package.rb
146
128
  - lib/geoffrey/plist.rb
147
- - lib/geoffrey/template.rb
148
129
  - lib/geoffrey/version.rb
149
130
  - spec/package_spec.rb
150
131
  - spec/plist_spec.rb
@@ -188,6 +169,6 @@ rubyforge_project: geoffrey
188
169
  rubygems_version: 1.3.7
189
170
  signing_key:
190
171
  specification_version: 3
191
- summary: Geoffrey is a little helper to aid in the installation of packages and configuration of various Mac OSX applications.
172
+ summary: Help methods to install packages and configure applications for OSX
192
173
  test_files: []
193
174
 
@@ -1,30 +0,0 @@
1
- module Geoffrey
2
- class Template
3
-
4
- attr_accessor :title, :description
5
-
6
- def self.inherited(subclass)
7
- @@subclasses ||= []
8
- @@subclasses << subclass
9
- end
10
-
11
- class << self
12
- def self.attr_rw(*attrs)
13
- attrs.each do |attr|
14
- class_eval %Q{
15
- def #{attr}(val=nil)
16
- val.nil? ? @#{attr} : @#{attr} = val
17
- end
18
- }
19
- end
20
- end
21
-
22
- attr_rw :title, :description
23
-
24
- def all
25
- @@subclasses
26
- end
27
-
28
- end
29
- end
30
- end