Sutto-SABnzbd 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/SABnzbd.gemspec +1 -1
- data/VERSION.yml +2 -2
- data/lib/sabnzbd.rb +60 -0
- metadata +1 -1
data/SABnzbd.gemspec
CHANGED
data/VERSION.yml
CHANGED
data/lib/sabnzbd.rb
CHANGED
@@ -121,4 +121,64 @@ class SABnzbd
|
|
121
121
|
Status.jobs_from(status)
|
122
122
|
end
|
123
123
|
|
124
|
+
class << self
|
125
|
+
|
126
|
+
@@settings_path = File.expand_path("~/.sabnzbd/sabnzbd.ini")
|
127
|
+
|
128
|
+
def settings_path
|
129
|
+
@@settings_path
|
130
|
+
end
|
131
|
+
|
132
|
+
def settings_path=(value)
|
133
|
+
@@settings_path = value
|
134
|
+
end
|
135
|
+
|
136
|
+
def settings
|
137
|
+
self.parse_ini(File.read(self.settings_path))
|
138
|
+
end
|
139
|
+
|
140
|
+
def local
|
141
|
+
s = self.settings
|
142
|
+
base_uri "#{s["misc"]["host"]}:#{s["misc"]["port"]}"
|
143
|
+
self.new(s["misc"]["username"], s["misc"]["password"])
|
144
|
+
end
|
145
|
+
|
146
|
+
protected
|
147
|
+
|
148
|
+
def parse_ini(text)
|
149
|
+
options = {}
|
150
|
+
keys = []
|
151
|
+
text.each_line do |line|
|
152
|
+
if line =~ /^(\[+([^\[\]]+)\]+)$/
|
153
|
+
normal, name = $1, $2
|
154
|
+
start = line.match(/^\[+/)[0]
|
155
|
+
depth = start.length
|
156
|
+
if depth == 1
|
157
|
+
keys = []
|
158
|
+
elsif depth <= keys.size
|
159
|
+
width = (depth - 2)
|
160
|
+
width = 0 if width < 0
|
161
|
+
keys = keys[0..width]
|
162
|
+
end
|
163
|
+
keys << name
|
164
|
+
set_value options, keys, {}
|
165
|
+
elsif line =~ /^(.*)=(.*)$/
|
166
|
+
key, value = $1.strip, $2.strip
|
167
|
+
set_value options, (keys + [key]), value
|
168
|
+
end
|
169
|
+
end
|
170
|
+
return options
|
171
|
+
end
|
172
|
+
|
173
|
+
def set_value(options, keys, value)
|
174
|
+
r = options
|
175
|
+
keys[0..-2].each do |k|
|
176
|
+
r = (r[k] ||= {})
|
177
|
+
end
|
178
|
+
r[keys.last] = value
|
179
|
+
return options
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
124
184
|
end
|