singleserving 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Christopher Sexton
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = singleserving
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Christopher Sexton. See LICENSE for details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "singleserving"
8
+ gem.summary = %Q{Single Serving web server for sharing files}
9
+ gem.description = %Q{Single Serving web server for sharing files over the local network}
10
+ gem.email = "csexton@gmail.com"
11
+ gem.homepage = "http://github.com/csexton/singleserving"
12
+ gem.authors = ["Christopher Sexton"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "singleserving #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'optparse'
4
+ require "#{File.dirname(__FILE__)}/../lib/singleserving"
5
+
6
+ options = { :port => 4337,
7
+ :timeout => 300}
8
+
9
+ OptionParser.new do |opts|
10
+ opts.summary_width = 25
11
+
12
+ opts.banner = "singleserve: http server for sharing"
13
+
14
+ opts.on('--help', "Print this message") do
15
+ puts "#{opts}\n"
16
+ exit
17
+ end
18
+
19
+ opts.on('--version', "Print the version") do
20
+ puts "singleserving #{SingleServing.version}"
21
+ exit
22
+ end
23
+
24
+ opts.on('-p' '--port=PORT', "Port to listen on (Default: #{options[:port]})") do |port|
25
+ options[:port] = port
26
+ end
27
+
28
+
29
+ end.parse!
30
+
31
+ if ARGV.length > 0
32
+ SingleServing.serve(ARGV[0], options)
33
+ exit
34
+ end
35
+
36
+ puts "Invalid option, run `singleserve --help` for usage"
@@ -0,0 +1,16 @@
1
+ require "#{File.dirname(__FILE__)}/singleserving/system_utils"
2
+ require "#{File.dirname(__FILE__)}/singleserving/server"
3
+
4
+
5
+ module SingleServing
6
+ def self.version
7
+ "#{File.open("#{File.dirname(__FILE__)}/../VERSION", "r").read}"
8
+ end
9
+ def self.serve(file, options)
10
+ url = "http://#{SystemUtils.ip_address}:#{options[:port]}/#{File.basename file}" # <-- Ugly, eh?
11
+ SystemUtils.pbcopy(url)
12
+ puts "Serving #{url}"
13
+
14
+ Server.new.serve(file, options[:port])
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'socket' # Get sockets from stdlib
2
+ require 'webrick/httputils' # for WEBrick::HTTPUtils::DefaultMimeTypes
3
+
4
+ module SingleServing
5
+ class Server
6
+ def get_ext(file)
7
+ # Not a great way to get the extension.
8
+ # If there is no '.' character it will return the entire string
9
+ # which is fine if we are looking it up in the DefaultMimeTypes
10
+ # hash, because we probablly won't get a match.
11
+ WEBrick::HTTPUtils::DefaultMimeTypes[file[/([^\.]+$)/]] || "application/octet-stream"
12
+ end
13
+
14
+ def serve(file, port=9000)
15
+ server = TCPServer.open(port) # Socket to listen on port 2000
16
+ client, sock_addr = server.accept # Wait for a client to connect
17
+ # We don't care about the incoming headers, we return the file every time
18
+ #puts client.readline
19
+ #raw_header = ""
20
+ #while line = client.readline
21
+ # break if /\A(\r\n|\n)\z/om =~ line
22
+ # raw_header << line
23
+ #end
24
+
25
+ client.puts "HTTP/100.0 200 OK\r"
26
+ client.puts "Connection: Keep-Alive\r"
27
+ client.puts "Content-Type: #{get_ext(file)}\r"
28
+ client.puts "Server: SingleServe\r"
29
+ client.puts "Content-Disposition: filename=#{File.basename file}\r"
30
+ client.puts "Content-Length: #{File.size file}\r"
31
+ client.puts "\r"
32
+ client.print File.open(file, 'r').read
33
+ client.close
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'socket'
2
+
3
+ module SingleServing
4
+ class SystemUtils
5
+ def self.ip_address
6
+ UDPSocket.open {|s| s.connect('4.4.4.4', 1); s.addr.last}
7
+ end
8
+
9
+ def self.hostname
10
+ Socket.gethostname
11
+ end
12
+
13
+ def self.pbcopy(str)
14
+ system "ruby -e \"print '#{str}'\" | pbcopy"
15
+ rescue
16
+ raise "Copy to clipboard failed"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'stringio'
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe "Server" do
5
+ before(:all) do
6
+ @buffer = StringIO.new
7
+ @tcp_server= mock(TCPServer, :accept => @buffer, :puts => true)
8
+ TCPServer.stub!(:open).and_return(@tcp_server)
9
+
10
+ @s = SingleServing::Server.new
11
+ end
12
+
13
+ it "should server a page" do
14
+ @s.serve(__FILE__, 9292)
15
+ puts @buffer.string
16
+ end
17
+ it "should get the file type" do
18
+ @s.get_ext("/Users/c.sexton/Desktop/Cool-Cucumber.png").should == "image/png"
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Singleserving" do
4
+ it "should have a version" do
5
+ SingleServing.version.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'singleserving'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: singleserving
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Sexton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-29 00:00:00 -05:00
13
+ default_executable: singleserve
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: Single Serving web server for sharing files over the local network
26
+ email: csexton@gmail.com
27
+ executables:
28
+ - singleserve
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - bin/singleserve
42
+ - lib/singleserving.rb
43
+ - lib/singleserving/server.rb
44
+ - lib/singleserving/system_utils.rb
45
+ - spec/server_spec.rb
46
+ - spec/singleserving_spec.rb
47
+ - spec/spec.opts
48
+ - spec/spec_helper.rb
49
+ has_rdoc: true
50
+ homepage: http://github.com/csexton/singleserving
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Single Serving web server for sharing files
77
+ test_files:
78
+ - spec/server_spec.rb
79
+ - spec/singleserving_spec.rb
80
+ - spec/spec_helper.rb