oode 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,69 +1,27 @@
1
- oode
2
- ====
1
+ # oode
3
2
 
4
- *print from a laptop to an AT printer*
3
+ <a href="http://stillmaintained.com/xoebus/oode">
4
+ <img src="http://stillmaintained.com/xoebus/oode.png" />
5
+ </a>
5
6
 
6
- `oode` makes printing to the printers in Appleton Tower much easier from laptops by automating some of the tediousness from the sequence of tasks required.
7
+ `oode` makes working in Appleton Tower with a laptop a little less soul
8
+ destroying.
7
9
 
8
- ## SAMPLE USAGE
10
+ ## Getting Help
11
+ There are a couple of ways to get help for using `oode`.
9
12
 
10
- * `oode -p at3 file.pdf`
11
- * Print `file.pdf` to the printer `at3`.
13
+ 1. If you use `gem man` then there is a man page avaliable.
12
14
 
13
- * `oode -p at13c -4 -n 5 file.pdf`
14
- * Print 5 copies of `file.pdf` to printer `at13c` using the 4-up layout.
15
-
16
- * `oode -p at13c -u s08xxxxx -a passw0rd file.pdf`
17
- * Print `file.pdf` to `at13c` as user `s08xxxxx` authenticating with password `passw0rd`.
15
+ 2. Come on IRC and ask me a question. (I'm **xoebus** on *Freenode* and
16
+ *ImaginaryNet*.
18
17
 
19
- ## CONFIGURATION FILE
18
+ 3. Find me in Appleton Tower!
20
19
 
21
- `oode` can read SSH authentication usernames and passwords from a configuration file so you don't have to type them in every time. A file called `.ooderc` should be placed in your home directory with the following contents:
20
+ ## Bugs
21
+ Report any you find here: <http://github.com/xoebus/oode/issues>
22
22
 
23
- :user: <username>
24
- :password: <password>
23
+ ## Authors
24
+ * Chris Brown ([xoebus](http://github.com/xoebus/))
25
25
 
26
- Either of these can be missed if you would rather enter them yourself each time.
27
-
28
- ## OPTIONS
29
- The following options and flags can be used with `oode`:
30
-
31
- ### Authentication
32
-
33
- * `-u`, `--user`:
34
- Your DICE username so that `oode` can authenticate.
35
-
36
- * `-a`, `--password`:
37
- Your DICE password so that `oode` can authenticate.
38
-
39
- ### Miscellaneous
40
-
41
- * `-p`, `--printer`:
42
- Use the printer, <PRINTER>, to print the <FILES>.
43
-
44
- * `-f`, `--force`:
45
- Force `oode` to use a certain printer even if it is not desired.
46
-
47
- ### Printing
48
-
49
- * `-n`, `--number`:
50
- Print <NUMBER> copies of the <FILES>.
51
-
52
- * `-2`, `--two-up`:
53
- Print the files in the 2-up style.
54
-
55
- * `-4`, `--four-up`:
56
- Print the files in the 4-up style.
57
-
58
- ## BUGS
59
-
60
- <http://github.com/xoebus/oode/issues>
61
-
62
- ## AUTHOR
63
-
64
- Chris Brown :: cb@tardis.ed.ac.uk :: @xoebus
65
-
66
- ## SEE ALSO
67
-
68
- <http://github.com>,
69
- <http://github.com/xoebus/oode>
26
+ ## See Also
27
+ <http://github.com/xoebus>, <http://github.com/xoebus/oode>
data/Rakefile CHANGED
@@ -1,7 +1,16 @@
1
+ require 'rake/testtask'
2
+ require 'metric_fu'
3
+
4
+ MetricFu::Configuration.run do |config|
5
+ config.metrics = [:churn, :flog, :roodi, :flay, :reek]
6
+ config.graphs = [:flog, :flay, :reek]
7
+ end
8
+
9
+ task :default => [:test]
10
+
1
11
  #
2
12
  # Helpers
3
13
  #
4
-
5
14
  def command?(command)
6
15
  `type -t #{command}`
7
16
  $?.success?
@@ -18,16 +27,14 @@ task :check_dirty do
18
27
  end
19
28
  end
20
29
 
21
-
22
30
  #
23
31
  # Tests
24
32
  #
25
-
26
33
  if command? :turn
27
34
  desc "Run tests"
28
35
  task :test do
29
36
  suffix = "-n #{ENV['TEST']}" if ENV['TEST']
30
- sh "turn test/*.rb #{suffix}"
37
+ sh "turn -m test/**/*_test.rb #{suffix}"
31
38
  end
32
39
  else
33
40
  Rake::TestTask.new do |t|
@@ -38,11 +45,9 @@ else
38
45
  end
39
46
  end
40
47
 
41
-
42
48
  #
43
- # Ron
49
+ # Ronn
44
50
  #
45
-
46
51
  if command? :ronn
47
52
  desc "Show the manual"
48
53
  task :man => "man:build" do
@@ -51,15 +56,25 @@ if command? :ronn
51
56
 
52
57
  desc "Build the manual"
53
58
  task "man:build" do
54
- sh "ronn -br5 --organization=XOEBUS --manual='Oode Manual' man/*.ronn"
59
+ sh "ronn -i --date=`date +%Y-%m-%d` --organization=Lolsoft --manual='Oode Manual' -sprint,toc -w man/*.ronn"
55
60
  end
56
61
  end
57
62
 
63
+ desc "Publish to GitHub Pages"
64
+ task :pages => [ "man:build", :check_dirty ] do
65
+ cp "man/oode.1.html", "html"
66
+ sh "git checkout gh-pages"
67
+ sh "mv html index.html"
68
+ sh "git add index.html"
69
+ sh "git commit -m 'update man page'"
70
+ sh "git push origin gh-pages"
71
+ sh "git checkout develop"
72
+ puts :done
73
+ end
58
74
 
59
75
  #
60
- # Gems
76
+ # Gem
61
77
  #
62
-
63
78
  begin
64
79
  require 'mg'
65
80
  MG.new('oode.gemspec')
@@ -68,7 +83,6 @@ rescue LoadError
68
83
  warn "Install it with: gem install mg"
69
84
  end
70
85
 
71
-
72
86
  desc "Push a new version."
73
87
  task :publish => "gem:publish" do
74
88
  require 'oode/version'
data/bin/oode CHANGED
@@ -1,106 +1,109 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "optparse"
4
- require "yaml"
5
-
6
- require "rubygems"
7
- require "net/ssh"
8
- require "net/sftp"
9
- require "highline/import"
10
-
11
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
12
- require "oode"
13
-
14
- options = {}
15
-
16
- begin
17
- config = YAML.load_file(File.expand_path('~/.ooderc'))
18
- rescue
19
- config = { :user => nil, :password => nil}
20
- end
21
-
22
- optparse = OptionParser.new do |opts|
23
- opts.banner = "Usage: oode [options] filename"
24
- opts.program_name = "oode"
25
- opts.version = Oode::Version
26
- options[:options] = {}
27
-
28
- opts.on( "-h", "--help", "Display this screen." ) do
29
- puts opts
30
- exit
31
- end
32
-
33
- opts.separator ""
34
- opts.separator "General"
35
-
36
- options[:printer] = nil
37
- opts.on( "-p", "--printer PRINTER", "The printer to send the file to." ) do |printer|
38
- options[:printer] = printer
39
- end
40
-
41
- opts.on( "-f", "--force", "Force the print job no matter what state the printer is in." ) do |force|
42
- options[:options][:force] = true
43
- end
44
-
45
- opts.separator ""
46
- opts.separator "Authentication"
47
-
48
- options[:user] = config[:user]
49
- opts.on( "-u", "--user USER", "The user to log into DICE with." ) do |user|
50
- options[:user] = user
51
- end
52
-
53
- options[:password] = config[:password]
54
- opts.on( "-a", "--password PASSWORD", "The password to log into DICE with." ) do |password|
55
- options[:password] = password
56
- end
57
-
58
- opts.separator ""
59
- opts.separator "Printing Options"
60
-
61
- opts.on( "-n", "--number COPIES", "The number of copies of FILE you would like to print." ) do |copies|
62
- options[:options][:copies] = copies
3
+ require 'gli'
4
+ require 'gli_version'
5
+ require 'highline/import'
6
+
7
+ $: << File.expand_path(File.join('..', __FILE__, '/../lib'))
8
+ require 'oode'
9
+
10
+ include GLI
11
+
12
+ # Commands that require authentication
13
+ AUTH_COMMANDS = [:print, :push]
14
+
15
+ # Oode Information
16
+ version Oode::VERSION
17
+ config_file '.ooderc'
18
+
19
+ # Global Flags
20
+ desc 'DICE username'
21
+ arg_name 'username'
22
+ flag [:u, :username]
23
+
24
+ desc 'DICE password'
25
+ arg_name 'password'
26
+ flag [:p, :password]
27
+
28
+ # Print Command
29
+ desc 'Print files to DICE printers'
30
+ arg_name '[files]'
31
+ long_desc <<EOS
32
+ This command allows for the printing of local files to any of the
33
+ printers on the DICE network.
34
+ EOS
35
+ command [:print] do |c|
36
+ c.desc 'The printer to send the files to.'
37
+ c.arg_name 'NAME'
38
+ c.flag [:P, :printer]
39
+
40
+ c.desc 'Force the job to print no matter what state the printer is in.'
41
+ c.default_value false
42
+ c.switch [:f, :force]
43
+
44
+ c.desc 'The number of copies of each file yo would like to print.'
45
+ c.arg_name 'COPIES'
46
+ c.default_value 1
47
+ c.flag [:n, :number]
48
+
49
+ c.desc 'Print the document as four pages to a sheet.'
50
+ c.switch ['4', :four]
51
+
52
+ c.desc 'Print the document as two pages to a sheet.'
53
+ c.switch ['2', :two]
54
+
55
+ c.action do |global_options,options,args|
56
+ user = Oode::User.new(global_options[:username], global_options[:password])
57
+ print_session = Oode::Uploader.new(user)
58
+
59
+ config = Hash.new
60
+
61
+ if config[:two]
62
+ config[:format] = :two
63
+ elsif config[:four]
64
+ config[:format] = :four
65
+ end
66
+
67
+ config[:number] = options[:number] if options[:number] != 1
68
+ config[:force] = true if options[:force]
69
+
70
+ error "You must specify a printer." unless options[:printer]
71
+
72
+ printer = Oode::Printer.new(options[:printer], print_session, config)
73
+
74
+ files = Array.new
75
+ args.each do |arg|
76
+ files << Oode::File.new(arg, user)
77
+ end
78
+
79
+ files.each do |file|
80
+ print_session.upload!(file)
81
+ end
82
+
83
+ files.each do |file|
84
+ printer.print!(file)
85
+ end
86
+
87
+ print_session.clean!
63
88
  end
64
-
65
- opts.on( "-4", "--four-up", "Print the document as four pages to a sheet." ) do |opt|
66
- options[:options][:four] = true
67
- end
68
-
69
- opts.on( "-2", "--two-up", "Print the document as two pages to a sheet." ) do |opt|
70
- options[:options][:two] = true
71
- end
72
- end
73
-
74
- optparse.parse!
75
-
76
- if ARGV.empty?
77
- puts optparse.help
78
- exit
79
89
  end
80
90
 
81
- if options[:printer].nil?
82
- error "No printer was specified.\nPlease specify one with the '--printer' or '-p' flags."
83
- end
84
-
85
- if options[:user].nil?
86
- options[:user] = ask("Username: ")
87
- end
88
-
89
- if options[:password].nil?
90
- options[:password] = ask("Password: ") { |q| q.echo = false}
91
- end
92
-
93
- print_queue = Oode::OodeQueue.new options[:user], options[:password], options[:printer], options[:options]
94
-
95
- ARGV.each do |filename|
96
- unless File.directory?(filename)
97
- print_queue.enqueue filename
98
- else
99
- warning "#{filename} is a directory and will not be printed..."
100
- exit
91
+ pre do |global_options,command,options,args|
92
+ if (!command.nil? && AUTH_COMMANDS.include?(command.name))
93
+ # No Username
94
+ if global_options[:username].nil?
95
+ username = ask("Username: ")
96
+ global_options.update({ :u => username, :username => username })
97
+ end
98
+
99
+ # No Password
100
+ if global_options[:password].nil?
101
+ password = ask("Password: ") { |q| q.echo = "*" * rand(3) }
102
+ global_options.update({ :p => password, :password => password })
103
+ end
101
104
  end
105
+
106
+ true
102
107
  end
103
108
 
104
- unless print_queue.empty?
105
- print_queue.print
106
- end
109
+ GLI.run(ARGV)
@@ -1,5 +1,18 @@
1
- require "oode/colour"
2
- require "oode/helper"
3
- require "oode/queue"
4
- require "oode/file"
5
- require "oode/version"
1
+ # Version
2
+ require 'oode/version'
3
+
4
+ # Extension Classes
5
+ require 'oode/ext/ext'
6
+
7
+ # Domain Models
8
+ require 'oode/domain/user'
9
+ require 'oode/domain/file'
10
+
11
+ # Network
12
+ require 'oode/net/session'
13
+ require 'oode/net/transferer'
14
+ require 'oode/net/uploader'
15
+ require 'oode/net/downloader'
16
+
17
+ # Printing
18
+ require 'oode/print/printer'
@@ -0,0 +1,27 @@
1
+ module Oode
2
+ class File
3
+ attr_reader :path
4
+ attr_reader :user
5
+
6
+ def initialize(path, user)
7
+ @path = path
8
+ @user = user
9
+ end
10
+
11
+ def remote_path
12
+ ::File.expand_path(::File.join(@user.home, ".oode", basename))
13
+ end
14
+
15
+ def extension
16
+ ::File.extname(path).split(".")[1].to_s
17
+ end
18
+
19
+ def basename
20
+ ::File.basename(path)
21
+ end
22
+
23
+ def size
24
+ ::File.size(::File.expand_path(path))
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module Oode
2
+ class User
3
+ attr_reader :username
4
+ attr_reader :password
5
+
6
+ def initialize(username, password)
7
+ @username = username
8
+ @password = password
9
+ end
10
+
11
+ def home
12
+ "/home/#{username}"
13
+ end
14
+ end
15
+ end
16
+