Permalink
Browse files

added nopaste & pastie to rubuildius (thanks to Chuck Remes)

  • Loading branch information...
1 parent a683dd7 commit 8309fe877fab005859b285c682d7dfaaad36661e @bandresen bandresen committed Feb 18, 2008
View
@@ -12,6 +12,10 @@ Currently most files are hardcoded for my box
+ matzbot/plugins/git.rb
+ repo/rubinius/HEAD [empty-dir]
+* bin/rubinius.zsh
+ + bin/pastie_client needs active_support!
+ + bin/nopaste is default for now
+
* everything needs to be in ~/continious
* continious/repo/rubinius/HEAD should contain a git checkout.
@@ -0,0 +1,159 @@
+#!/usr/bin/ruby -w
+#
+# nopaste -- quick script in the spirit of eatpaste, to generate nopaste urls.
+# See http://www.rafb.net/paste/ for more information.
+#
+# Copyright 2005,2007 Aron Griffis <agriffis n01se.net>
+# Released under the GNU General Public License v2
+#
+
+require 'cgi'
+require 'net/http'
+require 'optparse'
+require 'ostruct'
+require 'uri'
+
+class CmdLine
+ def self.parse(args)
+ options = OpenStruct.new
+ options.lang = 'Plain Text'
+
+ opts = OptionParser.new do |opts|
+ opts.banner = "Usage: nopaste [options]"
+ opts.separator ""
+ opts.separator "Options:"
+
+ opts.on("-l", "--language LANG",
+ "set language (defaults to \"Plain Text\")") do |x|
+ options.lang = x
+ end
+
+ opts.on("-d", "--description DESCRIPTION",
+ "set description (defaults to \"stdin\" or filename)") do |x|
+ options.desc = x
+ end
+
+ opts.on("-n", "--nick NICK",
+ "set nick (defaults to your username)") do |x|
+ options.nick = x
+ end
+
+ opts.on("-t", "--txturl",
+ "return url for the plain text file") do
+ options.txturl = true
+ end
+
+ opts.on("-x", "--xcut",
+ "nopaste from X selection (using xclip or xcut)") do
+ options.xcut = true
+ end
+
+ opts.on("--debug",
+ "enable debug output") do
+ options.debug = true
+ end
+
+ opts.on_tail("--help", "show this help") do
+ puts opts
+ exit
+ end
+
+ opts.on_tail("--version", "show version information") do
+ puts "nopaste " + $version
+ exit
+ end
+ end
+
+ opts.parse!(args)
+ options
+ end
+end
+
+def e(s)
+ return $zero+" error: "+s
+end
+
+def nopaste(nick, desc, text, lang = "Plain Text")
+ cxn = Net::HTTP::Proxy($proxy.host, $proxy.port, $proxy_user, $proxy_pass
+ ).start($url.host, $url.port) { |cxn|
+ response = cxn.request_post($url.path,
+ [ "cvt_tabs=No",
+ "lang=#{CGI::escape(lang)}",
+ "nick=#{CGI::escape(nick)}",
+ "desc=#{CGI::escape(desc)}",
+ "text=#{CGI::escape(text)}" ].join('&'),
+ { 'Content-Type' => 'application/x-www-form-urlencoded' })
+
+ if $options.debug
+ STDERR.puts response.inspect
+ response.each_header {|k,v| STDERR.printf "%s: %s\n", k, v}
+ STDERR.puts response.body
+ end
+
+ case response
+ when Net::HTTPRedirection
+ if response['location'] =~ /toofast.html/
+ return e("rafb.net says you're pasting too fast. Try again in 10 seconds")
+ else
+ u = $url.merge(response['location'])
+ u.path = u.path.sub(/html$/, 'txt') if $options.txturl
+ return u
+ end
+ when Net::HTTPSuccess
+ # strange
+ return e("rafb.net sent an unexpected HTML response")
+ else
+ return e("rafb.net says #{response.code} #{response.message}")
+ end
+ }
+end
+
+$proxy = URI.parse(ENV['http_proxy'] || '')
+$proxy_user, $proxy_pass = nil, nil
+$proxy_user, $proxy_pass = $proxy.userinfo.split(/:/) if $proxy.userinfo
+$url = URI.parse("http://www.rafb.net/paste/paste.php")
+$version = '$Revision: 2835 $'.split(' ')[1]
+$zero = $0.sub(/.*\//, '')
+$options = CmdLine.parse(ARGV)
+urls = []
+
+if $options.desc.to_s.empty?
+ if $options.xcut
+ $options.desc = 'xcut'
+ elsif ARGV.empty?
+ $options.desc = 'stdin'
+ else
+ $options.desc = ARGV[0]
+ end
+end
+
+if $options.nick.to_s.empty?
+ $options.nick = ENV['USER'] || 'unknown'
+end
+
+begin
+ if $options.xcut
+ buf = %x{xclip -o 2>/dev/null || xcut -p 2>/dev/null}
+ urls << nopaste($options.nick, $options.desc, buf, $options.lang)
+ elsif ARGV.empty?
+ urls << nopaste($options.nick, $options.desc, gets(nil), $options.lang)
+ end
+
+ urls << nopaste($options.nick, $options.desc, gets(nil), $options.lang) until ARGV.empty?
+ begin
+ IO.popen("xclip 2>/dev/null", "w") {|p| p.print urls.map {|u| u.to_s}.join(' ') }
+ rescue Errno::EPIPE
+ begin
+ IO.popen("xcut 2>/dev/null", "w") {|p| p.print urls.map {|u| u.to_s}.join(' ') }
+ rescue Errno::EPIPE
+ end
+ end
+
+rescue
+ puts urls # whatever we've accumulated already
+ puts e("something bad happened, stack trace follows")
+ raise
+end
+
+puts urls
+exit 1 if urls.join("\n") =~ /^(?!http:)/
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby
+#
+### Pastie from the console (thanks pinupgeek)
+#
+# file = pastie.rb (depends on pastie_client.rb)
+
+require 'pastie_client'
+require 'optparse'
+
+class CliPastie
+
+ attr :parser
+ attr :opt
+
+ def initialize
+ @opt = {
+ :parser => "ruby",
+ :nick => "rubuildius",
+ :key => nil,
+ :help => false
+ }
+
+ @parser = OptionParser.new do |cmd|
+ cmd.banner += " <filename>\n\nReads from STDIN if not passed a filename.\n\n"
+ cmd.on('-h', '--help', 'Show usage') { puts parser.help; exit }
+# cmd.on('-u', '--nick NICK', 'Set nickname') { |n| opt[:nick] = n }
+# cmd.on('-k', '--key KEY', 'Key to authenticate your nick') { |n| opt[:nick] = n }
+ cmd.on('-l', '--language LANG', 'Set language for syntax highlighting') { |l| opt[:parser] = l }
+ end
+ end
+
+ def run
+ parser.parse!(ARGV)
+ if not ARGV.empty?
+ body = File.read(ARGV[0])
+ else
+ body=STDIN.read
+ end
+ return if body.strip.empty?
+
+ p = PastieClient.new( :nick => opt[:nick], :key => opt[:key] )
+ id = p.paste(body, opt[:parser])
+ puts "http://pastie.caboo.se/paste/#{id}"
+ end
+
+end
+
+if __FILE__ == $0
+ CliPastie.new.run
+end
+
@@ -0,0 +1,42 @@
+# Derived from David's simple Backpack API library
+# file = pastie_client.rb (used by pastie.rb)
+
+require 'rubygems'
+require 'net/http'
+#require 'xmlsimple'
+require 'active_support'
+
+class PastieClient
+ attr_accessor :nickname, :key
+
+ def initialize(nick=nil, key=nil)
+ @nick, @key = nick, key
+ connect
+ end
+
+ def connect
+ @connection = Net::HTTP.new("pastie.caboo.se", 80)
+ end
+
+ def request(path, parameters = {})
+# parameters = { "token" => @token }.merge(parameters)
+
+ response = @connection.post(path , parameters.to_xml.gsub(/<\/?hash>/,""), "Content-Type" => "application/xml", "Accept" => "application/xml")
+
+ if response.code =~ /20[01]/
+# result = XmlSimple.xml_in(response.body) rescue response.body
+ result=response.body
+ result.empty? ? true : result
+ else
+ raise "Error occured (#{response.code}): #{response.body}"
+ end
+ end
+ alias :r :request
+
+ # returns the id if the paste was saved successfully
+ def paste(body, syntax="ruby")
+ request("/pastes/create", { :paste => { :body => body, :parser => syntax }})
+ end
+ alias :p :paste
+
+end
@@ -8,7 +8,7 @@ unset RUBYOPT # so that rubinius builds
root=~/continuous
#pastie=$root/bin/pastie.rb
-pastie=nopaste
+pastie=$root/bin/nopaste
rubinius=$root/repo/rubinius
head=$rubinius/HEAD
thischeckout=$rubinius/$1

0 comments on commit 8309fe8

Please sign in to comment.