oode 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,68 +1,67 @@
1
- oode(1) -- print from a laptop to an AT printer
2
- ===============================================
1
+ oode(1) -- work with DICE from a laptop
2
+ =======================================
3
3
 
4
4
  ## SYNOPSIS
5
5
 
6
- `oode` [<OPTIONS>] <FILE>...<br>
6
+ `oode` [<GLOBAL OPTIONS>] <COMMAND> [<OPTIONS>] <FILE>...
7
7
 
8
8
  ## DESCRIPTION
9
9
 
10
- `oode` makes printing to the printers in Appleton Tower much easier
11
- from laptops by automating some of the tediousness from the sequence
12
- of tasks required.
10
+ `oode` is a program that simplifies working with the DICE network from
11
+ a laptop in Appleton Tower. As of the current version `oode` is able to
12
+ print to any of the printers on the DICE network with more functionality
13
+ in the near future.
13
14
 
14
15
  ## SAMPLE USAGE
15
16
 
16
- * `oode -p at3 file.pdf`:
17
- Print `file.pdf` to the printer `at3`.
17
+ * `oode print -P at3 file.pdf`:
18
+ Print the file *file.pdf* to the printer *at3*.
18
19
 
19
- * `oode -p at13c -4 -n 5 file.pdf`:
20
- Print 5 copies of `file.pdf` to printer `at13c` using the 4-up layout.
21
-
22
- * `oode -p at13c -u s08xxxxx -a passw0rd file.pdf`:
23
- Print `file.pdf` to `at13c` as user `s08xxxxx` authenticating with password `passw0rd`.
20
+ * `oode print -P at13c -2 -n 3 file.pdf`:
21
+ Print *3* copies of the file *file.pdf* to the printer *at3* in the
22
+ *two-up* page layout.
24
23
 
25
24
  ## CONFIGURATION
26
25
 
27
26
  `oode` can read SSH authentication usernames and passwords from a
28
- configuration file so you don't have to type them in every time. A
29
- file called `.ooderc` should be placed in your home directory with
30
- the following contents:
27
+ configuration file so you don't have to type them in every time.
31
28
 
32
- :user: <username>
33
- :password: <password>
29
+ The following command will create the file `~/.ooderc` that contains
30
+ global options so that you don't have to type them each time.
34
31
 
35
- Either of these can be missed if you would rather enter them yourself
36
- each time.
32
+ `oode -u s0xxxxxx -p passw0rd initconfig`
37
33
 
38
- ## OPTIONS
39
- The following options and flags can be used with `oode`:
34
+ Either of these can be omitted if you would rather enter them yourself
35
+ each time or you can specify them at the command line like above for
36
+ individual commands.
40
37
 
41
- ### Authentication
38
+ ### GLOBAL OPTIONS
42
39
 
43
- * `-u`, `--user`=<USERNAME>:
40
+ * `-u`, `--username`=<USERNAME>:
44
41
  Your DICE username so that `oode` can authenticate.
45
42
 
46
- * `-a`, `--password`=<PASSWORD>:
43
+ * `-p`, `--password`=<PASSWORD>:
47
44
  Your DICE password so that `oode` can authenticate.
48
45
 
49
- ### Miscellaneous
46
+ ## COMMANDS
47
+
48
+ The following options and flags can be used with `oode`:
49
+
50
+ ### Print
50
51
 
51
- * `-p`, `--printer`=<PRINTER>:
52
+ * `-P`, `--printer`=<PRINTER>:
52
53
  Use the printer, <PRINTER>, to print the <FILES>.
53
54
 
54
55
  * `-f`, `--force`:
55
56
  Force `oode` to use a certain printer even if it is not desired.
56
57
 
57
- ### Printing
58
-
59
58
  * `-n`, `--number`=<NUMBER>:
60
59
  Print <NUMBER> copies of the <FILES>.
61
60
 
62
- * `-2`, `--two-up`:
61
+ * `-2`, `--two`:
63
62
  Print the files in the 2-up style.
64
63
 
65
- * `-4`, `--four-up`:
64
+ * `-4`, `--four`:
66
65
  Print the files in the 4-up style.
67
66
 
68
67
  ## BUGS
@@ -75,5 +74,4 @@ Chris Brown :: cb@tardis.ed.ac.uk :: @xoebus
75
74
 
76
75
  ## SEE ALSO
77
76
 
78
- <http://github.com>,
79
- <http://github.com/xoebus/oode>
77
+ <http://github.com>, <http://github.com/xoebus/oode>
@@ -0,0 +1,59 @@
1
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ class OodeFileTest < Test::Unit::TestCase
5
+ def setup
6
+ @user = Oode::User.new('s0812345', 'passw0rd')
7
+
8
+ @file_relative = Oode::File.new('LICENSE', @user)
9
+ @file_absolute = Oode::File.new(File.join(Dir.pwd, 'LICENSE'), @user)
10
+ end
11
+
12
+ def test_relative_path
13
+ assert_equal 'LICENSE', @file_relative.path
14
+ end
15
+
16
+ def test_relative_remote_path
17
+ assert_equal '/home/s0812345/.oode/LICENSE', @file_relative.remote_path
18
+ end
19
+
20
+ def test_relative_extension
21
+ assert_equal '', @file_relative.extension
22
+ end
23
+
24
+ def test_relative_extension_ruby
25
+ file_ruby = Oode::File.new(__FILE__, @user)
26
+ assert_equal 'rb', file_ruby.extension
27
+ end
28
+
29
+ def test_relative_basename
30
+ assert_equal 'LICENSE', @file_relative.basename
31
+ end
32
+
33
+ def test_relative_size
34
+ assert_equal 1054, @file_relative.size
35
+ assert_equal '1.029KB', @file_relative.size.to_human
36
+ end
37
+
38
+ def test_absolute_remote_path
39
+ assert_equal '/home/s0812345/.oode/LICENSE', @file_absolute.remote_path
40
+ end
41
+
42
+ def test_absolute_extension
43
+ assert_equal '', @file_absolute.extension
44
+ end
45
+
46
+ def test_absolute_extension_ruby
47
+ file_ruby = Oode::File.new(File.expand_path(__FILE__), @user)
48
+ assert_equal 'rb', file_ruby.extension
49
+ end
50
+
51
+ def test_absolute_basename
52
+ assert_equal 'LICENSE', @file_absolute.basename
53
+ end
54
+
55
+ def test_absolute_size
56
+ assert_equal 1054, @file_absolute.size
57
+ assert_equal '1.029KB', @file_absolute.size.to_human
58
+ end
59
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ class OodeUserTest < Test::Unit::TestCase
5
+ def setup
6
+ @user = Oode::User.new('s0812345', 'passw0rd')
7
+ end
8
+
9
+ def test_username
10
+ assert_equal 's0812345', @user.username
11
+ end
12
+
13
+ def test_password
14
+ assert_equal 'passw0rd', @user.password
15
+ end
16
+
17
+ def test_homedir
18
+ assert_equal '/home/s0812345', @user.home
19
+ end
20
+ end
@@ -1,9 +1,6 @@
1
- require 'test/unit'
1
+ require 'minitest/unit'
2
2
 
3
- begin
4
- require 'redgreen'
5
- rescue LoadError
6
- end
3
+ begin; require 'turn'; rescue LoadError; end
7
4
 
8
5
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
9
6
  require 'oode'
@@ -19,3 +16,25 @@ class Test::Unit::TestCase
19
16
  assert !haystack.include?(needle)
20
17
  end
21
18
  end
19
+
20
+ # Used for testing private methods
21
+ class Class
22
+ def publicize_methods
23
+ saved_private_instance_methods = self.private_instance_methods
24
+ self.class_eval { public *saved_private_instance_methods }
25
+ yield
26
+ self.class_eval { private *saved_private_instance_methods }
27
+ end
28
+ end
29
+
30
+ # Since tests can't have a usernames and passwords in them we can grab
31
+ # them from the tester's config.
32
+ def config var
33
+ data = ''
34
+ f = File.open(File.expand_path('~/.ooderc'), 'r')
35
+ f.each_line do |line|
36
+ if line =~ /^:#{var}:/
37
+ return line.split(" ")[1]
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ class OodeDownloaderTest < Test::Unit::TestCase
5
+ def setup
6
+ user = Oode::User.new(config('u'), config('p'))
7
+ @downloader = Oode::Downloader.new(user)
8
+ end
9
+
10
+ def test_download_file
11
+ @downloader.download!("/home/#{config 'u'}/.bashrc")
12
+
13
+ expected = @downloader.exec!("sha1sum ~/.bashrc",
14
+ :machine => 'raycroft').split.first
15
+ actual = `shasum ./.bashrc`.split.first
16
+ assert_equal expected, actual
17
+
18
+ `rm ./.bashrc`
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ class OodeSessionTest < Test::Unit::TestCase
5
+ def setup
6
+ user = Oode::User.new(config('u'), config('p'))
7
+ @session = Oode::Session.new(user)
8
+ end
9
+
10
+ def test_exec_machine_default
11
+ expected = 'shackleton.inf.ed.ac.uk'
12
+ actual = @session.exec!("hostname")
13
+ assert_equal expected, actual
14
+ end
15
+
16
+ def test_exec_machine_raycroft
17
+ expected = 'raycroft.inf.ed.ac.uk'
18
+ actual = @session.exec!("hostname", :machine => 'raycroft')
19
+ assert_equal expected, actual
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ class OodeUploaderTest < Test::Unit::TestCase
5
+ def setup
6
+ user = Oode::User.new(config('u'), config('p'))
7
+ @uploader = Oode::Uploader.new(user)
8
+ @file = Oode::File.new(__FILE__, user)
9
+
10
+ @uploader.clean!
11
+ end
12
+
13
+ def test_upload_file
14
+ @uploader.upload!(@file)
15
+
16
+ expected = `shasum #{__FILE__}`.split.first
17
+ actual = @uploader.exec!("sha1sum ~/.oode/#{@file.basename}",
18
+ :machine => 'raycroft').split.first
19
+ assert_equal expected, actual
20
+
21
+ @uploader.clean!
22
+ end
23
+ end
@@ -0,0 +1,255 @@
1
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ class MockSession
5
+ def exec!(command, options = {})
6
+ command
7
+ end
8
+ end
9
+
10
+ PRINTER_WORKING = <<EOS
11
+ lp is ready and printing
12
+ Rank Owner Job Files Total Size
13
+ active cantin 625 scourse.ps 38467 bytes
14
+ 1st cantin 626 history.ps 44529 bytes
15
+ EOS
16
+
17
+ PRINTER_OVERFULL = <<EOS
18
+ lp is ready and printing
19
+ Rank Owner Job Files Total Size
20
+ active cantin 625 scourse.ps 38467 bytes
21
+ 1st cantin 626 history.ps 44529 bytes
22
+ 2nd cantin 627 history.ps 44529 bytes
23
+ 3rd cantin 628 history.ps 44529 bytes
24
+ 4th cantin 629 history.ps 44529 bytes
25
+ 5th cantin 630 history.ps 44529 bytes
26
+ 6th cantin 631 history.ps 44529 bytes
27
+ EOS
28
+
29
+ PRINTER_ON_FIRE = <<EOS
30
+ lp is not ready
31
+ EOS
32
+
33
+ class MockBrokenPrinterSession
34
+ def exec!(command, options = {})
35
+ return PRINTER_ON_FIRE.strip
36
+ end
37
+ end
38
+
39
+ class MockOverfullPrinterSession
40
+ def exec!(command, options = {})
41
+ return PRINTER_OVERFULL.strip
42
+ end
43
+ end
44
+
45
+ class MockWorkingPrinterSession
46
+ def exec!(command, options = {})
47
+ return PRINTER_WORKING.strip
48
+ end
49
+ end
50
+
51
+ class MockLargeFile
52
+ def size
53
+ # HUGE FILE!
54
+ 9999999999
55
+ end
56
+ end
57
+
58
+ class MockSmallFile
59
+ def size
60
+ 1
61
+ end
62
+ end
63
+
64
+ def error message
65
+ puts "ERROR: #{message}".red
66
+ end
67
+
68
+ class OodePrinterTest < Test::Unit::TestCase
69
+ PRINTER_NAME = 'at3'
70
+
71
+ def setup
72
+ user = Oode::User.new('s0812345', 'passw0rd')
73
+ @file = Oode::File.new(__FILE__, user)
74
+ @session = MockSession.new
75
+
76
+ @printer = Oode::Printer.new(PRINTER_NAME, @session)
77
+ end
78
+
79
+ def test_print!
80
+ expected = 'lpr -P at3 /home/s0812345/.oode/oodeprinter_test.rb'
81
+ command = @printer.print!(@file)
82
+ assert_equal expected, command
83
+ end
84
+
85
+ def test_check_size_small
86
+ Oode::Printer.publicize_methods do
87
+ small_file = MockSmallFile.new
88
+ assert @printer.check_size(small_file)
89
+ end
90
+ end
91
+
92
+ def test_check_size_small_io
93
+ Oode::Printer.publicize_methods do
94
+ small_file = MockSmallFile.new
95
+
96
+ out, err = capture_io do
97
+ @printer.check_size(small_file)
98
+ end
99
+
100
+ assert_empty out
101
+ end
102
+ end
103
+
104
+ def test_check_size_large
105
+ Oode::Printer.publicize_methods do
106
+ large_file = MockLargeFile.new
107
+ refute @printer.check_size(large_file)
108
+ end
109
+ end
110
+
111
+ def test_check_size_large_io
112
+ Oode::Printer.publicize_methods do
113
+ large_file = MockLargeFile.new
114
+
115
+ out, err = capture_io do
116
+ @printer.check_size(large_file)
117
+ end
118
+
119
+ assert_match(/big/, out)
120
+ end
121
+ end
122
+
123
+ def test_check_printer_working
124
+ Oode::Printer.publicize_methods do
125
+ session = MockWorkingPrinterSession.new
126
+ working_printer = Oode::Printer.new(PRINTER_NAME, session)
127
+
128
+ assert working_printer.check_working
129
+ end
130
+ end
131
+
132
+ def test_check_printer_working_io
133
+ Oode::Printer.publicize_methods do
134
+ session = MockWorkingPrinterSession.new
135
+ working_printer = Oode::Printer.new(PRINTER_NAME, session)
136
+
137
+ out, err = capture_io do
138
+ working_printer.check_working
139
+ end
140
+
141
+ assert_empty out
142
+ end
143
+ end
144
+
145
+ def test_check_printer_force
146
+ Oode::Printer.publicize_methods do
147
+ session = MockBrokenPrinterSession.new
148
+ force_printer = Oode::Printer.new(PRINTER_NAME, session, :force => true)
149
+
150
+ assert force_printer.check_working
151
+ end
152
+ end
153
+
154
+ def test_check_printer_broken
155
+ Oode::Printer.publicize_methods do
156
+ session = MockBrokenPrinterSession.new
157
+ broken_printer = Oode::Printer.new(PRINTER_NAME, session)
158
+
159
+ refute broken_printer.check_working
160
+ end
161
+ end
162
+
163
+ def test_check_printer_broken_io
164
+ Oode::Printer.publicize_methods do
165
+ session = MockBrokenPrinterSession.new
166
+ broken_printer = Oode::Printer.new(PRINTER_NAME, session)
167
+
168
+ out, err = capture_io do
169
+ broken_printer.check_working
170
+ end
171
+
172
+ assert_match(/isn\'t doing too well/, out)
173
+ end
174
+ end
175
+
176
+ def test_check_printer_overfull
177
+ Oode::Printer.publicize_methods do
178
+ session = MockOverfullPrinterSession.new
179
+ overfull_printer = Oode::Printer.new(PRINTER_NAME, session)
180
+
181
+ refute overfull_printer.check_working
182
+ end
183
+ end
184
+
185
+ def test_check_printer_overfull_io
186
+ Oode::Printer.publicize_methods do
187
+ session = MockOverfullPrinterSession.new
188
+ overfull_printer = Oode::Printer.new(PRINTER_NAME, session)
189
+
190
+ out, err = capture_io do
191
+ overfull_printer.check_working
192
+ end
193
+
194
+ assert_match(/isn\'t doing too well/, out)
195
+ end
196
+ end
197
+
198
+ def test_print_command_default
199
+ Oode::Printer.publicize_methods do
200
+ expected = "lpr -P at3 /home/s0812345/.oode/oodeprinter_test.rb"
201
+ actual = @printer.print_command(@file)
202
+ assert_equal expected, actual
203
+ end
204
+ end
205
+
206
+ def test_print_command_copies
207
+ Oode::Printer.publicize_methods do
208
+ copies_printer = Oode::Printer.new(PRINTER_NAME, @session, :number => 6)
209
+
210
+ expected = "lpr -P at3 -# 6 /home/s0812345/.oode/oodeprinter_test.rb"
211
+ actual = copies_printer.print_command(@file)
212
+ assert_equal expected, actual
213
+ end
214
+ end
215
+
216
+ def test_print_command_two_up
217
+ Oode::Printer.publicize_methods do
218
+ two_printer = Oode::Printer.new(PRINTER_NAME, @session, :format => :two)
219
+
220
+ expected = "lpr -P at3 -Z 2up /home/s0812345/.oode/oodeprinter_test.rb"
221
+ actual = two_printer.print_command(@file)
222
+ assert_equal expected, actual
223
+ end
224
+ end
225
+
226
+ def test_print_command_four_up
227
+ Oode::Printer.publicize_methods do
228
+ four_printer = Oode::Printer.new(PRINTER_NAME, @session, :format => :four)
229
+
230
+ expected = "lpr -P at3 -Z 4up /home/s0812345/.oode/oodeprinter_test.rb"
231
+ actual = four_printer.print_command(@file)
232
+ assert_equal expected, actual
233
+ end
234
+ end
235
+
236
+ def test_print_command_copies_and_two_up
237
+ Oode::Printer.publicize_methods do
238
+ options_printer = Oode::Printer.new(PRINTER_NAME, @session, :number => 3, :format => :two)
239
+
240
+ expected = "lpr -P at3 -# 3 -Z 2up /home/s0812345/.oode/oodeprinter_test.rb"
241
+ actual = options_printer.print_command(@file)
242
+ assert_equal expected, actual
243
+ end
244
+ end
245
+
246
+ def test_print_command_copies_and_four_up
247
+ Oode::Printer.publicize_methods do
248
+ options_printer = Oode::Printer.new(PRINTER_NAME, @session, :number => 3, :format => :four)
249
+
250
+ expected = "lpr -P at3 -# 3 -Z 4up /home/s0812345/.oode/oodeprinter_test.rb"
251
+ actual = options_printer.print_command(@file)
252
+ assert_equal expected, actual
253
+ end
254
+ end
255
+ end