ruaur 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ruaur +112 -56
  3. data/lib/ruaur/aur.rb +70 -11
  4. data/lib/ruaur/pacman.rb +12 -4
  5. data/lib/ruaur.rb +17 -0
  6. metadata +11 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a15df6a67e8bbef446044e61a83017126f90651
4
- data.tar.gz: 38d2d1f8168469d5ae8abb3709bb047a4d92f261
3
+ metadata.gz: 48b2b7ed59ee0f2ec9ca9cdad118182873dca783
4
+ data.tar.gz: '083bc6bda5b920f151569330a9b2eb595edc834c'
5
5
  SHA512:
6
- metadata.gz: e3c761ac9b3e76c6e5f54090907f6f15ded67b6dff6e55fee69e709ac67d3c76037e0026e180be41f30d75494e7b92cf5a7287466b1cc05706d8df60b047cb01
7
- data.tar.gz: a31bca9de00135bcadd1bc5bd8a711005c7575078bcc5fdaa65c0fafb8e01d4c009b283c0b9d493743a27961d5ebdcf2d69e8ae2c00a9cdc416d28ea10f809b3
6
+ metadata.gz: 24b8185da260c21f6a6e6e5939f268761193efdb3d7ee6658cc48a1c9a2f5f6f0db5230f54accf13f5d6d7264ec550b73529549b2cd3bfb5096902b20115c203
7
+ data.tar.gz: 51b39ca6b34c8b12ed271bf8b93c959e504793e3d3650cf7396a24c9a6a0eac9703effd752e1981e8b88329b1b00b954f5e3a963e37b1e9a38c0210a7237a5ac
data/bin/ruaur CHANGED
@@ -4,6 +4,27 @@ require "hilighter"
4
4
  require "optparse"
5
5
  require "ruaur"
6
6
 
7
+ class Flags
8
+ # Query
9
+ INFO = 1
10
+
11
+ # Remove
12
+ NOSAVE = 2
13
+
14
+ # Sync
15
+ CLEAN = 3
16
+ NAMES_ONLY = 4
17
+ NOCONFIRM = 5
18
+ SEARCH = 6
19
+ UPGRADE = 7
20
+ end
21
+
22
+ class Operation
23
+ QUERY = 1
24
+ REMOVE = 2
25
+ SYNC = 3
26
+ end
27
+
7
28
  class RuAURExit
8
29
  GOOD = 0
9
30
  INVALID_OPTION = 1
@@ -15,26 +36,12 @@ class RuAURExit
15
36
  AMBIGUOUS_ARGUMENT = 6
16
37
  end
17
38
 
18
- class Operation
19
- REMOVE = 1
20
- SYNC = 2
21
- end
22
-
23
39
  def parse(args)
24
40
  options = Hash.new
41
+ options["flags"] = Array.new
25
42
  options["operation"] = nil
26
43
  options["verbose"] = false
27
44
 
28
- # Sync options
29
- options["clean"] = false
30
- options["names-only"] = false
31
- options["noconfirm"] = false
32
- options["search"] = false
33
- options["upgrade"] = false
34
-
35
- # Remove options
36
- options["nosave"] = false
37
-
38
45
  parser = OptionParser.new do |opts|
39
46
  opts.summary_width = 17
40
47
 
@@ -60,9 +67,24 @@ def parse(args)
60
67
  options["verbose"] = true
61
68
  end
62
69
 
70
+ opts.on("--version", "Show version") do
71
+ __FILE__.match(/ruaur-(\d+\.\d+\.\d+)/) do |m|
72
+ puts m[1]
73
+ end
74
+ exit RuAURExit::GOOD
75
+ end
76
+
63
77
  opts.on("", "OPERATIONS")
64
78
 
65
- opts.on("-R", "--remove", "Remove packages") do
79
+ opts.on("-Q", "--query", "Query the package database") do
80
+ if (options["operation"])
81
+ puts opts
82
+ exit RuAURExit::MULTIPLE_OPERATIONS
83
+ end
84
+ options["operation"] = Operation::QUERY
85
+ end
86
+
87
+ opts.on("-R", "--remove", "Remove package(s)") do
66
88
  if (options["operation"])
67
89
  puts opts
68
90
  exit RuAURExit::MULTIPLE_OPERATIONS
@@ -70,7 +92,7 @@ def parse(args)
70
92
  options["operation"] = Operation::REMOVE
71
93
  end
72
94
 
73
- opts.on("-S", "--sync", "Synchronize packages") do
95
+ opts.on("-S", "--sync", "Synchronize package(s)") do
74
96
  if (options["operation"])
75
97
  puts opts
76
98
  exit RuAURExit::MULTIPLE_OPERATIONS
@@ -78,42 +100,52 @@ def parse(args)
78
100
  options["operation"] = Operation::SYNC
79
101
  end
80
102
 
103
+ opts.on("", "QUERY_OPTIONS")
104
+
105
+ opts.on(
106
+ "-i",
107
+ "--info",
108
+ "Display information for given package(s)"
109
+ ) do
110
+ options["flags"].push(Flags::INFO)
111
+ end
112
+
113
+ opts.on("", "REMOVE_OPTIONS")
114
+
115
+ opts.on("-n", "--nosave", "Completely remove package") do
116
+ options["flags"].push(Flags::NOSAVE)
117
+ end
118
+
81
119
  opts.on("", "SYNC_OPTIONS")
82
120
 
83
121
  opts.on("-c", "--clean", "Remove packages from the cache") do
84
- options["clean"] = true
122
+ options["flags"].push(Flags::CLEAN)
85
123
  end
86
124
 
87
125
  opts.on(
88
126
  "--names-only",
89
127
  "Only show package names (useful for tab-completion)",
90
128
  ) do
91
- options["names-only"] = true
129
+ options["flags"].push(Flags::NAMES_ONLY)
92
130
  end
93
131
 
94
132
  opts.on(
95
133
  "--noconfirm",
96
134
  "Bypass any and all \"Are you sure?\" messages"
97
135
  ) do
98
- options["noconfirm"] = true
136
+ options["flags"].push(Flags::NOCONFIRM)
99
137
  end
100
138
 
101
139
  opts.on(
102
140
  "-s",
103
141
  "--search",
104
- "Search the sync database and AUR for packages"
142
+ "Search the sync database and AUR for package(s)"
105
143
  ) do
106
- options["search"] = true
144
+ options["flags"].push(Flags::SEARCH)
107
145
  end
108
146
 
109
147
  opts.on("-u", "--sysupgrade", "Upgrade all packages") do
110
- options["upgrade"] = true
111
- end
112
-
113
- opts.on("", "REMOVE_OPTIONS")
114
-
115
- opts.on("-n", "--nosave", "Completely remove package") do
116
- options["nosave"] = true
148
+ options["flags"].push(Flags::UPGRADE)
117
149
  end
118
150
  end
119
151
 
@@ -149,34 +181,45 @@ end
149
181
 
150
182
  def validate(options)
151
183
  case options["operation"]
184
+ when Operation::QUERY
185
+ flags = options["flags"].select do |flag|
186
+ flag != Flags::INFO
187
+ end
188
+ return false if (!flags.empty?)
152
189
  when Operation::REMOVE
153
- if (
154
- options["clean"] ||
155
- options["names-only"] ||
156
- options["noconfirm"] ||
157
- options["search"] ||
158
- options["upgrade"]
159
- )
160
- return false
190
+ flags = options["flags"].select do |flag|
191
+ flag != Flags::NOSAVE
161
192
  end
193
+ return false if (!flags.empty?)
162
194
  when Operation::SYNC
163
- return false if (options["nosave"])
195
+ flags = options["flags"].select do |flag|
196
+ (flag != Flags::CLEAN) &&
197
+ (flag != Flags::NAMES_ONLY) &&
198
+ (flag != Flags::NOCONFIRM) &&
199
+ (flag != Flags::SEARCH) &&
200
+ (flag != Flags::UPGRADE)
201
+ end
202
+ return false if (!flags.empty?)
164
203
 
165
- if (options["clean"])
204
+ if (options["flags"].include?(Flags::CLEAN))
166
205
  if (
167
- options["names-only"] ||
168
- options["search"] ||
169
- options["upgrade"]
206
+ options["flags"].include?(Flags::NAMES_ONLY) ||
207
+ options["flags"].include?(Flags::SEARCH) ||
208
+ options["flags"].include?(Flags::UPGRADE)
170
209
  )
171
210
  return false
172
211
  end
173
- elsif (options["search"])
174
- return false if (options["clean"] || options["upgrade"])
175
- elsif (options["upgrade"])
212
+ elsif (options["flags"].include?(Flags::SEARCH))
176
213
  if (
177
- options["clean"] ||
178
- options["names-only"] ||
179
- options["search"]
214
+ options["flags"].include?(Flags::CLEAN) || options["flags"].include?(Flags::UPGRADE)
215
+ )
216
+ return false
217
+ end
218
+ elsif (options["flags"].include?(Flags::UPGRADE))
219
+ if (
220
+ options["flags"].include?(Flags::CLEAN) ||
221
+ options["flags"].include?(Flags::NAMES_ONLY) ||
222
+ options["flags"].include?(Flags::SEARCH)
180
223
  )
181
224
  return false
182
225
  end
@@ -195,20 +238,33 @@ begin
195
238
  ruaur = RuAUR.new(!Hilighter.disable?)
196
239
 
197
240
  case options["operation"]
241
+ when Operation::QUERY
242
+ ruaur.query(
243
+ options["packages"],
244
+ options["flags"].include?(Flags::INFO)
245
+ )
198
246
  when Operation::REMOVE
199
- ruaur.remove(options["packages"], options["nosave"])
247
+ ruaur.remove(
248
+ options["packages"],
249
+ options["flags"].include?(Flags::NOSAVE)
250
+ )
200
251
  when Operation::SYNC
201
- if (options["clean"])
202
- ruaur.clean(options["noconfirm"])
203
- elsif (options["search"])
252
+ if (options["flags"].include?(Flags::CLEAN))
253
+ ruaur.clean(options["flags"].include?(Flags::NOCONFIRM))
254
+ elsif (options["flags"].include?(Flags::SEARCH))
204
255
  puts ruaur.search(
205
256
  options["packages"].join(" "),
206
- options["names-only"]
257
+ options["flags"].include?(Flags::NAMES_ONLY)
258
+ )
259
+ elsif (options["flags"].include?(Flags::UPGRADE))
260
+ ruaur.upgrade(
261
+ options["flags"].include?(Flags::NOCONFIRM)
207
262
  )
208
- elsif (options["upgrade"])
209
- ruaur.upgrade(options["noconfirm"])
210
263
  else
211
- ruaur.install(options["packages"], options["noconfirm"])
264
+ ruaur.install(
265
+ options["packages"],
266
+ options["flags"].include?(Flags::NOCONFIRM)
267
+ )
212
268
  end
213
269
  end
214
270
  rescue Interrupt
data/lib/ruaur/aur.rb CHANGED
@@ -17,6 +17,7 @@ class RuAUR::AUR
17
17
 
18
18
  def compile(package)
19
19
  puts hilight_status("Compiling #{package.name}...")
20
+
20
21
  if (Process.uid == 0)
21
22
  system("chown -R nobody:nobody .")
22
23
  system("su -s /bin/sh nobody -c \"makepkg -sr\"")
@@ -25,8 +26,11 @@ class RuAUR::AUR
25
26
  end
26
27
 
27
28
  compiled = Dir["#{package.name}*.pkg.tar.xz"]
29
+
28
30
  if (compiled.empty?)
29
- raise RuAUR::Error::FailedToCompileError.new(package.name)
31
+ raise RuAUR::Error::FailedToCompileError.new(
32
+ package.name
33
+ )
30
34
  end
31
35
 
32
36
  return compiled
@@ -142,11 +146,19 @@ class RuAUR::AUR
142
146
  end
143
147
  private :hilight_upgrade
144
148
 
145
- def info(package)
146
- return nil if (package.nil? || package.empty?)
149
+ def info(pkg_name)
150
+ return nil if (pkg_name.nil? || pkg_name.empty?)
151
+
152
+ query = "type=info&arg=#{pkg_name}"
153
+ response = Typhoeus.get("#{@rpc_url}?#{query}", timeout: 5)
147
154
 
148
- query = "type=info&arg=#{package}"
149
- body = JSON.parse(Typhoeus.get("#{@rpc_url}?#{query}").body)
155
+ if (response.timed_out?)
156
+ raise RuAUR::Error::AURError.new(
157
+ "Check your internet connection!"
158
+ )
159
+ end
160
+
161
+ body = JSON.parse(response.body)
150
162
 
151
163
  if (body["type"] == "error")
152
164
  raise RuAUR::Error::AURError.new(body["results"])
@@ -167,7 +179,6 @@ class RuAUR::AUR
167
179
 
168
180
  def install(pkg_name, noconfirm = false)
169
181
  package = info(pkg_name)
170
-
171
182
  if (package.nil?)
172
183
  raise RuAUR::Error::PackageNotFoundError.new(pkg_name)
173
184
  end
@@ -184,6 +195,7 @@ class RuAUR::AUR
184
195
  download(package)
185
196
  extract(package)
186
197
  end
198
+
187
199
  Dir.chdir("#{@cache}/#{package.name}") do
188
200
  return if (edit_pkgbuild(package, noconfirm))
189
201
  install_dependencies(package, noconfirm)
@@ -196,7 +208,6 @@ class RuAUR::AUR
196
208
 
197
209
  def install_dependencies(package, noconfirm)
198
210
  pkgbuild = File.read("PKGBUILD")
199
-
200
211
  pkgbuild.match(/^depends\=\(([^\)]+)\)/m) do |match|
201
212
  match.captures.each do |cap|
202
213
  cap.gsub(/\n/, " ").scan(/[^' ]+/) do |scan|
@@ -223,11 +234,19 @@ class RuAUR::AUR
223
234
  private :install_dependencies
224
235
 
225
236
  def multiinfo(pkgs)
226
- results = Array.new
227
- return results if (pkgs.nil? || pkgs.empty?)
237
+ return Array.new if (pkgs.nil? || pkgs.empty?)
228
238
 
239
+ results = Array.new
229
240
  query = "type=multiinfo&arg[]=#{pkgs.join("&arg[]=")}"
230
- body = JSON.parse(Typhoeus.get("#{@rpc_url}?#{query}").body)
241
+ response = Typhoeus.get("#{@rpc_url}?#{query}", timeout: 5)
242
+
243
+ if (response.timed_out?)
244
+ raise RuAUR::Error::AURError.new(
245
+ "Check your internet connection!"
246
+ )
247
+ end
248
+
249
+ body = JSON.parse(response.body)
231
250
 
232
251
  if (body["type"] == "error")
233
252
  raise RuAUR::Error::AURError.new(body["results"])
@@ -236,15 +255,51 @@ class RuAUR::AUR
236
255
  body["results"].each do |result|
237
256
  results.push(RuAUR::Package.new(result, "aur"))
238
257
  end
258
+
239
259
  return results.sort
240
260
  end
241
261
 
262
+ def query(pkg_name, info = false)
263
+ package = info(pkg_name)
264
+ return Hash.new if (package.nil?)
265
+
266
+ results = Hash.new
267
+ json = package.json
268
+
269
+ if (!json.empty?)
270
+ results[pkg_name] = json["Version"]
271
+ if (info)
272
+ max = 0
273
+ json.each do |k, v|
274
+ max = k.length if (max < k.length)
275
+ end
276
+
277
+ out = Array.new
278
+ json.each do |k, v|
279
+ filler = Array.new(max - k.length + 2, " ").join
280
+ out.push("#{k}#{filler}: #{v}")
281
+ end
282
+ results[pkg_name] = out.join("\n")
283
+ end
284
+ end
285
+
286
+ return results
287
+ end
288
+
242
289
  def search(string)
243
290
  results = Array.new
244
291
  return results if (string.nil? || string.empty?)
245
292
 
246
293
  query = "type=search&arg=#{string}"
247
- body = JSON.parse(Typhoeus.get("#{@rpc_url}?#{query}").body)
294
+ response = Typhoeus.get("#{@rpc_url}?#{query}", timeout: 5)
295
+
296
+ if (response.timed_out?)
297
+ raise RuAUR::Error::AURError.new(
298
+ "Check your internet connection!"
299
+ )
300
+ end
301
+
302
+ body = JSON.parse(response.body)
248
303
 
249
304
  if (body["type"] == "error")
250
305
  raise RuAUR::Error::AURError.new(body["results"])
@@ -269,17 +324,21 @@ class RuAUR::AUR
269
324
 
270
325
  tgz = File.open(file, "wb")
271
326
  request = Typhoeus::Request.new(url)
327
+
272
328
  request.on_headers do |response|
273
329
  if (response.code != 200)
274
330
  raise RuAUR::Error::FailedToDownloadError.new(name)
275
331
  end
276
332
  end
333
+
277
334
  request.on_body do |chunk|
278
335
  tgz.write(chunk)
279
336
  end
337
+
280
338
  request.on_complete do
281
339
  tgz.close
282
340
  end
341
+
283
342
  request.run
284
343
  end
285
344
  private :tarball
data/lib/ruaur/pacman.rb CHANGED
@@ -64,11 +64,19 @@ class RuAUR::Pacman
64
64
  end
65
65
  end
66
66
 
67
- def query(pkg_name = "")
67
+ def query(pkg_name = "", info = false)
68
68
  results = Hash.new
69
- %x(#{@pac_nocolor} -Q #{pkg_name}).split("\n").each do |line|
70
- line = line.split
71
- results[line[0]] = line[1]
69
+ if (info)
70
+ result = %x(#{@pac_nocolor} -Qi #{pkg_name} 2>/dev/null)
71
+ result.strip!
72
+ results[pkg_name] = result if (!result.empty?)
73
+ else
74
+ result = %x(#{@pac_nocolor} -Q #{pkg_name} 2>/dev/null)
75
+ result.strip!
76
+ result.split("\n").each do |l|
77
+ name, version = l.split
78
+ results[name] = version
79
+ end
72
80
  end
73
81
  return results
74
82
  end
data/lib/ruaur.rb CHANGED
@@ -57,6 +57,23 @@ class RuAUR
57
57
  unlock
58
58
  end
59
59
 
60
+ def query(pkg_names, info = false)
61
+ pkg_names.each do |pkg_name|
62
+ results = @pacman.query(pkg_name, info)
63
+ results.each do |name, details|
64
+ print "#{name} " if (!info)
65
+ puts details
66
+ puts if (info)
67
+ end
68
+ results = @aur.query(pkg_name, info)
69
+ results.each do |name, details|
70
+ print "#{name} " if (!info)
71
+ puts details
72
+ puts if (info)
73
+ end
74
+ end
75
+ end
76
+
60
77
  def remove(pkg_names, nosave = false)
61
78
  check_and_lock
62
79
  @pacman.remove(pkg_names, nosave)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruaur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Whittaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-04 00:00:00.000000000 Z
11
+ date: 2017-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '10.5'
19
+ version: '12.1'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 10.5.0
22
+ version: 12.1.0
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '10.5'
29
+ version: '12.1'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 10.5.0
32
+ version: 12.1.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: hilighter
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -96,20 +96,20 @@ dependencies:
96
96
  requirements:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: '1.0'
99
+ version: '1.3'
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 1.0.1
102
+ version: 1.3.0
103
103
  type: :runtime
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '1.0'
109
+ version: '1.3'
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: 1.0.1
112
+ version: 1.3.0
113
113
  description: RuAUR is a Ruby gem that allows searching and installing packages from
114
114
  the Pacman sync database as well as the Arch User Repository (AUR).
115
115
  email: mjwhitta@gmail.com
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  requirements: []
154
154
  rubyforge_project:
155
- rubygems_version: 2.4.5.1
155
+ rubygems_version: 2.6.13
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Can search and install packages for Arch Linux