view_server 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -9,3 +9,4 @@ _yardoc
9
9
  coverage
10
10
  .DS_store
11
11
  doc/
12
+ *.swp
data/bin/cbcopy ADDED
@@ -0,0 +1,11 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'main'
4
+ require 'view_server'
5
+
6
+ Main do
7
+ def run
8
+ ViewServer::Client.new.server.to_cb($stdin.read)
9
+ end
10
+ end
11
+
data/bin/cbpaste ADDED
@@ -0,0 +1,11 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'main'
4
+ require 'view_server'
5
+
6
+ Main do
7
+ def run
8
+ $stdout << ViewServer::Client.new.server.paste
9
+ end
10
+ end
11
+
data/bin/show ADDED
@@ -0,0 +1,50 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'main'
4
+ require 'view_server'
5
+ require 'optparse'
6
+ require 'pry'
7
+ require 'pry-nav'
8
+
9
+ options = {}
10
+
11
+ class ShowRunner
12
+ def self.parse(args)
13
+ options = {}
14
+ opt_parser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: show [options] [file]"
16
+
17
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
18
+ options[:verbose] = v
19
+ end
20
+
21
+ opts.on("-e", "--extension EXTENSION", "File extension") do |v|
22
+ options[:ext] = v
23
+ end
24
+
25
+ opts.on("-p", "--port PORT", "Port number") do |v|
26
+ options[:ext] = v
27
+ end
28
+ end
29
+
30
+ opt_parser.parse!(args)
31
+ filename = ARGV.first
32
+ if filename
33
+ data = File.read filename
34
+ ext = File.extname(filename)[1..-1]
35
+ else
36
+ data = $stdin.read
37
+ ext = options.fetch(:ext) {'txt'}
38
+ end
39
+
40
+ {:data => data, :ext => ext }
41
+ end
42
+
43
+ def self.run(args)
44
+ opts = self.parse args
45
+ ViewServer::Client.new.server.show(opts[:data], opts[:ext])
46
+ end
47
+ end
48
+ options = ShowRunner.run(ARGV)
49
+
50
+
data/bin/view_server CHANGED
@@ -1,91 +1,3 @@
1
- #!/usr/bin/env ruby
1
+ require 'view_server'
2
2
 
3
- # server
4
- require 'tmpdir'
5
- require 'fileutils'
6
- require 'digest'
7
-
8
- require "rubygems"
9
- require "clip"
10
-
11
- class TmpFile
12
- def self.open(prefix = "", suffix= "")
13
- begin
14
- digest = Digest::MD5.hexdigest((Time.now.to_f + rand(10000)).to_s)
15
- file_name = File.join(Dir.tmpdir, prefix + digest + suffix )
16
- File.open(file_name, 'w+' ) do |f|
17
- yield f
18
- end
19
- ensure
20
- FileUtils::rm(file_name) if File.exist?(file_name)
21
- end
22
- end
23
- end
24
-
25
- options = Clip do |p|
26
- p.flag 's', 'server',:desc => 'Is a server', :default => false
27
-
28
- p.optional 'p', 'port', :desc => 'The port', :default => 10021 do |v|
29
- v.to_i # always deal with integers
30
- end
31
- p.flag 'c', 'copy_to_clipboard', :desc => "Send to clipboard"
32
- p.flag 'P', 'paste_from_clipboard', :desc => "Read from clipboard"
33
- p.flag 'v', 'verbose', :desc => 'Make it chatty'
34
- end
35
-
36
- if options.valid?
37
- if options.verbose?
38
- puts options.host
39
- puts options.port
40
- puts 'files:'
41
- options.files.each do |f|
42
- puts "\t#{f}"
43
- end
44
- end
45
- else
46
- # print error message(s) and usage
47
- $stderr.puts options.to_s
48
- end
49
-
50
-
51
- require 'drb'
52
-
53
- if options.server?
54
- class Viewer
55
- def affiche(file_ext, data)
56
- TmpFile.open( "", "." + file_ext) do |a|
57
- a << data
58
- a.close
59
- `open #{a.path} `
60
- sleep 5 #We don't want to delete the file before it's loaded
61
- end
62
- end
63
-
64
- def to_cb(data) # To clipboard
65
- File.open("#{ENV['HOME']}/tmp/clipboard", "w"){|a| a << data}
66
- IO.popen('pbcopy', 'w'){|a| a << data}
67
- end
68
-
69
- def paste # From clipboard
70
- `pbpaste`
71
- end
72
- end
73
-
74
- DRb.start_service "druby://localhost:#{options.port}", Viewer.new
75
- puts DRb.uri
76
-
77
- DRb.thread.join
78
- else
79
- DRb.start_service
80
- obj = DRbObject.new(nil, "druby://localhost:#{options.port}")
81
-
82
- if options.copy_to_clipboard?
83
- obj.to_cb(STDIN.read)
84
- elsif options.paste_from_clipboard?
85
- print obj.paste
86
- else
87
- if obj.remaining?
88
- affiche("csv", "2,4,5\n3,4,5")
89
- end
90
- end
91
- end
3
+ ViewServer::Runner.run
data/lib/view_server.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "view_server/version"
2
2
 
3
3
  module ViewServer
4
- # Your code goes here...
4
+ autoload :Server, 'view_server/server'
5
+ autoload :Client, 'view_server/client'
6
+ autoload :Runner, 'view_server/runner'
7
+ autoload :TmpFile, 'view_server/tmp_file'
5
8
  end
@@ -0,0 +1,13 @@
1
+ require 'drb'
2
+ require 'pry'
3
+
4
+ module ViewServer
5
+ class Client
6
+ attr_reader :server
7
+
8
+ def initialize(port = 10021)
9
+ DRb.start_service
10
+ @server = DRbObject.new(nil, "druby://localhost:#{port}")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ require 'main'
2
+
3
+ module ViewServer
4
+ class Runner
5
+ def self.old_run
6
+ options = Clip do |p|
7
+ p.flag 's', 'server',:desc => 'Is a server', :default => false
8
+
9
+ p.optional 'p', 'port', :desc => 'The port', :default => 10021 do |v|
10
+ v.to_i # always deal with integers
11
+ end
12
+ p.flag 'c', 'copy_to_clipboard', :desc => "Send to clipboard"
13
+ p.flag 'P', 'paste_from_clipboard', :desc => "Read from clipboard"
14
+ p.flag 'v', 'verbose', :desc => 'Make it chatty'
15
+ end
16
+
17
+ if options.valid?
18
+ if options.verbose?
19
+ puts options.host
20
+ puts options.port
21
+ puts 'files:'
22
+ options.files.each do |f|
23
+ puts "\t#{f}"
24
+ end
25
+ end
26
+ if options.server?
27
+ Server.serve(options)
28
+ else
29
+ Client.new(options.port).send(options)
30
+ end
31
+ else
32
+ # print error message(s) and usage
33
+ $stderr.puts options.to_s
34
+ end
35
+ end
36
+
37
+ def self.run
38
+ main.run
39
+ end
40
+
41
+ def self.main
42
+ main = Main.new do
43
+ option 'port', 'p' do
44
+ cast :int
45
+ default 10021
46
+ end
47
+
48
+ option 'verbose', 'v' do
49
+ default false
50
+ end
51
+
52
+ def run
53
+ puts "serving on port #{params['port']}"
54
+ Server.serve params['port'].value
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ require 'drb'
2
+
3
+ module ViewServer
4
+ class Server
5
+ # I wanted to use the display method but it conflicts
6
+ # with the Object#display method
7
+ def show(data, file_ext = 'txt')
8
+ TmpFile.open("", "." + file_ext) do |a|
9
+ a << data
10
+ a.close
11
+ `open #{a.path} `
12
+ sleep 5 #We don't want to delete the file before it's loaded
13
+ end
14
+ end
15
+
16
+ def to_cb(data) # To clipboard
17
+ File.open("#{ENV['HOME']}/tmp/clipboard", "w"){|a| a << data}
18
+ IO.popen('pbcopy', 'w'){|a| a << data}
19
+ end
20
+
21
+ def paste # From clipboard
22
+ `pbpaste`
23
+ end
24
+
25
+ def self.serve(port)
26
+ DRb.start_service "druby://localhost:#{port}", Server.new
27
+ puts DRb.uri
28
+ DRb.thread.join
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+ require 'digest'
4
+
5
+ module ViewServer
6
+ class TmpFile
7
+ def self.open(prefix = "", suffix= "")
8
+ begin
9
+ digest = Digest::MD5.hexdigest((Time.now.to_f + rand(10000)).to_s)
10
+ file_name = File.join(Dir.tmpdir, prefix + digest + suffix )
11
+ File.open(file_name, 'w+' ) do |f|
12
+ yield f
13
+ end
14
+ ensure
15
+ FileUtils::rm(file_name) if File.exist?(file_name)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -1,3 +1,3 @@
1
1
  module ViewServer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ViewServer Runner Main' do
4
+ before do
5
+ @main = ViewServer.main
6
+ end
7
+
8
+ it 'should start as a sever' do
9
+ end
10
+ end
@@ -1,4 +1,4 @@
1
1
  $:.unshift File.expand_path('..', __FILE__)
2
2
  $:.unshift File.expand_path('../../lib', __FILE__)
3
- require 'minitest/unit'
3
+ require 'minitest/spec'
4
4
  require 'minitest/autorun'
data/view_server.gemspec CHANGED
@@ -7,9 +7,12 @@ Gem::Specification.new do |gem|
7
7
  gem.name = "view_server"
8
8
  gem.version = ViewServer::VERSION
9
9
  gem.add_dependency "clip"
10
+ gem.add_dependency "main"
10
11
  gem.add_development_dependency 'rake'
11
12
  gem.add_development_dependency "bundler", "~> 1.0"
12
13
  gem.add_development_dependency 'minitest'
14
+ gem.add_development_dependency 'pry'
15
+ gem.add_development_dependency 'pry-nav'
13
16
  gem.authors = ["Martin Chabot"]
14
17
  gem.email = ["chabotm@gmail.com"]
15
18
  gem.description = %q{Allow local viewing of remote files}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-11 00:00:00.000000000 Z
12
+ date: 2013-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clip
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: main
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rake
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -75,10 +91,45 @@ dependencies:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry-nav
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
78
126
  description: Allow local viewing of remote files
79
127
  email:
80
128
  - chabotm@gmail.com
81
129
  executables:
130
+ - cbcopy
131
+ - cbpaste
132
+ - show
82
133
  - view_server
83
134
  extensions: []
84
135
  extra_rdoc_files: []
@@ -88,10 +139,18 @@ files:
88
139
  - LICENSE.txt
89
140
  - README.md
90
141
  - Rakefile
142
+ - bin/cbcopy
143
+ - bin/cbpaste
144
+ - bin/show
91
145
  - bin/view_server
92
146
  - lib/view_server.rb
147
+ - lib/view_server/client.rb
148
+ - lib/view_server/runner.rb
149
+ - lib/view_server/server.rb
150
+ - lib/view_server/tmp_file.rb
93
151
  - lib/view_server/version.rb
94
- - test/test_helper.rb
152
+ - test/runner_spec.rb
153
+ - test/spec_helper.rb
95
154
  - test/view_server_test.rb
96
155
  - view_server.gemspec
97
156
  homepage: ''
@@ -108,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
167
  version: '0'
109
168
  segments:
110
169
  - 0
111
- hash: -2501156995423652076
170
+ hash: 4172687942151470953
112
171
  required_rubygems_version: !ruby/object:Gem::Requirement
113
172
  none: false
114
173
  requirements:
@@ -117,13 +176,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
176
  version: '0'
118
177
  segments:
119
178
  - 0
120
- hash: -2501156995423652076
179
+ hash: 4172687942151470953
121
180
  requirements: []
122
181
  rubyforge_project:
123
- rubygems_version: 1.8.24
182
+ rubygems_version: 1.8.23
124
183
  signing_key:
125
184
  specification_version: 3
126
185
  summary: Allow local viewing of remote files
127
186
  test_files:
128
- - test/test_helper.rb
187
+ - test/runner_spec.rb
188
+ - test/spec_helper.rb
129
189
  - test/view_server_test.rb