xpcomcore-rubygem 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,14 +3,31 @@ require 'rake'
3
3
 
4
4
  begin
5
5
  require 'jeweler'
6
+ require 'colored'
7
+
6
8
  Jeweler::Tasks.new do |gem|
7
9
  gem.name = "xpcomcore-rubygem"
10
+ gem.executables = %w[xpcomcore-rubygem-install xpcomcore-firefox]
8
11
  gem.summary = %Q{Gem to allow for using XPCOMCore via RubyGems}
9
12
  gem.description = %Q{Gem to allow for using XPCOMCore via RubyGems}
10
- gem.email = "gabriel.gironda@centro.net"
13
+ gem.email = "gabriel.gironda@gmail.com"
11
14
  gem.homepage = "http://github.com/gabrielg/xpcomcore-rubygem"
12
15
  gem.authors = ["ggironda"]
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+
17
+ gem.post_install_message = <<-EOF;
18
+
19
+ #{"".ljust(80).red_on_blue.bold}
20
+ #{"PAY HEED TO THIS ANNOYING MESSAGE".center(80).red_on_blue.bold}
21
+ #{"".ljust(80).red_on_blue.bold}
22
+
23
+ The XPCOMCore gem has been installed but you still need to complete installation
24
+ by hand. Run the command #{'xpcomcore-rubygem-install'.underline.bold} without options to get
25
+ usage information on using it to install the bootstrapper code for this gem.
26
+
27
+ EOF
28
+
29
+ gem.add_dependency "sys-uname"
30
+ gem.add_development_dependency "colored"
14
31
  end
15
32
  Jeweler::GemcutterTasks.new
16
33
  rescue LoadError
@@ -54,3 +71,4 @@ Rake::RDocTask.new do |rdoc|
54
71
  rdoc.rdoc_files.include('README*')
55
72
  rdoc.rdoc_files.include('lib/**/*.rb')
56
73
  end
74
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'sys/uname'
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'sys/uname'
4
+ require 'pathname'
5
+ require 'optparse'
6
+ require 'rexml/document'
7
+ require 'fileutils'
8
+
9
+ class XPCOMCoreRubyGemInstaller
10
+ attr_accessor :no_dry_run, :install_global, :install_local, :fix_path
11
+
12
+ KnownAppIds = {'Firefox' => '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'}
13
+ KnownVendors = %w[Mozilla]
14
+ ScriptName = Pathname(__FILE__).basename
15
+ SysName = Sys::Uname.sysname.downcase.to_sym
16
+ InstallPathBuilders = {:linux => {}, :darwin => {}}
17
+ GeckoCommands = %w[firefox-bin firefox xulrunner-bin]
18
+ ProfilePath = Pathname("~/.profile").expand_path
19
+
20
+ # Linux install path builders
21
+ InstallPathBuilders[:linux][:global] = [
22
+ lambda {|vendor,app,extension| Pathname("/usr/lib") + vendor + "extensions" + app + extension },
23
+ lambda {|vendor,app,extension| Pathname("/usr/lib64") + vendor + "extensions" + app + extension },
24
+ lambda {|vendor,app,extension| Pathname("/usr/share") + vendor + "extensions" + app + extension }
25
+ ]
26
+ InstallPathBuilders[:linux][:local] = [
27
+ lambda {|vendor,app,extension| Pathname("~/.#{vendor}") + "extensions" + app + extension }
28
+ ]
29
+
30
+ # Mac OS X install path builders
31
+ InstallPathBuilders[:darwin][:global] = [
32
+ lambda {|vendor,app,extension| Pathname("/Library/Application Support") + vendor + "Extensions" + app + extension }
33
+ ]
34
+ InstallPathBuilders[:darwin][:local] = [
35
+ lambda {|vendor,app,extension| Pathname("~/Library/Application Support") + vendor + "Extensions" + app + extension }
36
+ ]
37
+
38
+ GeckoLocations = {:linux => [], :darwin => []}
39
+ GeckoLocations[:darwin] << Pathname("/Applications/Firefox.app/Contents/MacOS/firefox-bin")
40
+ GeckoLocations[:darwin] << Pathname("/Library/Frameworks/XUL.framework/xulrunner-bin")
41
+
42
+ def initialize(args, options = {})
43
+ @args = args
44
+ @options = options
45
+ @option_parser = OptionParser.new do |opts|
46
+ opts.banner = "Usage: #{ScriptName} [options]"
47
+ opts.on("--install-global", "Install the XPCOMCore gem bootstrap code globally.", method(:install_global=))
48
+ opts.on("--install-local", "Install the XPCOMCore gem bootstrap code for the current user only.", method(:install_local=))
49
+ opts.on("--fix-path", "Checks the path for an executable Gecko installation and fixes it if necessary.", method(:fix_path=))
50
+ opts.on("--do-it", "By default, we do a dry run and show the user what would happen. This forces the actual install.", method(:no_dry_run=))
51
+ end
52
+ end
53
+
54
+ def dry_run?
55
+ !no_dry_run
56
+ end
57
+
58
+ def go!
59
+ @option_parser.parse(@args)
60
+ install_opts = {:install_global => install_global, :install_local => install_local}
61
+ if !install_opts.values.any?
62
+ puts @option_parser
63
+ exit(1)
64
+ end
65
+ read_install_manifest
66
+ install_opts.each do |opt_name,value|
67
+ send(:"do_#{opt_name}") if value
68
+ log("All done!.")
69
+ end
70
+ rescue OptionParser::InvalidOption => e
71
+ invalid_option(e)
72
+ end
73
+
74
+ private
75
+
76
+ def invalid_option(exception)
77
+ puts exception.message
78
+ puts @option_parser
79
+ exit(1)
80
+ end
81
+
82
+ def do_install_global
83
+ do_install(:global) && rewrite_path
84
+ end
85
+
86
+ def do_install_local
87
+ do_install(:local) && rewrite_path
88
+ end
89
+
90
+ def do_install(scope)
91
+ each_vendor_and_app_name_and_app_id do |vendor, app_name, app_id|
92
+ if install_extension(scope, vendor, app_id)
93
+ next(true)
94
+ else
95
+ log("No app install location for application '#{app_name}' by vendor '#{vendor}' exists. Skipping.")
96
+ next(false)
97
+ end
98
+ end.any?
99
+ end
100
+
101
+ def each_vendor_and_app_name_and_app_id
102
+ KnownVendors.each do |vendor_name|
103
+ KnownAppIds.each do |app_name, app_id|
104
+ yield(vendor_name, app_name, app_id)
105
+ end
106
+ end
107
+ end
108
+
109
+ def install_extension(scope, vendor, app_id)
110
+ raise "Couldn't read extension id from install manifest" if extension_id.empty?
111
+ InstallPathBuilders[SysName][scope].select do |path_builder|
112
+ log("Performing a #{scope} install...")
113
+ install_path = path_builder[vendor, app_id, extension_id].expand_path
114
+ if !install_path.parent.exist?
115
+ log("Directory '#{install_path.parent}' doesn't exist - skipping installation to this location.")
116
+ next(false)
117
+ else
118
+ copy_extension_to(install_path)
119
+ next(true)
120
+ end
121
+ end.any?
122
+ end
123
+
124
+ def read_install_manifest
125
+ manifest_contents = (@options[:extension_path] + "install.rdf").read
126
+ @install_manifest = REXML::Document.new(manifest_contents)
127
+ end
128
+
129
+ def extension_path
130
+ @options[:extension_path]
131
+ end
132
+
133
+ def extension_id
134
+ @extension_id ||= @install_manifest.root.elements["Description/em:id"].text
135
+ end
136
+
137
+ def copy_extension_to(install_path)
138
+ if install_path.parent.writable?
139
+ log("Copying '#{extension_path}' to '#{install_path}'")
140
+ copy_dir(extension_path, install_path)
141
+ else
142
+ log("Path '#{install_path}' isn't writable. Maybe you need to run this as root and try again if installing globally?")
143
+ end
144
+ end
145
+
146
+ def log(str)
147
+ puts("#{dry_run? ? "[DRY RUN]" : "[INSTALLER]"} #{str}")
148
+ end
149
+
150
+ def copy_dir(src_path, install_path)
151
+ return false if dry_run?
152
+ FileUtils.cp_r(src_path.expand_path.to_s + "/.", install_path.to_s)
153
+ end
154
+
155
+ def rewrite_path
156
+ return false unless fix_path
157
+ gecko_available = check_path
158
+ rewrite_profile unless gecko_available
159
+ end
160
+
161
+ def check_path
162
+ GeckoCommands.collect do |cmd|
163
+ `#{cmd} -v 2>/dev/null`
164
+ $? == 0
165
+ end.any?
166
+ end
167
+
168
+ def rewrite_profile
169
+ log("I couldn't find any of '#{GeckoCommands.join(", ")}'. Doing my best attempt to rectify this.")
170
+ send(:"rewrite_profile_for_#{SysName}")
171
+ end
172
+
173
+ def rewrite_profile_for_linux
174
+ log("Sorry. You're on your own here. Check your distribution's documentation for details - for example, Firefox may be installed under a different name.")
175
+ end
176
+
177
+ def rewrite_profile_for_darwin
178
+ loc = GeckoLocations[:darwin].detect {|p| p.exist?}
179
+ unless loc
180
+ log("I can't find Firefox installed on your system. Sorry.")
181
+ exit(1)
182
+ end
183
+ log("Awesome. I found a Gecko installation at '#{loc}'. Rewriting your .profile to include this in the $PATH.")
184
+ rewrite_path_with_location(loc.parent)
185
+ end
186
+
187
+ def rewrite_path_with_location(path_entry)
188
+ profile_entry = %Q[PATH="#{path_entry}:$PATH"]
189
+ log("Adding .profile entry: #{profile_entry}")
190
+ if dry_run?
191
+ log("Not adding an entry due to running in dry run mode.")
192
+ else
193
+ ProfilePath.open("a") do |io|
194
+ io << "\n"
195
+ io.puts("# This and the following lines automatically added by xpcomcore-rubygem on #{Time.now}.")
196
+ io.puts(profile_entry)
197
+ end
198
+ log(".profile entry added. You may need to source your .profile again or log in and out for it to take effect.")
199
+ end
200
+ end
201
+
202
+ end
203
+
204
+ installer = XPCOMCoreRubyGemInstaller.new(ARGV, :extension_path => (Pathname(__FILE__).parent.parent + "extension").expand_path)
205
+ installer.go!
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0"?>
2
+
3
+ <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
4
+ <Description about="urn:mozilla:install-manifest">
5
+ <em:id>xpcomcorebootstrapper@conflagrationjs.org</em:id>
6
+ <em:version>0.1.0</em:version>
7
+ <em:type>2</em:type>
8
+ <em:targetApplication>
9
+ <Description>
10
+ <em:id>toolkit@mozilla.org</em:id>
11
+ <em:minVersion>1.9.0</em:minVersion>
12
+ </Description>
13
+ </em:targetApplication>
14
+ <em:name>XPCOMCore Bootstrapper Extension</em:name>
15
+ </Description>
16
+ </RDF>
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{xpcomcore-rubygem}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["ggironda"]
12
+ s.date = %q{2009-10-07}
13
+ s.description = %q{Gem to allow for using XPCOMCore via RubyGems}
14
+ s.email = %q{gabriel.gironda@gmail.com}
15
+ s.executables = ["xpcomcore-rubygem-install", "xpcomcore-firefox"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bin/xpcomcore-firefox",
28
+ "bin/xpcomcore-rubygem-install",
29
+ "extension/install.rdf",
30
+ "lib/xpcomcore-rubygem.rb",
31
+ "test/test_helper.rb",
32
+ "test/xpcomcore-rubygem_test.rb",
33
+ "xpcomcore-rubygem.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/gabrielg/xpcomcore-rubygem}
36
+ s.post_install_message = %q{
37
+  
38
+  PAY HEED TO THIS ANNOYING MESSAGE 
39
+  
40
+
41
+ The XPCOMCore gem has been installed but you still need to complete installation
42
+ by hand. Run the command xpcomcore-rubygem-install without options to get
43
+ usage information on using it to install the bootstrapper code for this gem.
44
+
45
+ }
46
+ s.rdoc_options = ["--charset=UTF-8"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = %q{1.3.5}
49
+ s.summary = %q{Gem to allow for using XPCOMCore via RubyGems}
50
+ s.test_files = [
51
+ "test/test_helper.rb",
52
+ "test/xpcomcore-rubygem_test.rb"
53
+ ]
54
+
55
+ if s.respond_to? :specification_version then
56
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
57
+ s.specification_version = 3
58
+
59
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
60
+ s.add_runtime_dependency(%q<sys-uname>, [">= 0"])
61
+ s.add_development_dependency(%q<colored>, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<sys-uname>, [">= 0"])
64
+ s.add_dependency(%q<colored>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<sys-uname>, [">= 0"])
68
+ s.add_dependency(%q<colored>, [">= 0"])
69
+ end
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xpcomcore-rubygem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ggironda
@@ -9,14 +9,34 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-06 00:00:00 -05:00
12
+ date: 2009-10-07 00:00:00 -05:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sys-uname
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: colored
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
16
35
  description: Gem to allow for using XPCOMCore via RubyGems
17
- email: gabriel.gironda@centro.net
18
- executables: []
19
-
36
+ email: gabriel.gironda@gmail.com
37
+ executables:
38
+ - xpcomcore-rubygem-install
39
+ - xpcomcore-firefox
20
40
  extensions: []
21
41
 
22
42
  extra_rdoc_files:
@@ -29,14 +49,24 @@ files:
29
49
  - README.rdoc
30
50
  - Rakefile
31
51
  - VERSION
52
+ - bin/xpcomcore-firefox
53
+ - bin/xpcomcore-rubygem-install
54
+ - extension/install.rdf
32
55
  - lib/xpcomcore-rubygem.rb
33
56
  - test/test_helper.rb
34
57
  - test/xpcomcore-rubygem_test.rb
58
+ - xpcomcore-rubygem.gemspec
35
59
  has_rdoc: true
36
60
  homepage: http://github.com/gabrielg/xpcomcore-rubygem
37
61
  licenses: []
38
62
 
39
- post_install_message:
63
+ post_install_message: "\n\
64
+ \e[1m\e[31m\e[44m \e[0m\e[0m\n\
65
+ \e[1m\e[31m\e[44m PAY HEED TO THIS ANNOYING MESSAGE \e[0m\e[0m\n\
66
+ \e[1m\e[31m\e[44m \e[0m\e[0m\n\n\
67
+ The XPCOMCore gem has been installed but you still need to complete installation\n\
68
+ by hand. Run the command \e[1m\e[4mxpcomcore-rubygem-install\e[0m\e[0m without options to get\n\
69
+ usage information on using it to install the bootstrapper code for this gem.\n\n"
40
70
  rdoc_options:
41
71
  - --charset=UTF-8
42
72
  require_paths: