launchy 0.4.0 → 2.0.0

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.
Files changed (45) hide show
  1. data/.autotest +28 -0
  2. data/HISTORY +15 -0
  3. data/LICENSE +1 -1
  4. data/NOTES +1 -0
  5. data/README +6 -6
  6. data/Rakefile +47 -51
  7. data/bin/launchy +2 -10
  8. data/lib/launchy.rb +96 -30
  9. data/lib/launchy/application.rb +55 -152
  10. data/lib/launchy/applications/browser.rb +68 -0
  11. data/lib/launchy/cli.rb +70 -0
  12. data/lib/launchy/descendant_tracker.rb +49 -0
  13. data/lib/launchy/detect.rb +10 -0
  14. data/lib/launchy/detect/host_os.rb +31 -0
  15. data/lib/launchy/detect/host_os_family.rb +71 -0
  16. data/lib/launchy/detect/nix_desktop_environment.rb +60 -0
  17. data/lib/launchy/detect/ruby_engine.rb +78 -0
  18. data/lib/launchy/detect/runner.rb +96 -0
  19. data/lib/launchy/error.rb +4 -0
  20. data/lib/launchy/os_family.rb +8 -0
  21. data/lib/launchy/version.rb +8 -7
  22. data/spec/application_spec.rb +26 -47
  23. data/spec/detect/host_os_family_spec.rb +40 -0
  24. data/spec/detect/host_os_spec.rb +19 -0
  25. data/spec/detect/nix_desktop_environment_spec.rb +13 -0
  26. data/spec/detect/ruby_engine_spec.rb +37 -0
  27. data/spec/launchy_spec.rb +29 -5
  28. data/spec/mock_scheme.rb +5 -0
  29. data/spec/spec_helper.rb +3 -3
  30. data/spec/{tattle-host-os.yml → tattle-host-os.yaml} +0 -0
  31. data/spec/version_spec.rb +4 -5
  32. metadata +67 -78
  33. data/gemspec.rb +0 -46
  34. data/lib/launchy/browser.rb +0 -98
  35. data/lib/launchy/command_line.rb +0 -48
  36. data/lib/launchy/paths.rb +0 -53
  37. data/spec/browser_spec.rb +0 -62
  38. data/spec/paths_spec.rb +0 -15
  39. data/tasks/announce.rake +0 -39
  40. data/tasks/config.rb +0 -107
  41. data/tasks/distribution.rake +0 -46
  42. data/tasks/documentation.rake +0 -32
  43. data/tasks/rspec.rake +0 -25
  44. data/tasks/rubyforge.rake +0 -52
  45. data/tasks/utils.rb +0 -80
data/gemspec.rb DELETED
@@ -1,46 +0,0 @@
1
- require 'rubygems'
2
- require 'launchy/version'
3
- require 'tasks/config'
4
-
5
- Launchy::GEM_SPEC = Gem::Specification.new do |spec|
6
- proj = Configuration.for('project')
7
- spec.name = proj.name
8
- spec.version = Launchy::VERSION
9
-
10
- spec.author = proj.author
11
- spec.email = proj.email
12
- spec.homepage = proj.homepage
13
- spec.summary = proj.summary
14
- spec.description = proj.description
15
- spec.platform = Gem::Platform::RUBY
16
-
17
-
18
- pkg = Configuration.for('packaging')
19
- spec.files = pkg.files.all
20
- spec.executables = pkg.files.bin.collect { |b| File.basename(b) }
21
-
22
- # add dependencies here
23
- spec.add_dependency("rake", ">= 0.8.1")
24
- spec.add_dependency("configuration", ">= 0.0.5")
25
-
26
- spec.add_development_dependency("rake", "~> 0.8.7")
27
- spec.add_development_dependency("configuration", "~> 1.2.0")
28
- spec.add_development_dependency("rspec-core", "~> 2.5.1")
29
-
30
-
31
- if rdoc = Configuration.for_if_exist?('rdoc') then
32
- spec.has_rdoc = true
33
- spec.extra_rdoc_files = pkg.files.rdoc
34
- spec.rdoc_options = rdoc.options + [ "--main" , rdoc.main_page ]
35
- else
36
- spec.has_rdoc = false
37
- end
38
-
39
- if test = Configuration.for_if_exist?('testing') then
40
- spec.test_files = test.files
41
- end
42
-
43
- if rf = Configuration.for_if_exist?('rubyforge') then
44
- spec.rubyforge_project = rf.project
45
- end
46
- end
@@ -1,98 +0,0 @@
1
- require 'launchy/application'
2
- require 'uri'
3
-
4
- module Launchy
5
- class Browser < Application
6
-
7
-
8
- class << self
9
- def desktop_environment_browser_launchers
10
- @desktop_environment_browser_launchers ||= {
11
- :kde => "kfmclient",
12
- :gnome => "gnome-open",
13
- :xfce => "exo-open",
14
- :generic => "htmlview"
15
- }
16
- end
17
- def fallback_browsers
18
- @fallback_browsers ||= %w[ firefox seamonkey opera mozilla netscape galeon ]
19
- end
20
- def run(*args)
21
- Browser.new.visit(args[0])
22
- end
23
-
24
- # return true if this class can handle the given parameter(s)
25
- def handle?(*args)
26
- begin
27
- Launchy.log "#{self.name} : testing if [#{args[0]}] (#{args[0].class}) is a url."
28
- uri = URI.parse(args[0])
29
- result = %w[http https ftp file].include?(uri.scheme)
30
- rescue Exception => e
31
- # hmm... why does rcov not see that this is executed ?
32
- Launchy.log "#{self.name} : not a url, #{e}"
33
- return false
34
- end
35
- end
36
- end
37
-
38
- def initialize
39
- @browser = nil
40
- @nix_app_list = []
41
- raise "Unable to find browser to launch for os family '#{my_os_family}'." unless browser
42
- end
43
-
44
- def desktop_environment_browser_launchers
45
- self.class.desktop_environment_browser_launchers
46
- end
47
-
48
- def fallback_browsers
49
- self.class.fallback_browsers
50
- end
51
-
52
- # Find a list of potential browser applications to run on *nix machines.
53
- # The order is:
54
- # 1) What is in ENV['LAUNCHY_BROWSER'] or ENV['BROWSER']
55
- # 2) xdg-open
56
- # 3) desktop environment launcher program
57
- # 4) a list of fallback browsers
58
- def nix_app_list
59
- if @nix_app_list.empty?
60
- browser_cmds = ['xdg-open']
61
- browser_cmds << desktop_environment_browser_launchers[nix_desktop_environment]
62
- browser_cmds << fallback_browsers
63
- browser_cmds.flatten!
64
- browser_cmds.delete_if { |b| b.nil? || (b.strip.size == 0) }
65
- Launchy.log "#{self.class.name} : Initial *Nix Browser List: #{browser_cmds.join(', ')}"
66
- @nix_app_list = browser_cmds.collect { |bin| find_executable(bin) }.find_all { |x| not x.nil? }
67
- Launchy.log "#{self.class.name} : Filtered *Nix Browser List: #{@nix_app_list.join(', ')}"
68
- end
69
- @nix_app_list
70
- end
71
-
72
- # return the full command line path to the browser or nil
73
- def browser
74
- if not @browser then
75
- if ENV['LAUNCHY_BROWSER'] and File.exists?(ENV['LAUNCHY_BROWSER']) then
76
- Launchy.log "#{self.class.name} : Using LAUNCHY_BROWSER environment variable : #{ENV['LAUNCHY_BROWSER']}"
77
- @browser = ENV['LAUNCHY_BROWSER']
78
- elsif ENV['BROWSER'] and File.exists?(ENV['BROWSER']) then
79
- Launchy.log "#{self.class.name} : Using BROWSER environment variable : #{ENV['BROWSER']}"
80
- @browser = ENV['BROWSER']
81
- elsif app_list.size > 0 then
82
- @browser = app_list.first
83
- Launchy.log "#{self.class.name} : Using application list : #{@browser}"
84
- else
85
- msg = "Unable to launch. No Browser application found."
86
- Launchy.log "#{self.class.name} : #{msg}"
87
- $stderr.puts msg
88
- end
89
- end
90
- return @browser
91
- end
92
-
93
- # launch the browser at the appointed url
94
- def visit(url)
95
- run(browser,url)
96
- end
97
- end
98
- end
@@ -1,48 +0,0 @@
1
- require 'optparse'
2
-
3
- module Launchy
4
- class CommandLine
5
-
6
- def parser
7
- @parser ||= OptionParser.new do |op|
8
- op.banner = "Usage: launchy [options] url"
9
- op.separator ""
10
- op.on("-d", "--debug", "Force debug, output lots of information.",
11
- "This sets the LAUNCHY_DEBUG environment variable to 'true'.") do |d|
12
- ENV["LAUNCHY_DEBUG"] = 'true'
13
- end
14
-
15
- op.on("-h", "--help", "Print this message") do |h|
16
- puts op.to_s
17
- exit 0
18
- end
19
-
20
- op.on("-v", "--version", "Output the version of Launchy") do |v|
21
- puts "Launchy version #{Launchy::VERSION}"
22
- exit 0
23
- end
24
-
25
- op.on("-o", "--host-os HOST_OS","Force the behavior of a particular host os.",
26
- "This sets the LAUNCHY_HOST_OS environment variable.") do |os|
27
- ENV["LAUNCHY_HOST_OS"] = os
28
- end
29
-
30
- op.on("-b", "--browser BROWSER", "Force launchy to use a particular browser.",
31
- "This sets the LAUNCHY_BROWSER environment variable.") do |browser|
32
- ENV["LAUNCHY_BROWSER"] = browser
33
- end
34
- end
35
- end
36
-
37
- def run(argv = ARGV)
38
- begin
39
- parser.parse!(argv)
40
- Launchy.open(*argv)
41
- rescue ::OptionParser::ParseError => pe
42
- $stderr.puts "#{parser.programn_name}: #{pe}"
43
- $stderr.puts "Try `#{parser.program_name} --help' for more information."
44
- exit 1
45
- end
46
- end
47
- end
48
- end
@@ -1,53 +0,0 @@
1
- #--
2
- # Copyright (c) 2007 Jeremy Hinegardner
3
- # All rights reserved. See LICENSE and/or COPYING for details.
4
- #++
5
- #
6
- module Launchy
7
- #
8
- # Access to various paths inside the project programatically
9
- #
10
- module Paths
11
- #
12
- # :call-seq:
13
- # Launchy::Paths.root_dir -> String
14
- #
15
- # Returns The full expanded path of the parent directory of +lib+
16
- # going up the path from the current file. A trailing File::SEPARATOR⋅
17
- # is guaranteed
18
- #
19
- def self.root_dir
20
- @root_dir ||=(
21
- path_parts = ::File.expand_path( __FILE__ ).split( ::File::SEPARATOR )
22
- lib_index = path_parts.rindex( "lib" )
23
- @root_dir = path_parts[0...lib_index].join( ::File::SEPARATOR ) + ::File::SEPARATOR
24
- )
25
- end
26
-
27
- #
28
- # :call-seq:
29
- # Launchy::Paths.lib_path( *args ) -> String
30
- #
31
- # Returns The full expanded path of the +lib+ directory below
32
- # _root_dir_. All parameters passed in are joined onto the⋅
33
- # result. A trailing File::SEPARATOR is guaranteed if⋅
34
- # _args_ are *not* present.
35
- #
36
- def self.lib_path( *args )
37
- self.sub_path( "lib", *args )
38
- end
39
-
40
- #
41
- # :call-seq:
42
- # Launchy::Paths.sub_path( sub, *args ) -> String
43
- #
44
- # Returns the full expanded path of the +sub+ directory below _root_dir. All
45
- # _arg_ parameters passed in are joined onto the result. A trailing
46
- # File::SEPARATOR is guaranteed if _args_ are *not* present.
47
- #
48
- def self.sub_path( sub, *args )
49
- sp = ::File.join( root_dir, sub ) + File::SEPARATOR
50
- sp = ::File.join( sp, *args ) if args
51
- end
52
- end
53
- end
@@ -1,62 +0,0 @@
1
- require File.join(File.dirname(__FILE__),"spec_helper.rb")
2
- require 'stringio'
3
- describe Launchy::Browser do
4
- it "should find a path to a executable" do
5
- begin
6
- File.executable?(Launchy::Browser.new.browser).should == true
7
- rescue => e
8
- e.message.should == "Unable to find browser to launch for os family 'nix'."
9
- end
10
- end
11
-
12
- it "should handle an http url" do
13
- Launchy::Browser.handle?("http://www.example.com").should == true
14
- end
15
-
16
- it "should handle an https url" do
17
- Launchy::Browser.handle?("https://www.example.com").should == true
18
- end
19
-
20
- it "should handle an ftp url" do
21
- Launchy::Browser.handle?("ftp://download.example.com").should == true
22
- end
23
-
24
- it "should handle an file url" do
25
- Launchy::Browser.handle?("file:///home/user/index.html").should == true
26
- end
27
-
28
- it "should not handle a mailto url" do
29
- Launchy::Browser.handle?("mailto:jeremy@example.com").should == false
30
- end
31
-
32
- it "creates a default unix application list" do
33
- begin
34
- Launchy::Browser.new.nix_app_list.class.should == Array
35
- rescue => e
36
- e.message.should == "Unable to find browser to launch for os family 'nix'."
37
- end
38
- end
39
-
40
- { "BROWSER" => "/bin/sh",
41
- "LAUNCHY_BROWSER" => "/bin/sh"}.each_pair do |e,v|
42
- it "can use environmental variable overrides of #{e} for the browser" do
43
- ENV[e] = v
44
- Launchy::Browser.new.browser.should eql(v)
45
- ENV[e] = nil
46
- end
47
- end
48
-
49
- it "reports when it cannot find an browser" do
50
- old_error = $stderr
51
- $stderr = StringIO.new
52
- ENV["LAUNCHY_HOST_OS"] = "testing"
53
- begin
54
- browser = Launchy::Browser.new
55
- rescue => e
56
- e.message.should =~ /Unable to find browser to launch for os family/m
57
- end
58
- ENV["LAUNCHY_HOST_OS"] = nil
59
- $stderr.string.should =~ /Unable to launch. No Browser application found./m
60
- $stderr = old_error
61
- end
62
- end
@@ -1,15 +0,0 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'launchy/paths'
4
-
5
- describe Launchy::Paths do
6
- it "can access the root dir of the project" do
7
- Launchy::Paths.root_dir.should == File.expand_path( File.join( File.dirname( __FILE__ ), ".." ) ) + ::File::SEPARATOR
8
- end
9
-
10
- %w[ lib ].each do |sub|
11
- it "can access the #{sub} path of the project" do
12
- Launchy::Paths.send("#{sub}_path" ).should == File.expand_path( File.join( File.dirname( __FILE__ ), "..", sub ) ) + ::File::SEPARATOR
13
- end
14
- end
15
- end
@@ -1,39 +0,0 @@
1
- require 'tasks/config'
2
- #-------------------------------------------------------------------------------
3
- # announcement methods
4
- #-------------------------------------------------------------------------------
5
-
6
- proj_config = Configuration.for('project')
7
- namespace :announce do
8
- desc "create email for ruby-talk"
9
- task :email do
10
- info = Utils.announcement
11
-
12
- File.open("email.txt", "w") do |mail|
13
- mail.puts "From: #{proj_config.author} <#{proj_config.email}>"
14
- mail.puts "To: ruby-talk@ruby-lang.org"
15
- mail.puts "Date: #{Time.now.rfc2822}"
16
- mail.puts "Subject: [ANN] #{info[:subject]}"
17
- mail.puts
18
- mail.puts info[:title]
19
- mail.puts
20
- mail.puts " gem install #{Launchy::GEM_SPEC.name}"
21
- mail.puts
22
- mail.puts info[:urls]
23
- mail.puts
24
- mail.puts info[:description]
25
- mail.puts
26
- mail.puts "{{ Release notes for Version #{Launchy::VERSION} }}"
27
- mail.puts
28
- mail.puts info[:release_notes]
29
- mail.puts
30
- end
31
- puts "Created the following as email.txt:"
32
- puts "-" * 72
33
- puts File.read("email.txt")
34
- puts "-" * 72
35
- end
36
-
37
- CLOBBER << "email.txt"
38
- end
39
-
@@ -1,107 +0,0 @@
1
- require 'configuration'
2
-
3
- require 'rake'
4
- require 'tasks/utils'
5
-
6
- #-----------------------------------------------------------------------
7
- # General project configuration
8
- #-----------------------------------------------------------------------
9
- Configuration.for('project') {
10
- name "launchy"
11
- version Launchy::Version.to_s
12
- author "Jeremy Hinegardner"
13
- email "jeremy at copiousfreetime dot org"
14
- homepage "http://copiousfreetime.rubyforge.org/launchy/"
15
- description Utils.section_of("README", "description")
16
- summary description.split(".").first
17
- history "HISTORY"
18
- license FileList["LICENSE"]
19
- readme "README"
20
- }
21
-
22
- #-----------------------------------------------------------------------
23
- # Packaging
24
- #-----------------------------------------------------------------------
25
- Configuration.for('packaging') {
26
- # files in the project
27
- proj_conf = Configuration.for('project')
28
- files {
29
- bin FileList["bin/*"]
30
- ext FileList["ext/*.{c,h,rb}"]
31
- examples FileList["examples/*.rb"]
32
- lib FileList["lib/**/*.rb"]
33
- test FileList["spec/**/*.rb", "test/**/*.rb"]
34
- data FileList["data/**/*", "spec/**/*.yml"]
35
- tasks FileList["tasks/**/*.r{ake,b}"]
36
- rdoc FileList[proj_conf.readme, proj_conf.history,
37
- proj_conf.license] + lib + FileList["ext/*.c"]
38
- all bin + examples + ext + lib + test + data + rdoc + tasks + FileList["Rakefile"]
39
- }
40
-
41
- # ways to package the results
42
- formats {
43
- tgz true
44
- zip true
45
- rubygem Configuration::Table.has_key?('gem')
46
- }
47
- }
48
-
49
- #-----------------------------------------------------------------------
50
- # Gem packaging
51
- #-----------------------------------------------------------------------
52
- Configuration.for("gem") {
53
- spec "gemspec.rb"
54
- Configuration.for('packaging').files.all << spec
55
- }
56
-
57
- #-----------------------------------------------------------------------
58
- # Testing
59
- # - change mode to 'testunit' to use unit testing
60
- #-----------------------------------------------------------------------
61
- Configuration.for('test') {
62
- mode "spec"
63
- files Configuration.for("packaging").files.test
64
- options %w[ --format documentation --color ]
65
- ruby_opts %w[ ]
66
- }
67
-
68
- #-----------------------------------------------------------------------
69
- # Rcov
70
- #-----------------------------------------------------------------------
71
- Configuration.for('rcov') {
72
- output_dir "coverage"
73
- libs %w[ lib ]
74
- rcov_opts %w[ --html -o coverage ]
75
- ruby_opts %w[ ]
76
- test_files Configuration.for('packaging').files.test
77
- }
78
-
79
- #-----------------------------------------------------------------------
80
- # Rdoc
81
- #-----------------------------------------------------------------------
82
- Configuration.for('rdoc') {
83
- files Configuration.for('packaging').files.rdoc
84
- main_page files.first
85
- title Configuration.for('project').name
86
- options %w[ --line-numbers --inline-source ]#-f darkfish ]
87
- output_dir "doc"
88
- }
89
-
90
- #-----------------------------------------------------------------------
91
- # Extension
92
- #-----------------------------------------------------------------------
93
- Configuration.for('extension') {
94
- configs Configuration.for('packaging').files.ext.find_all { |x| %w[ mkrf_conf.rb extconf.rb ].include?(File.basename(x)) }
95
- }
96
-
97
- #-----------------------------------------------------------------------
98
- # Rubyforge
99
- #-----------------------------------------------------------------------
100
- Configuration.for('rubyforge') {
101
- project "copiousfreetime"
102
- user "jjh"
103
- host "rubyforge.org"
104
- rdoc_location "#{user}@#{host}:/var/www/gforge-projects/#{project}/launchy"
105
- }
106
-
107
-