Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
20070731062252-42483-5ffb336e60ae6736f34198877e790ca7d3f1aed7.gz
  • Loading branch information
copiousfreetime authored and git-darcs-import committed Jun 22, 2008
1 parent 1cc24fc commit 0ac2432
Show file tree
Hide file tree
Showing 26 changed files with 768 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .boring
@@ -0,0 +1,44 @@
# Boring file regexps:
\.hi$
\.o$
\.o\.cmd$
# *.ko files aren't boring by default because they might
# be Korean translations rather than kernel modules.
# \.ko$
\.ko\.cmd$
\.mod\.c$
(^|/)\.tmp_versions($|/)
(^|/)CVS($|/)
(^|/)RCS($|/)
~$
#(^|/)\.[^/]
(^|/)_darcs($|/)
\.bak$
\.BAK$
\.orig$
(^|/)vssver\.scc$
\.swp$
(^|/)MT($|/)
(^|/)\{arch\}($|/)
(^|/).arch-ids($|/)
(^|/),
\.class$
\.prof$
(^|/)\.DS_Store$
(^|/)BitKeeper($|/)
(^|/)ChangeSet($|/)
(^|/)\.svn($|/)
\.py[co]$
\#
\.cvsignore$
(^|/)Thumbs\.db$
(^|/)autom4te\.cache($|/)

# project specific items
^doc\/*
^pkg/*
^log/*
\.swo$
\.swp$
email.txt

4 changes: 4 additions & 0 deletions CHANGES
@@ -0,0 +1,4 @@
= launchy Changelog
=== Version 0.0.1

* Initial public release
31 changes: 31 additions & 0 deletions LICENSE
@@ -0,0 +1,31 @@
Copyright (c) 2007, Jeremy Hinegardner

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.

* Neither the name of Jeremy Hinegardner nor the
names of its contributors may be used to endorse or promote
products derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 changes: 15 additions & 0 deletions README
@@ -0,0 +1,15 @@
== launchy

* Homepage
* rubyforge project
* email

== DESCRIPTION

== FEATURES

== SYNOPSIS

== CREDITS

== LICENSE
65 changes: 65 additions & 0 deletions Rakefile
@@ -0,0 +1,65 @@
require 'rubygems'
require 'rake/gempackagetask'
require 'rake/clean'
require 'rake/rdoctask'

$: << File.join(File.dirname(__FILE__),"lib")
require 'launchy'

# load all the extra tasks for the project
TASK_DIR = File.join(File.dirname(__FILE__),"tasks")
FileList[File.join(TASK_DIR,"*.rb")].each do |tasklib|
require "tasks/#{File.basename(tasklib)}"
end

task :default => "test:default"

#-----------------------------------------------------------------------
# Documentation
#-----------------------------------------------------------------------
namespace :doc do

# generating documentation locally
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = Launchy::SPEC.local_rdoc_dir
rdoc.options = Launchy::SPEC.rdoc_options
rdoc.rdoc_files = Launchy::SPEC.rdoc_files
end

desc "View the RDoc documentation locally"
task :view => :rdoc do
show_files Launchy::SPEC.local_rdoc_dir
end

end

#-----------------------------------------------------------------------
# Packaging and Distribution
#-----------------------------------------------------------------------
namespace :dist do

Rake::GemPackageTask.new(Launchy::SPEC) do |pkg|
pkg.need_tar = Launchy::SPEC.need_tar
pkg.need_zip = Launchy::SPEC.need_zip
end

desc "Install as a gem"
task :install => [:clobber, :package] do
sh "sudo gem install pkg/#{Launchy::SPEC.full_name}.gem"
end

# uninstall the gem and all executables
desc "Uninstall gem"
task :uninstall do
sh "sudo gem uninstall #{Launchy::SPEC.name} -x"
end

desc "dump gemspec"
task :gemspec do
puts Launchy::SPEC.to_ruby
end

desc "reinstall gem"
task :reinstall => [:install, :uninstall]

end
Empty file added bin/.git-darcs-dir
Empty file.
12 changes: 12 additions & 0 deletions bin/launchy
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby

begin
require 'launchy'
rescue LoadError
path = File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
raise if $:.include? path
$: << path
retry
end

Launchy.do_magic(*ARGV)
Empty file added lib/.git-darcs-dir
Empty file.
31 changes: 31 additions & 0 deletions lib/launchy.rb
@@ -0,0 +1,31 @@
module Launchy

ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__),".."))
LIB_DIR = File.join(ROOT_DIR,"lib").freeze
RESOURCE_DIR = File.join(ROOT_DIR,"resources").freeze

#
# Utility method to require all files ending in .rb in the directory
# with the same name as this file minus .rb
#
def require_all_libs_relative_to(fname)
prepend = File.basename(fname,".rb")
search_me = File.join(File.dirname(fname),prepend)

Dir.entries(search_me).each do |rb|
if File.extname(rb) == ".rb" then
require "#{prepend}/#{File.basename(rb,".rb")}"
end
end
end
module_function :require_all_libs_relative_to

class << self
def do_magic(*params)
klass = Launchy::Spawnable::Application.find_application_class_for(*params)
klass.run(*params)
end
end
end

Launchy.require_all_libs_relative_to(__FILE__)
Empty file added lib/launchy/.git-darcs-dir
Empty file.
48 changes: 48 additions & 0 deletions lib/launchy/gemspec.rb
@@ -0,0 +1,48 @@
require 'rubygems'
require 'launchy/specification'
require 'launchy/version'
require 'rake'

# The Gem Specification plus some extras for launchy.
module Launchy
SPEC = Launchy::Specification.new do |spec|
spec.name = "launchy"
spec.version = Launchy::VERSION
spec.rubyforge_project = "launchy"
spec.author = "Jeremy Hinegardner"
spec.email = "jeremy@hinegardner.org"
spec.homepage = "http://launchy.rubyforge.org/"

spec.summary = "A Summary of launchy."
spec.description = <<-DESC
A longer more detailed description of launchy.
DESC

spec.extra_rdoc_files = FileList["[A-Z]*"]
spec.has_rdoc = true
spec.rdoc_main = "README"
spec.rdoc_options = [ "--line-numbers" , "--inline-source" ]

spec.test_files = FileList["spec/**/*.rb", "test/**/*.rb"]
spec.files = spec.test_files + spec.extra_rdoc_files +
FileList["lib/**/*.rb", "resources/**/*"]

spec.executable = spec.name


# add dependencies
spec.add_dependency("systemu")

spec.platform = Gem::Platform::RUBY

spec.local_rdoc_dir = "doc/rdoc"
spec.remote_rdoc_dir = "#{spec.name}/rdoc"
spec.local_coverage_dir = "doc/coverage"
spec.remote_coverage_dir= "#{spec.name}/coverage"

spec.remote_site_dir = "#{spec.name}/"

end
end


2 changes: 2 additions & 0 deletions lib/launchy/spawnable.rb
@@ -0,0 +1,2 @@
require 'launchy/spawnable/application'
require 'launchy/spawnable/browser'
Empty file.
72 changes: 72 additions & 0 deletions lib/launchy/spawnable/application.rb
@@ -0,0 +1,72 @@
require 'launchy/spawnable'
require 'rbconfig'
require 'systemu'

module Launchy
module Spawnable
class Application

KNOWN_OS_FAMILIES = [ :windows, :darwin, :nix ]

class << self
def inherited(sub_class)
application_classes << sub_class
end
def application_classes
@application_classes ||= []
end

def find_application_class_for(*args)
application_classes.find { |klass| klass.handle?(*args) }
end
end

# find an executable in the available paths
# mkrf did such a good job on this I had to borrow it.
def find_executable(bin,*paths)
paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
paths.each do |path|
file = File.join(path,bin)
return file if File.executable?(file)
end
return nil
end

# return the current 'host_os' string from ruby's configuration
def my_os
::Config::CONFIG['host_os']
end

# detect what the current os is and return :windows, :darwin, :nix or :java
def my_os_family(test_os = my_os)
case test_os
when /mswin/i
family = :windows
when /windows/i
family = :windows
when /darwin/i
family = :darwin
when /mac os/i
family = :darwin
when /solaris/i
family = :nix
when /bsd/i
family = :nix
when /linux/i
family = :nix
when /cygwin/i
family = :nix
else
$stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug."
family = :unknown
end
end

# run the command via systemu
def run(cmd,*args)
args.unshift(cmd)
systemu args.join(' ')
end
end
end
end
50 changes: 50 additions & 0 deletions lib/launchy/spawnable/browser.rb
@@ -0,0 +1,50 @@
require 'launchy/spawnable/application'
require 'uri'

module Launchy
module Spawnable
class Browser < Application
APP_LIST = {
:windows => %w[ firefox iexplore ],
:darwin => %w[ open ],
:nix => %w[ firefox ],
:unknown => [],
}
class << self
def run(*args)
Browser.new.visit(args[0])
end

# return true if this class can handle the given parameter(s)
def handle?(*args)
begin
uri = URI.parse(args[0])
return [URI::HTTP, URI::HTTPS, URI::FTP].include?(uri.class)
rescue Exception
return false
end
end
end

def initialize
raise "Unable to find browser to launch for os family '#{my_os_family}'." unless browser
end

# returns the list of command line application names for the current os
def app_list
APP_LIST[my_os_family]
end

# return the full command line path to the browser or nil
def browser
@browser ||= app_list.collect { |bin| find_executable(bin) }.reject { |x| x.nil? }.first
end

# launch the browser at the appointed url
def visit(url)
run(browser,url)
end

end
end
end

0 comments on commit 0ac2432

Please sign in to comment.