Module: CommonStuff
- Defined in:
- lib/common_stuff.rb
Constant Summary collapse
- @@config_file =
File.join(Dir.home, "printsly.json")
- @@prov_log =
"/var/log/cups/provision_log"
Instance Method Summary collapse
- #choose_file ⇒ Object
- #fill_hash(work_dir, batchy, auto_mater) ⇒ Object
- #load_config ⇒ Object
- #log_entry(printerdata, status) ⇒ Object
- #log_entry_data_fail(printerdata) ⇒ Object
- #log_entry_data_woot(printerdata) ⇒ Object
- #log_entry_write(printerdata, status) ⇒ Object
- #log_file ⇒ Object
- #mod_name(namey, store) ⇒ Object
- #prompt ⇒ Object
- #save_config(cur_conf) ⇒ Object
- #yes_no ⇒ Object
Instance Method Details
#choose_file ⇒ Object
53 54 55 56 57 |
# File 'lib/common_stuff.rb', line 53 def choose_file puts #formatting puts "Please enter the full path to the spreadsheet(s):" prompt; gets.chomp end |
#fill_hash(work_dir, batchy, auto_mater) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/common_stuff.rb', line 59 def fill_hash work_dir, batchy, auto_mater cur_conf = Hash.new cur_conf[:work_dir] = work_dir cur_conf[:batchy] = batchy cur_conf[:auto_mater] = auto_mater cur_conf end |
#load_config ⇒ Object
67 68 69 70 71 |
# File 'lib/common_stuff.rb', line 67 def load_config file_conf = JSON.parse(File.read(@@config_file)) cur_conf = fill_hash(file_conf['work_dir'], file_conf['batchy'], file_conf['auto_mater']) cur_conf end |
#log_entry(printerdata, status) ⇒ Object
12 13 14 15 16 |
# File 'lib/common_stuff.rb', line 12 def log_entry printerdata, status if File.exists?(@@prov_log) log_entry_write(printerdata, status) end end |
#log_entry_data_fail(printerdata) ⇒ Object
30 31 32 33 |
# File 'lib/common_stuff.rb', line 30 def log_entry_data_fail printerdata timey = Time.new "FAILED: " + timey.inspect + " " + printerdata[0] + " " + printerdata[2] + " IP: " + printerdata[1] end |
#log_entry_data_woot(printerdata) ⇒ Object
25 26 27 28 |
# File 'lib/common_stuff.rb', line 25 def log_entry_data_woot printerdata timey = Time.new "Add: " + timey.inspect + " " + printerdata[0] + " " + printerdata[2] + " IP: " + printerdata[1] end |
#log_entry_write(printerdata, status) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/common_stuff.rb', line 18 def log_entry_write printerdata, status File.open(@@prov_log, "a") do |f| f.puts log_entry_data_woot(printerdata) if status == 0 f.puts log_entry_data_fail(printerdata) if status == 1 end end |
#log_file ⇒ Object
6 7 8 9 10 |
# File 'lib/common_stuff.rb', line 6 def log_file if Dir.exists?("/var/log/cups") File.new(@@prov_log, "w+") unless File.exists?(@@prov_log) end end |
#mod_name(namey, store) ⇒ Object
35 36 37 38 |
# File 'lib/common_stuff.rb', line 35 def mod_name namey, store namey = "0" + store + namey if namey.include?('RT') || namey.include?('SIM') namey end |
#prompt ⇒ Object
40 41 42 |
# File 'lib/common_stuff.rb', line 40 def prompt print ">> " end |
#save_config(cur_conf) ⇒ Object
73 74 75 76 77 |
# File 'lib/common_stuff.rb', line 73 def save_config(cur_conf) File.open(@@config_file, "w") do |f| f.write(cur_conf.to_json) end end |
#yes_no ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/common_stuff.rb', line 44 def yes_no #restrict input to valid answers, but don't worry about case begin puts "Please enter " + "[yes]".yellow + " or " + "[no]".yellow + ":" prompt; @yes_no = STDIN.gets.chomp.downcase end while not (@yes_no == "yes" or @yes_no == "no") @yes_no end |