Skip to content
Browse files

1.0 in first commit, the way it should be.

  • Loading branch information...
0 parents commit e7f460b2e5cc5dfa14093964e92b7b1f496f16d8 @evanphx committed Jun 3, 2008
Showing with 267 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +55 −0 README.rdoc
  3. +47 −0 Rakefile
  4. +27 −0 bin/gemjour
  5. +24 −0 gemjour.gemspec
  6. +109 −0 lib/gemjour.rb
  7. +3 −0 lib/gemjour/version.rb
2 .gitignore
@@ -0,0 +1,2 @@
+pkg
+.*.sw?
55 README.rdoc
@@ -0,0 +1,55 @@
+= Pastejour
+
+Broadcast standard out.
+
+== Installation
+
+ sudo gem install dnssd
+ sudo gem install jbarnette-pastejour --source=http://gems.github.com
+
+== Usage
+
+ alice$ git diff | pastejour
+ bob$ pastejour alice | cat
+
+ alice$ git diff | pastejour bob
+ bob$ pastejour | cat
+
+ alice$ git diff | pastejour monkeys
+ bob$ pastejour alice-monkeys | cat
+
+== ORLY?
+
+Yup. Pastejour gives you a simple, discoverable pipe for standard in and
+out. By default, Pastejour will only stay up until the first person
+grabs your paste. If you want to let a bunch of people grab the same
+thing, shoot it out in multiple mode:
+
+ alice$ git diff | pastejour -m # keeps on serving 'til you CTRL-C
+
+== Awesome!
+
+You know it.
+
+== License
+
+Copyright (c) 2008 John Barnette, Evan Phoenix
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47 Rakefile
@@ -0,0 +1,47 @@
+require "date"
+require "fileutils"
+require "rubygems"
+require "rake/gempackagetask"
+
+require "./lib/gemjour/version.rb"
+
+gemjour_gemspec = Gem::Specification.new do |s|
+ s.name = "gemjour"
+ s.version = Gemjour::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README.rdoc"]
+ s.summary = "Advertise, list, and install gems over Bonjour."
+ s.description = s.summary
+ s.authors = ["Evan Phoenix"]
+ s.email = "evan@fallingsnow.net"
+ s.homepage = "http://github.com/evanphx/gemjour"
+ s.require_path = "lib"
+ s.autorequire = "gemjour"
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{bin,lib}/**/*")
+ s.executables = %w(gemjour)
+
+ s.add_dependency "dnssd", ">= 0.6.0"
+end
+
+Rake::GemPackageTask.new(gemjour_gemspec) do |pkg|
+ pkg.gem_spec = gemjour_gemspec
+end
+
+namespace :gem do
+ namespace :spec do
+ desc "Update gemjour.gemspec"
+ task :generate do
+ File.open("gemjour.gemspec", "w") do |f|
+ f.puts(gemjour_gemspec.to_ruby)
+ end
+ end
+ end
+end
+
+task :install => :package do
+ sh %{sudo gem install pkg/gemjour-#{Gemjour::VERSION}}
+end
+
+desc "Remove all generated artifacts"
+task :clean => :clobber_package
27 bin/gemjour
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+require "rubygems"
+require "gemjour"
+
+begin
+
+ cmd = ARGV.shift
+
+ case cmd
+ when "serve"
+ Gemjour.serve(*ARGV)
+ when "list"
+ Gemjour.list
+ when "show"
+ Gemjour.show(*ARGV)
+ when "install"
+ Gemjour.install(*ARGV)
+ else
+ Gemjour.usage
+ end
+
+rescue => e
+ puts "ERROR: running '#{cmd}': #{e.message} (#{e.class})"
+ puts
+ Gemjour.usage
+end
24 gemjour.gemspec
@@ -0,0 +1,24 @@
+Gem::Specification.new do |s|
+ s.name = %q{gemjour}
+ s.version = "1.0.0"
+
+ s.specification_version = 2 if s.respond_to? :specification_version=
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Evan Phoenix"]
+ s.autorequire = %q{gemjour}
+ s.date = %q{2008-06-03}
+ s.default_executable = %q{gemjour}
+ s.description = %q{Advertise, list, and install gems over Bonjour.}
+ s.email = %q{evan@fallingsnow.net}
+ s.executables = ["gemjour"]
+ s.extra_rdoc_files = ["README.rdoc"]
+ s.files = ["README.rdoc", "Rakefile", "bin/gemjour", "lib/gemjour", "lib/gemjour/version.rb", "lib/gemjour.rb"]
+ s.has_rdoc = true
+ s.homepage = %q{http://github.com/evanphx/gemjour}
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.1.1}
+ s.summary = %q{Advertise, list, and install gems over Bonjour.}
+
+ s.add_dependency(%q<dnssd>, [">= 0.6.0"])
+end
109 lib/gemjour.rb
@@ -0,0 +1,109 @@
+require "dnssd"
+require "set"
+require "gemjour/version"
+
+Thread.abort_on_exception = true
+
+module Gemjour
+ Server = Struct.new(:name, :host, :port)
+ PORT = 8808
+ SERVICE = "_rubygems._tcp"
+
+ def self.usage
+ puts <<-HELP
+Usage:
+
+serve [<name>] [<port>]
+ Start up a gem server as <name> on <port>. <name> is your username
+ by default, and <port> is 8088. If you want to use the default <name>,
+ pass it as "".
+
+install <server> <gem>
+ Installs <gem> from <server>. <server> is the name the server announces
+ itself as.
+
+list
+ List all available gem servers.
+
+show <server>
+ List all gems available from <server>
+
+ HELP
+ end
+
+ def self.find(name)
+ host = nil
+
+ waiting = Thread.current
+
+ service = DNSSD.browse(SERVICE) do |reply|
+ if name === reply.name
+ DNSSD.resolve(reply.name, reply.type, reply.domain) do |rr|
+ host = Server.new(reply.name, rr.target, rr.port)
+ waiting.run
+ end
+ end
+ end
+
+ sleep 5
+ service.stop
+
+ host
+ end
+
+ def self.list
+ hosts = []
+
+ waiting = Thread.current
+
+ service = DNSSD.browse(SERVICE) do |reply|
+ DNSSD.resolve(reply.name, reply.type, reply.domain) do |rr|
+ host = Server.new(reply.name, rr.target, rr.port)
+ unless hosts.include? host
+ puts "#{host.name} (#{host.host}:#{host.port})"
+ hosts << host
+ end
+ end
+ end
+
+ sleep 5
+ service.stop
+ end
+
+ def self.show(name)
+ host = find(name)
+
+ unless host
+ puts "ERROR: Unable to find server '#{name}'"
+ return
+ end
+
+ system "gem list -r --source=http://#{host.host}:#{host.port}"
+ end
+
+ def self.install(name, gem)
+ host = find(name)
+
+ unless host
+ puts "ERROR: Unable to find server named '#{user}'"
+ return
+ end
+
+ puts "Installing gem '#{gem}' from #{host.host}:#{host.port}"
+ system "gem install #{gem} -s http://#{host.host}:#{host.port}"
+ end
+
+ def self.serve(name="", port=PORT)
+ name = ENV['USER'] if name.empty?
+
+ tr = DNSSD::TextRecord.new
+ tr['description'] = "#{name}'s gem server"
+
+ DNSSD.register(name, SERVICE, "local", port, tr.encode) do |reply|
+ puts "Serving gems under name '#{name}'..."
+ end
+
+ system "gem server --port=#{port} -q > /dev/null 2>&1"
+ end
+
+end
3 lib/gemjour/version.rb
@@ -0,0 +1,3 @@
+module Gemjour
+ VERSION = "1.0.0".freeze
+end

0 comments on commit e7f460b

Please sign in to comment.
Something went wrong with that request. Please try again.