brewer 0.0.91 β 0.0.93
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/brewer +0 -1
- data/lib/brewer/adaptibrew.rb +22 -23
- data/lib/brewer/brewer.rb +7 -7
- data/lib/brewer/recipe.rb +10 -1
- data/lib/brewer/settings.rb +16 -19
- data/lib/brewer/slacker.rb +0 -0
- data/spec/adaptibrew_spec.rb +51 -42
- data/spec/hardware_spec.rb +12 -12
- data/spec/spec_helper.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c755e13a364fc36a15b6b6bf8322eb659a0e989
|
4
|
+
data.tar.gz: 0cd30f9c517ba49a9c1df3fd85dc56d20274237b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1faa193fad4f23676479df686d0116df05197a8fd5bb22232ffbcc3dd937068e5ed7f0125913c28b2ef9e4540236037cb20a800e78dd642f5f8f7e173a321087
|
7
|
+
data.tar.gz: 7a2d2de0a3b03a981f2569958c505be5313c5312f51492252a9f52eb4c92766caa0397a864ad47dc43648fea6d5a0733d37234d3518289c35ac35c858c55b637
|
data/bin/brewer
CHANGED
data/lib/brewer/adaptibrew.rb
CHANGED
@@ -3,50 +3,49 @@ require_relative "helpers.rb"
|
|
3
3
|
include Helpers
|
4
4
|
|
5
5
|
module Brewer
|
6
|
-
# This class handles the adaptibrew repo
|
7
|
-
# It is stored in ~/.brewer/adaptibrew/
|
8
6
|
class Adaptibrew
|
9
7
|
|
8
|
+
attr_accessor :disable_network_operations
|
9
|
+
|
10
10
|
def initialize
|
11
|
+
@disable_network_operations = network? ? false : true
|
12
|
+
@adaptibrew_url = 'https://github.com/llamicron/adaptibrew.git'
|
13
|
+
|
11
14
|
if !Dir.exists?(adaptibrew_dir)
|
12
15
|
Dir.mkdir(adaptibrew_dir)
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
# This will clone adaptibrew into ~/.brewer/adaptibrew/
|
17
19
|
def clone
|
18
|
-
|
20
|
+
if @disable_network_operations
|
21
|
+
return false
|
22
|
+
end
|
19
23
|
|
20
24
|
if !Dir.exists?(adaptibrew_dir)
|
21
|
-
Git.clone(
|
25
|
+
Git.clone(@adaptibrew_url, 'adaptibrew', :path => brewer_dir)
|
26
|
+
return true
|
22
27
|
end
|
23
|
-
|
24
|
-
self
|
28
|
+
false
|
25
29
|
end
|
26
30
|
|
27
|
-
# Danger zone...
|
28
|
-
# This deletes adaptibrew
|
29
31
|
def clear
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
if @disable_network_operations
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
if present?
|
36
|
+
FileUtils.rm_rf(adaptibrew_dir)
|
37
|
+
return true
|
34
38
|
end
|
35
|
-
|
36
|
-
FileUtils.rm_rf(adaptibrew_dir)
|
37
|
-
self
|
39
|
+
false
|
38
40
|
end
|
39
41
|
|
40
|
-
# This is a good catch-all method
|
41
|
-
# This deletes and re-clones adaptibrew
|
42
42
|
def refresh
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
if clear and clone
|
44
|
+
return true
|
45
|
+
end
|
46
|
+
false
|
47
47
|
end
|
48
48
|
|
49
|
-
# Returns true if adaptibrew is present
|
50
49
|
def present?
|
51
50
|
return Dir.exists?(adaptibrew_dir) ? true : false
|
52
51
|
end
|
data/lib/brewer/brewer.rb
CHANGED
@@ -36,7 +36,7 @@ module Brewer
|
|
36
36
|
# Turning the pump off will turn the pid off too, as it should not be on when the pump is off
|
37
37
|
def pump(state="status")
|
38
38
|
if state == "status"
|
39
|
-
return relay_status($settings['
|
39
|
+
return relay_status($settings['pump'])
|
40
40
|
end
|
41
41
|
|
42
42
|
if state == 1
|
@@ -150,7 +150,7 @@ module Brewer
|
|
150
150
|
statuses = {}
|
151
151
|
all_relays_status.shift(4).each do |status|
|
152
152
|
relay_num, status = status.match(/relay [0-9+]([0-9]+): (on|off)/).captures
|
153
|
-
relay_names = $settings.select { |key, value| key.to_s.match(/
|
153
|
+
relay_names = $settings.select { |key, value| key.to_s.match(/hlt|rims[^A]|pump/) }
|
154
154
|
statuses[relay_names.key(relay_num.to_i)] = status
|
155
155
|
end
|
156
156
|
statuses
|
@@ -173,9 +173,9 @@ module Brewer
|
|
173
173
|
def rims_to(location)
|
174
174
|
if location == "mash"
|
175
175
|
# we ended up swapping this relay, so the name is backwards
|
176
|
-
relay($settings['
|
176
|
+
relay($settings['rimsToMash'], 0)
|
177
177
|
elsif location == "boil"
|
178
|
-
relay($settings['
|
178
|
+
relay($settings['rimsToMash'], 1)
|
179
179
|
else
|
180
180
|
raise "Not a valid location for rims valve"
|
181
181
|
end
|
@@ -185,9 +185,9 @@ module Brewer
|
|
185
185
|
# Diverts hlt valve to mash or boil tun
|
186
186
|
def hlt_to(location)
|
187
187
|
if location == "mash"
|
188
|
-
relay($settings['
|
188
|
+
relay($settings['hltToMash'], 0)
|
189
189
|
elsif location == "boil"
|
190
|
-
relay($settings['
|
190
|
+
relay($settings['hltToMash'], 1)
|
191
191
|
else
|
192
192
|
raise "Not a valid location for the hlt valve"
|
193
193
|
end
|
@@ -196,7 +196,7 @@ module Brewer
|
|
196
196
|
|
197
197
|
# Opens or closes hlt valve
|
198
198
|
def hlt(state)
|
199
|
-
relay($settings['
|
199
|
+
relay($settings['hlt'], state)
|
200
200
|
self
|
201
201
|
end
|
202
202
|
|
data/lib/brewer/recipe.rb
CHANGED
@@ -31,7 +31,10 @@ module Brewer
|
|
31
31
|
return true
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
clear_screen
|
35
|
+
puts "Enter a recipe name to load an existing recipe, or nothing to start a new one."
|
36
|
+
puts list_as_table
|
37
|
+
print "> "
|
35
38
|
name = gets.chomp.strip
|
36
39
|
|
37
40
|
unless name.empty?
|
@@ -123,6 +126,12 @@ module Brewer
|
|
123
126
|
recipes
|
124
127
|
end
|
125
128
|
|
129
|
+
def list_as_table
|
130
|
+
recipes_table_rows = list_recipes.each_slice(5).to_a
|
131
|
+
recipes_table = Terminal::Table.new :title => "All Recipes", :rows => recipes_table_rows
|
132
|
+
return recipes_table
|
133
|
+
end
|
134
|
+
|
126
135
|
def loaded_recipe?
|
127
136
|
if File.exists?(recipe_dir(@vars['name']) + ".yml")
|
128
137
|
return true
|
data/lib/brewer/settings.rb
CHANGED
@@ -8,7 +8,7 @@ module Brewer
|
|
8
8
|
|
9
9
|
def initialize(testing=false)
|
10
10
|
|
11
|
-
@source = adaptibrew_dir('
|
11
|
+
@source = adaptibrew_dir('print_settings.py')
|
12
12
|
@cache_file = brewer_dir('settings.yml')
|
13
13
|
|
14
14
|
@settings = Hash.new
|
@@ -51,19 +51,15 @@ module Brewer
|
|
51
51
|
false
|
52
52
|
end
|
53
53
|
|
54
|
-
# Parse the settings from
|
54
|
+
# Parse the settings from @source into @settings
|
55
55
|
def parse
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
63
|
-
type_cast
|
64
|
-
return true
|
56
|
+
settings_file_output = `python #{@source}`.chomp
|
57
|
+
settings_array = settings_file_output.split("\n")
|
58
|
+
settings_array.each do |setting|
|
59
|
+
key, value = setting.match(/(.+)=(.+)/).captures
|
60
|
+
@settings[key.strip.chomp] = value.strip.chomp
|
65
61
|
end
|
66
|
-
|
62
|
+
true
|
67
63
|
end
|
68
64
|
|
69
65
|
# Creates the cache if there isn't one already
|
@@ -108,6 +104,7 @@ module Brewer
|
|
108
104
|
# and for backwards compatability purposes
|
109
105
|
def load_global
|
110
106
|
raise "settings instance variable does not exist yet. Run Settings#parse first" unless !@settings.empty?
|
107
|
+
type_cast
|
111
108
|
$settings = @settings
|
112
109
|
end
|
113
110
|
|
@@ -123,14 +120,14 @@ module Brewer
|
|
123
120
|
def type_cast
|
124
121
|
# Super janky
|
125
122
|
change({
|
126
|
-
'
|
127
|
-
'
|
128
|
-
'
|
123
|
+
'rimsAddress' => @settings['rimsAddress'].to_i,
|
124
|
+
'switchAddress' => @settings['switchAddress'].to_i,
|
125
|
+
'baudRate' => @settings['baudRate'].to_i,
|
129
126
|
'timeout' => @settings['timeout'].to_i,
|
130
|
-
'
|
131
|
-
'
|
132
|
-
'
|
133
|
-
'
|
127
|
+
'hltToMash' => @settings['hltToMash'].to_i,
|
128
|
+
'hlt' => @settings['hlt'].to_i,
|
129
|
+
'rimsToMash' => @settings['rimsToMash'].to_i,
|
130
|
+
'pump' => @settings['pump'].to_i,
|
134
131
|
'DEBUG' => @settings['DEBUG'].to_b,
|
135
132
|
})
|
136
133
|
end
|
data/lib/brewer/slacker.rb
CHANGED
File without changes
|
data/spec/adaptibrew_spec.rb
CHANGED
@@ -1,89 +1,98 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
include Helpers
|
4
|
+
|
5
|
+
describe Brewer::Adaptibrew do
|
4
6
|
|
5
7
|
before :each do
|
6
|
-
@adaptibrew = Adaptibrew.new
|
8
|
+
@adaptibrew = Adaptibrew.new
|
9
|
+
@adaptibrew.refresh
|
10
|
+
end
|
11
|
+
|
12
|
+
after :all do
|
13
|
+
Adaptibrew.new.clone
|
7
14
|
end
|
8
15
|
|
9
16
|
describe "#new" do
|
10
|
-
|
17
|
+
it "makes a new Adaptibrew object" do
|
18
|
+
expect(Adaptibrew.new).to be_an_instance_of Adaptibrew
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
22
|
describe ".clear" do
|
14
23
|
context "when the repo exists" do
|
15
|
-
|
16
|
-
specify { expect(adaptibrew.present?).to be true }
|
17
|
-
|
18
|
-
|
19
|
-
@adaptibrew.clear
|
24
|
+
before { @adaptibrew.clone }
|
25
|
+
specify { expect(@adaptibrew.present?).to be true }
|
26
|
+
it "deletes the repo and returns true" do
|
27
|
+
expect(@adaptibrew.clear).to be true
|
20
28
|
expect(@adaptibrew.present?).to be false
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
24
32
|
context "when the repo does not exist" do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
it "does nothing" do
|
30
|
-
@adaptibrew.clear
|
33
|
+
before { @adaptibrew.clear }
|
34
|
+
specify { expect(@adaptibrew.present?).to be false }
|
35
|
+
it "does nothing and returns false" do
|
36
|
+
expect(@adaptibrew.clear).to be false
|
31
37
|
expect(@adaptibrew.present?).to be false
|
32
38
|
end
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
42
|
describe ".clone" do
|
37
|
-
context "when the repo
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
it "clones the repo" do
|
43
|
-
@adaptibrew.clone
|
43
|
+
context "when the repo exists" do
|
44
|
+
before { @adaptibrew.clone }
|
45
|
+
it "does nothing and returns false" do
|
46
|
+
expect(@adaptibrew.clone).to be false
|
44
47
|
expect(@adaptibrew.present?).to be true
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
|
-
context "when the repo
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
it "does nothing" do
|
54
|
-
@adaptibrew.clone
|
51
|
+
context "when the repo does not exist" do
|
52
|
+
before { @adaptibrew.clear }
|
53
|
+
it "clones it and returns true" do
|
54
|
+
expect(@adaptibrew.clone).to be true
|
55
55
|
expect(@adaptibrew.present?).to be true
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
context "when network operations are disabled" do
|
60
|
+
# Clearing it here so that @adaptibrew.clone would otherwise return true
|
61
|
+
before { @adaptibrew.clear}
|
62
|
+
before { @adaptibrew.disable_network_operations = true}
|
63
|
+
it "does nothing and returns false" do
|
64
|
+
expect(@adaptibrew.clone).to be false
|
65
|
+
end
|
66
|
+
after { @adaptibrew.disable_network_operations = false}
|
67
|
+
end
|
58
68
|
end
|
59
69
|
|
60
70
|
describe ".refresh" do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@adaptibrew.
|
67
|
-
expect(@adaptibrew.present?).to be true
|
71
|
+
context "when network operations are disabled" do
|
72
|
+
before { @adaptibrew.disable_network_operations = true}
|
73
|
+
it "does nothing and returns false" do
|
74
|
+
expect(@adaptibrew.refresh).to be false
|
75
|
+
end
|
76
|
+
after { @adaptibrew.disable_network_operations = false}
|
68
77
|
end
|
69
78
|
|
79
|
+
it "clears and clones the repo then returns true" do
|
80
|
+
expect(@adaptibrew.refresh).to be true
|
81
|
+
end
|
70
82
|
end
|
71
83
|
|
72
84
|
describe ".present?" do
|
73
85
|
context "when the exists" do
|
74
|
-
|
75
|
-
|
76
|
-
specify { expect(Dir.exists?(Dir.home + '/.brewer/adaptibrew')).to be true }
|
77
|
-
|
86
|
+
before { @adaptibrew.clone }
|
87
|
+
specify { expect(Dir.exists?(adaptibrew_dir)).to be true }
|
78
88
|
it "returns true" do
|
79
89
|
expect(@adaptibrew.present?).to be true
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
83
93
|
context "when the repo does not exist" do
|
84
|
-
|
85
|
-
|
86
|
-
specify { expect(Dir.exists?('adaptibrew')).to be false }
|
94
|
+
before { @adaptibrew.clear }
|
95
|
+
specify { expect(Dir.exists?(adaptibrew_dir)).to be false }
|
87
96
|
it "returns false" do
|
88
97
|
expect(@adaptibrew.present?).to be false
|
89
98
|
end
|
data/spec/hardware_spec.rb
CHANGED
@@ -92,10 +92,10 @@ describe Brewer do
|
|
92
92
|
|
93
93
|
describe ".relay_status" do
|
94
94
|
it "returns the status of a relay" do
|
95
|
-
@brewer.relay($settings['
|
96
|
-
expect(@brewer.relay_status($settings['
|
97
|
-
@brewer.relay($settings['
|
98
|
-
expect(@brewer.relay_status($settings['
|
95
|
+
@brewer.relay($settings['rimsToMash'], 1)
|
96
|
+
expect(@brewer.relay_status($settings['rimsToMash'].to_i)).to eq("on")
|
97
|
+
@brewer.relay($settings['rimsToMash'], 0)
|
98
|
+
expect(@brewer.relay_status($settings['rimsToMash'].to_i)).to eq("off")
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -104,7 +104,7 @@ describe Brewer do
|
|
104
104
|
statuses = @brewer.relays_status
|
105
105
|
expect(statuses).to be_an_instance_of Hash
|
106
106
|
expect(statuses).to_not be_empty
|
107
|
-
expect(statuses['
|
107
|
+
expect(statuses['hlt']).to be_an_instance_of String
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -120,25 +120,25 @@ describe Brewer do
|
|
120
120
|
'hlt' => 1,
|
121
121
|
'pump' => 0,
|
122
122
|
})
|
123
|
-
expect(@brewer.relay_status($settings['
|
123
|
+
expect(@brewer.relay_status($settings['hlt'])).to eq("on")
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
describe ".hlt" do
|
128
128
|
it "opens or closes the hlt valve" do
|
129
129
|
@brewer.hlt(0)
|
130
|
-
expect(@brewer.relay_status($settings['
|
130
|
+
expect(@brewer.relay_status($settings['hlt'])).to eq("off")
|
131
131
|
@brewer.hlt(1)
|
132
|
-
expect(@brewer.relay_status($settings['
|
132
|
+
expect(@brewer.relay_status($settings['hlt'])).to eq("on")
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
136
|
describe ".rims_to" do
|
137
137
|
it "diverts the rims relay to boil or mash tuns" do
|
138
138
|
@brewer.rims_to("boil")
|
139
|
-
expect(@brewer.relay_status($settings['
|
139
|
+
expect(@brewer.relay_status($settings['rimsToMash'])).to eq("on")
|
140
140
|
@brewer.rims_to("mash")
|
141
|
-
expect(@brewer.relay_status($settings['
|
141
|
+
expect(@brewer.relay_status($settings['rimsToMash'])).to eq("off")
|
142
142
|
end
|
143
143
|
|
144
144
|
context "when the location is not valid" do
|
@@ -151,9 +151,9 @@ describe Brewer do
|
|
151
151
|
describe ".hlt_to" do
|
152
152
|
it "diverts the hlt relay to boil or mash tuns" do
|
153
153
|
@brewer.hlt_to("boil")
|
154
|
-
expect(@brewer.relay_status($settings['
|
154
|
+
expect(@brewer.relay_status($settings['hltToMash'])).to eq("on")
|
155
155
|
@brewer.hlt_to("mash")
|
156
|
-
expect(@brewer.relay_status($settings['
|
156
|
+
expect(@brewer.relay_status($settings['hltToMash'])).to eq("off")
|
157
157
|
end
|
158
158
|
|
159
159
|
context "when the location is not valid" do
|
data/spec/spec_helper.rb
CHANGED