oode 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -15
- data/bin/oode +51 -1
- data/lib/oode.rb +2 -0
- data/lib/oode/colour.rb +6 -8
- data/lib/oode/file.rb +27 -0
- data/lib/oode/queue.rb +65 -0
- data/lib/oode/version.rb +1 -1
- data/man/oode.1 +23 -0
- data/man/oode.1.html +98 -0
- data/man/oode.1.ronn +25 -0
- metadata +33 -8
- data/spec/oode_spec.rb +0 -7
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -2
data/Rakefile
CHANGED
@@ -23,22 +23,7 @@ end
|
|
23
23
|
# Tests
|
24
24
|
#
|
25
25
|
|
26
|
-
begin
|
27
|
-
require 'spec/rake/spectask'
|
28
|
-
rescue LoadError
|
29
|
-
puts 'To use rspec for testing you must install rspec gem:'
|
30
|
-
puts '$ sudo gem install rspec'
|
31
|
-
exit
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Run the specs under spec"
|
35
|
-
Spec::Rake::SpecTask.new do |t|
|
36
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
37
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
38
|
-
end
|
39
26
|
|
40
|
-
desc "Default task is to run specs"
|
41
|
-
task :default => :spec
|
42
27
|
|
43
28
|
#
|
44
29
|
# Ron
|
data/bin/oode
CHANGED
@@ -1,22 +1,72 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "optparse"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
require "rubygems"
|
7
|
+
require "net/ssh"
|
8
|
+
require "net/sftp"
|
4
9
|
|
5
10
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
6
11
|
require "oode"
|
7
12
|
|
8
13
|
options = {}
|
9
14
|
|
15
|
+
begin
|
16
|
+
config = YAML.load_file(File.expand_path('~/.ooderc'))
|
17
|
+
rescue
|
18
|
+
config = { :user => nil, :password => nil}
|
19
|
+
end
|
20
|
+
|
10
21
|
optparse = OptionParser.new do |opts|
|
11
22
|
opts.banner = "Usage: oode [options] filename"
|
12
23
|
|
24
|
+
opts.on( "-h", "--help", "Display this screen." ) do
|
25
|
+
puts opts
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
13
29
|
options[:printer] = nil
|
14
30
|
opts.on( "-p", "--printer PRINTER", "The printer to send the file to." ) do |printer|
|
15
31
|
options[:printer] = printer
|
16
32
|
end
|
33
|
+
|
34
|
+
options[:user] = config[:user]
|
35
|
+
opts.on( "-u", "--user USER", "The user to log into DICE with." ) do |user|
|
36
|
+
options[:user] = user
|
37
|
+
end
|
38
|
+
|
39
|
+
options[:password] = config[:password]
|
40
|
+
opts.on( "-a", "--password PASSWORD",
|
41
|
+
"The password to log into DICE with." ) do |password|
|
42
|
+
options[:password] = password
|
43
|
+
end
|
17
44
|
end
|
18
45
|
|
19
46
|
optparse.parse!
|
20
47
|
|
21
|
-
|
48
|
+
if options[:printer].nil?
|
49
|
+
puts "No printer was specified.".red
|
50
|
+
puts "Please specify one with the '--printer' or '-p' flags."
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
if options[:user].nil?
|
55
|
+
puts "No user was specified.".red
|
56
|
+
puts "Please specify one with the '--user' or '-u' flags or set it in the configuration."
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
if options[:password].nil?
|
61
|
+
puts "No password was specified.".red
|
62
|
+
puts "Please specify one with the '--password' or '-a' flags or set it in the configuration."
|
63
|
+
exit
|
64
|
+
end
|
65
|
+
|
66
|
+
print_queue = Oode::OodeQueue.new options[:user], options[:password], options[:printer]
|
67
|
+
|
68
|
+
ARGV.each do |filename|
|
69
|
+
print_queue.enqueue filename
|
70
|
+
end
|
22
71
|
|
72
|
+
print_queue.print
|
data/lib/oode.rb
CHANGED
data/lib/oode/colour.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
define_method :"#{color}ish" do "\033[0;#{30+i}m#{self}\033[0m" end
|
7
|
-
end
|
1
|
+
# This wonderful code taken from http://github.com/michaeldv/awesome_print.
|
2
|
+
class String
|
3
|
+
[:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white].each_with_index do |color, offset|
|
4
|
+
define_method color do "\033[1;#{30+offset}m#{self}\033[0m" end
|
5
|
+
define_method :"#{color}ish" do "\033[0;#{30+offset}m#{self}\033[0m" end
|
8
6
|
end
|
9
|
-
end
|
7
|
+
end
|
data/lib/oode/file.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Oode
|
2
|
+
class OodeFile
|
3
|
+
def initialize filename
|
4
|
+
@filename = filename
|
5
|
+
end
|
6
|
+
|
7
|
+
def upload session, destination
|
8
|
+
session.upload! File.expand_path(@filename), File.join(destination, @filename)
|
9
|
+
end
|
10
|
+
|
11
|
+
def print session, directory, printer
|
12
|
+
command = "lpr -P #{printer} #{remote_path}"
|
13
|
+
session.exec!(command)
|
14
|
+
#puts command.blue
|
15
|
+
end
|
16
|
+
|
17
|
+
def clean session, directory
|
18
|
+
command = "rm #{remote_path}"
|
19
|
+
session.exec!(command)
|
20
|
+
#puts command.blue
|
21
|
+
end
|
22
|
+
|
23
|
+
def remote_path
|
24
|
+
File.join File.expand_path("~/.oode/"), @filename
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/oode/queue.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Oode
|
2
|
+
class OodeQueue
|
3
|
+
attr_reader :queue
|
4
|
+
|
5
|
+
def initialize(user, password, printer)
|
6
|
+
@queue = []
|
7
|
+
@user = user
|
8
|
+
@password = password
|
9
|
+
@printer = printer
|
10
|
+
end
|
11
|
+
|
12
|
+
def print
|
13
|
+
Net::SSH.start('ssh.inf.ed.ac.uk', @user, :password => @password) do |ssh|
|
14
|
+
sftp = ssh.sftp
|
15
|
+
|
16
|
+
puts "Checking remote destination...".yellow
|
17
|
+
unless sftp.dir.entries(remote_user_path).map { |d| d.name }.include? ".oode"
|
18
|
+
sftp.mkdir! remote_oode_path
|
19
|
+
end
|
20
|
+
|
21
|
+
puts "Uploading files for printing...".yellow
|
22
|
+
@queue.each do |file|
|
23
|
+
file.upload sftp, remote_oode_path
|
24
|
+
end
|
25
|
+
|
26
|
+
puts "Printing files on #{@printer.red}...".yellow
|
27
|
+
@queue.each do |file|
|
28
|
+
file.print ssh, remote_oode_path, @printer
|
29
|
+
end
|
30
|
+
|
31
|
+
# Make sure the job has been sent to the printer.
|
32
|
+
sleep 1
|
33
|
+
|
34
|
+
puts "Cleaning up this mess...".yellow
|
35
|
+
@queue.each do |file|
|
36
|
+
file.clean ssh, remote_oode_path
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def remote_user_path
|
42
|
+
"/home/#{@user}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def remote_oode_path
|
46
|
+
File.join remote_user_path, ".oode"
|
47
|
+
end
|
48
|
+
|
49
|
+
def clean
|
50
|
+
end
|
51
|
+
|
52
|
+
def length
|
53
|
+
@queue.length
|
54
|
+
end
|
55
|
+
|
56
|
+
def enqueue(filename)
|
57
|
+
file = OodeFile.new(filename)
|
58
|
+
@queue.push file
|
59
|
+
end
|
60
|
+
|
61
|
+
def clear
|
62
|
+
@queue.clear
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/oode/version.rb
CHANGED
data/man/oode.1
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
.\" generated with Ronn/v0.5
|
2
|
+
.\" http://github.com/rtomayko/ronn/
|
3
|
+
.
|
4
|
+
.TH "OODE" "1" "April 2010" "XOEBUS" "Oode Manual"
|
5
|
+
.
|
6
|
+
.SH "NAME"
|
7
|
+
\fBoode\fR \-\- print from a laptop to an AT printer
|
8
|
+
.
|
9
|
+
.SH "SYNOPSIS"
|
10
|
+
\fBoode\fR \fIOPTIONS\fR \fIFILENAMES\fR
|
11
|
+
.
|
12
|
+
.SH "DESCRIPTION"
|
13
|
+
.
|
14
|
+
.SH "CONFIGURATION"
|
15
|
+
.
|
16
|
+
.SH "BUGS"
|
17
|
+
\fIhttp://github.com/xoebus/oode/issues\fR
|
18
|
+
.
|
19
|
+
.SH "AUTHOR"
|
20
|
+
Chris Brown :: cb@tardis.ed.ac.uk :: @xoebus
|
21
|
+
.
|
22
|
+
.SH "SEE ALSO"
|
23
|
+
\fIhttp://github.com\fR, \fIhttp://github.com/xoebus/oode\fR
|
data/man/oode.1.html
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv='content-type' value='text/html;charset=utf8'>
|
5
|
+
<meta name='generator' value='Ronn/v0.5'>
|
6
|
+
<title>oode(1) -- print from a laptop to an AT printer</title>
|
7
|
+
<style type='text/css'>
|
8
|
+
body {margin:0}
|
9
|
+
#man, #man code, #man pre, #man tt, #man kbd, #man samp {
|
10
|
+
font-family:consolas,monospace;
|
11
|
+
font-size:16px;
|
12
|
+
line-height:1.3;
|
13
|
+
color:#343331;
|
14
|
+
background:#fff; }
|
15
|
+
#man { max-width:89ex; text-align:justify; margin:0 25px 25px 25px }
|
16
|
+
#man h1, #man h2, #man h3 { color:#232221;clear:left }
|
17
|
+
#man h1 { font-size:28px; margin:15px 0 30px 0; text-align:center }
|
18
|
+
#man h2 { font-size:18px; margin-bottom:0; margin-top:10px; line-height:1.3; }
|
19
|
+
#man h3 { font-size:16px; margin:0 0 0 4ex; }
|
20
|
+
#man p, #man ul, #man ol, #man dl, #man pre { margin:0 0 18px 0; }
|
21
|
+
#man pre {
|
22
|
+
color:#333231;
|
23
|
+
background:#edeceb;
|
24
|
+
padding:5px 7px;
|
25
|
+
margin:0px 0 20px 0;
|
26
|
+
border-left:2ex solid #ddd}
|
27
|
+
#man pre + h2, #man pre + h3 {
|
28
|
+
margin-top:22px;
|
29
|
+
}
|
30
|
+
#man h2 + pre, #man h3 + pre {
|
31
|
+
margin-top:5px;
|
32
|
+
}
|
33
|
+
#man > p, #man > ul, #man > ol, #man > dl, #man > pre { margin-left:8ex; }
|
34
|
+
#man dt { margin:0; clear:left }
|
35
|
+
#man dt.flush { float:left; width:8ex }
|
36
|
+
#man dd { margin:0 0 0 9ex }
|
37
|
+
#man code, #man strong, #man b { font-weight:bold; color:#131211; }
|
38
|
+
#man pre code { font-weight:normal; color:#232221; background:inherit }
|
39
|
+
#man em, var, u {
|
40
|
+
font-style:normal; color:#333231; border-bottom:1px solid #999; }
|
41
|
+
#man h1.man-title { display:none; }
|
42
|
+
#man ol.man, #man ol.man li { margin:2px 0 10px 0; padding:0;
|
43
|
+
float:left; width:33%; list-style-type:none;
|
44
|
+
text-transform:uppercase; font-size:18px; color:#999;
|
45
|
+
letter-spacing:1px;}
|
46
|
+
#man ol.man { width:100%; }
|
47
|
+
#man ol.man li.tl { text-align:left }
|
48
|
+
#man ol.man li.tc { text-align:center;letter-spacing:4px }
|
49
|
+
#man ol.man li.tr { text-align:right }
|
50
|
+
#man ol.man a { color:#999 }
|
51
|
+
#man ol.man a:hover { color:#333231 }
|
52
|
+
</style>
|
53
|
+
</head>
|
54
|
+
<body>
|
55
|
+
<div id='man'>
|
56
|
+
|
57
|
+
<h1 class='man-title'>oode(1)</h1>
|
58
|
+
|
59
|
+
<ol class='head man'>
|
60
|
+
<li class='tl'>oode(1)</li>
|
61
|
+
<li class='tc'>Oode Manual</li>
|
62
|
+
<li class='tr'>oode(1)</li>
|
63
|
+
</ol>
|
64
|
+
|
65
|
+
<h2 id='NAME'>NAME</h2>
|
66
|
+
<p><code>oode</code> -- print from a laptop to an AT printer</p>
|
67
|
+
|
68
|
+
<h2>SYNOPSIS</h2>
|
69
|
+
|
70
|
+
<p><code>oode</code> <var>OPTIONS</var> <var>FILENAMES</var></p>
|
71
|
+
|
72
|
+
<h2>DESCRIPTION</h2>
|
73
|
+
|
74
|
+
<h2>CONFIGURATION</h2>
|
75
|
+
|
76
|
+
<h2>BUGS</h2>
|
77
|
+
|
78
|
+
<p><a href="http://github.com/xoebus/oode/issues">http://github.com/xoebus/oode/issues</a></p>
|
79
|
+
|
80
|
+
<h2>AUTHOR</h2>
|
81
|
+
|
82
|
+
<p>Chris Brown :: cb@tardis.ed.ac.uk :: @xoebus</p>
|
83
|
+
|
84
|
+
<h2>SEE ALSO</h2>
|
85
|
+
|
86
|
+
<p><a href="http://github.com">http://github.com</a>,
|
87
|
+
<a href="http://github.com/xoebus/oode">http://github.com/xoebus/oode</a></p>
|
88
|
+
|
89
|
+
|
90
|
+
<ol class='foot man'>
|
91
|
+
<li class='tl'>XOEBUS</li>
|
92
|
+
<li class='tc'>April 2010</li>
|
93
|
+
<li class='tr'>oode(1)</li>
|
94
|
+
</ol>
|
95
|
+
|
96
|
+
</div>
|
97
|
+
</body>
|
98
|
+
</html>
|
data/man/oode.1.ronn
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
oode(1) -- print from a laptop to an AT printer
|
2
|
+
===============================================
|
3
|
+
|
4
|
+
## SYNOPSIS
|
5
|
+
|
6
|
+
`oode` <OPTIONS> <FILENAMES>
|
7
|
+
|
8
|
+
## DESCRIPTION
|
9
|
+
|
10
|
+
|
11
|
+
## CONFIGURATION
|
12
|
+
|
13
|
+
|
14
|
+
## BUGS
|
15
|
+
|
16
|
+
<http://github.com/xoebus/oode/issues>
|
17
|
+
|
18
|
+
## AUTHOR
|
19
|
+
|
20
|
+
Chris Brown :: cb@tardis.ed.ac.uk :: @xoebus
|
21
|
+
|
22
|
+
## SEE ALSO
|
23
|
+
|
24
|
+
<http://github.com>,
|
25
|
+
<http://github.com/xoebus/oode>
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Chris Brown
|
@@ -14,10 +14,33 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-26 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: net-ssh
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: net-sftp
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
21
44
|
description: oode prints to AT printers from laptops
|
22
45
|
email: cb@tardis.ed.ac.uk
|
23
46
|
executables:
|
@@ -31,12 +54,14 @@ files:
|
|
31
54
|
- Rakefile
|
32
55
|
- LICENSE
|
33
56
|
- lib/oode/colour.rb
|
57
|
+
- lib/oode/file.rb
|
58
|
+
- lib/oode/queue.rb
|
34
59
|
- lib/oode/version.rb
|
35
60
|
- lib/oode.rb
|
36
61
|
- bin/oode
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
62
|
+
- man/oode.1
|
63
|
+
- man/oode.1.html
|
64
|
+
- man/oode.1.ronn
|
40
65
|
has_rdoc: true
|
41
66
|
homepage: http://github.com/xoebus/oode
|
42
67
|
licenses: []
|
data/spec/oode_spec.rb
DELETED
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour
|
data/spec/spec_helper.rb
DELETED