ruaur 0.3.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f53abf0e780651b0812a01891e932a1d838d8405816c517e639eacb7fde261b7
4
- data.tar.gz: 7e9fac6807b77aa3a452913decfa70e839349e740899d74c00e72325efb1ab4c
3
+ metadata.gz: b01098013dd9ed59fccce23da82483847e996f0bb1a7c97f628bbc9f9dcacaf8
4
+ data.tar.gz: 31c06195d3623e8e9dbe1c0bb81474541f3a827c058cc26d2482883f58f61c78
5
5
  SHA512:
6
- metadata.gz: e7e38ec385c2e13696913548716a7f022225cb1bcecee212934f0b4d2b08316a81f4e769cbf4e2517681a0df9adefb3ce4c5e1b500d16690937a8034b1852c63
7
- data.tar.gz: d3d1bf51e7117a0f51bc32e663c6ea63cf85fe342082a4b283efe05d8c9cb030e4c3733d43356ad4a80e80d3def336c6b1cfdc47db2ce2a7b3713115d62f03f4
6
+ metadata.gz: d67993b378e92f3ce5722202bd0f314922b89b71032700679f6053cc35acf8582ca9c3d018043323eded941deed8021bb0d5da25d3fe3ccc211a79aeef4ae614
7
+ data.tar.gz: ac9a1bbe13af4575d50fcea0ae677fbf4ce98cacd767b61a5b308846cd7fc43985692019aa5c6764d1bf9d73b6942955f045a6bcb441af0a6cf35a44104153aa
data/bin/ruaur CHANGED
@@ -4,28 +4,6 @@ require "hilighter"
4
4
  require "optparse"
5
5
  require "ruaur"
6
6
 
7
- class Flags
8
- # Query
9
- INFO = 1
10
- OWNS = 2
11
-
12
- # Remove
13
- NOSAVE = 3
14
-
15
- # Sync
16
- CLEAN = 4
17
- NAMES_ONLY = 5
18
- NOCONFIRM = 6
19
- SEARCH = 7
20
- UPGRADE = 8
21
- end
22
-
23
- class Operation
24
- QUERY = 1
25
- REMOVE = 2
26
- SYNC = 3
27
- end
28
-
29
7
  class RuAURExit
30
8
  GOOD = 0
31
9
  INVALID_OPTION = 1
@@ -39,12 +17,12 @@ end
39
17
 
40
18
  def parse(args)
41
19
  options = Hash.new
42
- options["flags"] = Array.new
43
20
  options["operation"] = nil
21
+ options["options"] = Array.new
44
22
  options["verbose"] = false
45
23
 
46
24
  parser = OptionParser.new do |opts|
47
- opts.summary_width = 17
25
+ opts.summary_width = 19
48
26
 
49
27
  opts.banner =
50
28
  "Usage: #{File.basename($0)} <operation> [OPTIONS] [pkgs]"
@@ -82,7 +60,7 @@ def parse(args)
82
60
  puts opts
83
61
  exit RuAURExit::MULTIPLE_OPERATIONS
84
62
  end
85
- options["operation"] = Operation::QUERY
63
+ options["operation"] = RuAUR::Operation::Query
86
64
  end
87
65
 
88
66
  opts.on("-R", "--remove", "Remove package(s)") do
@@ -90,7 +68,7 @@ def parse(args)
90
68
  puts opts
91
69
  exit RuAURExit::MULTIPLE_OPERATIONS
92
70
  end
93
- options["operation"] = Operation::REMOVE
71
+ options["operation"] = RuAUR::Operation::Remove
94
72
  end
95
73
 
96
74
  opts.on("-S", "--sync", "Synchronize package(s)") do
@@ -98,7 +76,7 @@ def parse(args)
98
76
  puts opts
99
77
  exit RuAURExit::MULTIPLE_OPERATIONS
100
78
  end
101
- options["operation"] = Operation::SYNC
79
+ options["operation"] = RuAUR::Operation::Sync
102
80
  end
103
81
 
104
82
  opts.on("", "QUERY_OPTIONS")
@@ -108,7 +86,7 @@ def parse(args)
108
86
  "--info",
109
87
  "Display information for given package(s)"
110
88
  ) do
111
- options["flags"].push(Flags::INFO)
89
+ options["options"].push(RuAUR::Options::Info)
112
90
  end
113
91
 
114
92
  opts.on(
@@ -116,33 +94,33 @@ def parse(args)
116
94
  "--owns",
117
95
  "Search for packages that own the specified file(s)"
118
96
  ) do
119
- options["flags"].push(Flags::OWNS)
97
+ options["options"].push(RuAUR::Options::Owns)
120
98
  end
121
99
 
122
100
  opts.on("", "REMOVE_OPTIONS")
123
101
 
124
102
  opts.on("-n", "--nosave", "Completely remove package") do
125
- options["flags"].push(Flags::NOSAVE)
103
+ options["options"].push(RuAUR::Options::NoSave)
126
104
  end
127
105
 
128
106
  opts.on("", "SYNC_OPTIONS")
129
107
 
130
108
  opts.on("-c", "--clean", "Remove packages from the cache") do
131
- options["flags"].push(Flags::CLEAN)
109
+ options["options"].push(RuAUR::Options::Clean)
132
110
  end
133
111
 
134
112
  opts.on(
135
113
  "--names-only",
136
114
  "Only show package names (useful for tab-completion)",
137
115
  ) do
138
- options["flags"].push(Flags::NAMES_ONLY)
116
+ options["options"].push(RuAUR::Options::NamesOnly)
139
117
  end
140
118
 
141
119
  opts.on(
142
120
  "--noconfirm",
143
121
  "Bypass any and all \"Are you sure?\" messages"
144
122
  ) do
145
- options["flags"].push(Flags::NOCONFIRM)
123
+ options["options"].push(RuAUR::Options::NoConfirm)
146
124
  end
147
125
 
148
126
  opts.on(
@@ -150,11 +128,19 @@ def parse(args)
150
128
  "--search",
151
129
  "Search the sync database and AUR for package(s)"
152
130
  ) do
153
- options["flags"].push(Flags::SEARCH)
131
+ options["options"].push(RuAUR::Options::Search)
154
132
  end
155
133
 
156
134
  opts.on("-u", "--sysupgrade", "Upgrade all packages") do
157
- options["flags"].push(Flags::UPGRADE)
135
+ options["options"].push(RuAUR::Options::Upgrade)
136
+ end
137
+
138
+ opts.on(
139
+ "-w",
140
+ "--downloadonly",
141
+ "Retrieve packages from the server, but do not install"
142
+ ) do
143
+ options["options"].push(RuAUR::Options::Download)
158
144
  end
159
145
  end
160
146
 
@@ -178,7 +164,7 @@ def parse(args)
178
164
  exit RuAURExit::AMBIGUOUS_ARGUMENT
179
165
  end
180
166
 
181
- if (!validate(options))
167
+ if (!RuAUR::validate_options(options))
182
168
  puts parser
183
169
  exit RuAURExit::INVALID_OPERATION
184
170
  end
@@ -188,95 +174,19 @@ def parse(args)
188
174
  return options
189
175
  end
190
176
 
191
- def validate(options)
192
- case options["operation"]
193
- when Operation::QUERY
194
- flags = options["flags"].select do |flag|
195
- (flag != Flags::INFO) &&
196
- (flag != Flags::OWNS)
197
- end
198
- return false if (!flags.empty?)
199
- when Operation::REMOVE
200
- flags = options["flags"].select do |flag|
201
- flag != Flags::NOSAVE
202
- end
203
- return false if (!flags.empty?)
204
- when Operation::SYNC
205
- flags = options["flags"].select do |flag|
206
- (flag != Flags::CLEAN) &&
207
- (flag != Flags::NAMES_ONLY) &&
208
- (flag != Flags::NOCONFIRM) &&
209
- (flag != Flags::SEARCH) &&
210
- (flag != Flags::UPGRADE)
211
- end
212
- return false if (!flags.empty?)
213
-
214
- if (options["flags"].include?(Flags::CLEAN))
215
- if (
216
- options["flags"].include?(Flags::NAMES_ONLY) ||
217
- options["flags"].include?(Flags::SEARCH) ||
218
- options["flags"].include?(Flags::UPGRADE)
219
- )
220
- return false
221
- end
222
- elsif (options["flags"].include?(Flags::SEARCH))
223
- if (
224
- options["flags"].include?(Flags::CLEAN) || options["flags"].include?(Flags::UPGRADE)
225
- )
226
- return false
227
- end
228
- elsif (options["flags"].include?(Flags::UPGRADE))
229
- if (
230
- options["flags"].include?(Flags::CLEAN) ||
231
- options["flags"].include?(Flags::NAMES_ONLY) ||
232
- options["flags"].include?(Flags::SEARCH)
233
- )
234
- return false
235
- end
236
- end
237
- else
238
- return false
239
- end
240
-
241
- return true
242
- end
243
-
244
177
  # Parse CLI args
245
178
  options = parse(ARGV)
246
179
 
247
180
  begin
248
181
  ruaur = RuAUR.new(!Hilighter.disable?)
249
-
250
182
  case options["operation"]
251
- when Operation::QUERY
252
- ruaur.query(
253
- options["packages"],
254
- options["flags"].include?(Flags::INFO),
255
- options["flags"].include?(Flags::OWNS)
256
- )
257
- when Operation::REMOVE
258
- ruaur.remove(
259
- options["packages"],
260
- options["flags"].include?(Flags::NOSAVE)
261
- )
262
- when Operation::SYNC
263
- if (options["flags"].include?(Flags::CLEAN))
264
- ruaur.clean(options["flags"].include?(Flags::NOCONFIRM))
265
- elsif (options["flags"].include?(Flags::SEARCH))
266
- puts ruaur.search(
267
- options["packages"].join(" "),
268
- options["flags"].include?(Flags::NAMES_ONLY)
269
- )
270
- elsif (options["flags"].include?(Flags::UPGRADE))
271
- ruaur.upgrade(
272
- options["flags"].include?(Flags::NOCONFIRM)
273
- )
274
- else
275
- ruaur.install(
276
- options["packages"],
277
- options["flags"].include?(Flags::NOCONFIRM)
278
- )
279
- end
183
+ when RuAUR::Operation::Query
184
+ ruaur.query(options["packages"], options["options"])
185
+ when RuAUR::Operation::Remove
186
+ ruaur.remove(options["packages"], options["options"])
187
+ when RuAUR::Operation::Sync
188
+ ret = ruaur.sync(options["packages"], options["options"])
189
+ puts ret if (ret)
280
190
  end
281
191
  rescue Interrupt
282
192
  # ^C
data/lib/ruaur/aur.rb CHANGED
@@ -53,7 +53,6 @@ class RuAUR::AUR
53
53
  )
54
54
  end
55
55
  end
56
- private :download
57
56
 
58
57
  def edit_pkgbuild(package, noconfirm = false)
59
58
  return false if (noconfirm)
@@ -134,18 +133,9 @@ class RuAUR::AUR
134
133
  def get_dependencies(package)
135
134
  deps = Array.new
136
135
  Dir.chdir("#{@cache}/#{package.name}") do
137
- pkgbuild = File.read("PKGBUILD")
138
- pkgbuild.match(/^depends\=\(([^\)]+)\)/m) do |match|
139
- match.captures.each do |cap|
140
- cap.gsub(/\n/, " ").scan(/[^' ]+/) do |scan|
141
- # Strip version info and skip any deps that
142
- # are variables, for now
143
- # FIXME maybe find way to evaluate variable
144
- # value
145
- dep = scan.gsub(/(\<|\=|\>).*$/, "")
146
- next if (dep.start_with?("$"))
147
- deps.push(dep)
148
- end
136
+ %x(makepkg --printsrcinfo).each_line do |line|
137
+ line.match(/depends\s*\=\s*([^>=:\n]+)/) do |m|
138
+ deps.push(m[1])
149
139
  end
150
140
  end
151
141
  end
@@ -0,0 +1,5 @@
1
+ class RuAUR::Operation
2
+ Query = 1
3
+ Remove = 2
4
+ Sync = 3
5
+ end
@@ -0,0 +1,16 @@
1
+ class RuAUR::Options
2
+ # Query
3
+ Info = 1
4
+ Owns = 2
5
+
6
+ # Remove
7
+ NoSave = 3
8
+
9
+ # Sync
10
+ Clean = 4
11
+ Download = 5
12
+ NamesOnly = 6
13
+ NoConfirm = 7
14
+ Search = 8
15
+ Upgrade = 9
16
+ end
data/lib/ruaur/pacman.rb CHANGED
@@ -8,6 +8,15 @@ class RuAUR::Pacman
8
8
  system("sudo #{@pac_cmd} -Sc --noconfirm") if (noconfirm)
9
9
  end
10
10
 
11
+ def download(pkg_name, noconfirm = false)
12
+ puts hilight_status("Downloading #{pkg_name}...")
13
+ if (!noconfirm)
14
+ system("sudo #{@pac_cmd} -Sw #{pkg_name}")
15
+ else
16
+ system("sudo #{@pac_cmd} -Sw #{pkg_name} --noconfirm")
17
+ end
18
+ end
19
+
11
20
  def exist?(pkg_name)
12
21
  return !%x(#{@pac_nocolor} -Ss "^#{pkg_name}$").empty?
13
22
  end
@@ -82,17 +91,10 @@ class RuAUR::Pacman
82
91
  end
83
92
 
84
93
  def query_aur(pkg_name = "")
85
- community = Pathname.new(
86
- "/var/lib/pacman/sync/community"
87
- ).expand_path
88
-
89
94
  results = Hash.new
90
95
  %x(
91
- #{@pac_nocolor} -Qm #{pkg_name}
92
- ).split("\n").delete_if do |p|
93
- # Skip packages in community
94
- Dir["#{community}/#{p.split.join("-")}"].any?
95
- end.each do |line|
96
+ #{@pac_nocolor} -Qm #{pkg_name} 2>/dev/null
97
+ ).each_line do |line|
96
98
  line = line.split
97
99
  results[line[0]] = line[1]
98
100
  end
data/lib/ruaur.rb CHANGED
@@ -12,8 +12,25 @@ class RuAUR
12
12
  private :check_and_lock
13
13
 
14
14
  def clean(noconfirm)
15
+ check_and_lock
15
16
  @pacman.clean(noconfirm)
16
17
  @aur.clean
18
+ ensure
19
+ unlock
20
+ end
21
+
22
+ def download(pkg_names, noconfirm = false)
23
+ pkg_names.each do |pkg_name|
24
+ if (@pacman.exist?(pkg_name))
25
+ @pacman.download(pkg_name, noconfirm)
26
+ system(
27
+ "cp /var/cache/pacman/pkg/#{pkg_name}-[0-9]*.xz ."
28
+ )
29
+ else
30
+ package = @aur.info(pkg_name)
31
+ @aur.download(package)
32
+ end
33
+ end
17
34
  end
18
35
 
19
36
  def self.hilight?
@@ -57,7 +74,10 @@ class RuAUR
57
74
  unlock
58
75
  end
59
76
 
60
- def query(pkg_names, info = false, owns = false)
77
+ def query(pkg_names, options = [])
78
+ info = options.include?(RuAUR::Options::Info)
79
+ owns = options.include?(RuAUR::Options::Owns)
80
+
61
81
  if (owns)
62
82
  puts @pacman.query_owns(pkg_names.join(" "))
63
83
  else
@@ -78,8 +98,9 @@ class RuAUR
78
98
  end
79
99
  end
80
100
 
81
- def remove(pkg_names, nosave = false)
101
+ def remove(pkg_names, options = [])
82
102
  check_and_lock
103
+ nosave = options.include?(RuAUR::Options::NoSave)
83
104
  @pacman.remove(pkg_names, nosave)
84
105
  ensure
85
106
  unlock
@@ -95,6 +116,30 @@ class RuAUR
95
116
  return names
96
117
  end
97
118
 
119
+ def sync(packages = [], options = [])
120
+ if (options.include?(RuAUR::Options::Clean))
121
+ clean(options.include?(RuAUR::Options::NoConfirm))
122
+ elsif (options.include?(RuAUR::Options::Download))
123
+ download(
124
+ packages,
125
+ options.include?(RuAUR::Options::NoConfirm)
126
+ )
127
+ elsif (options.include?(RuAUR::Options::Search))
128
+ return search(
129
+ packages.join(" "),
130
+ options.include?(RuAUR::Options::NamesOnly)
131
+ )
132
+ elsif (options.include?(RuAUR::Options::Upgrade))
133
+ upgrade(options.include?(RuAUR::Options::NoConfirm))
134
+ else
135
+ install(
136
+ packages,
137
+ options.include?(RuAUR::Options::NoConfirm)
138
+ )
139
+ end
140
+ return nil
141
+ end
142
+
98
143
  def unlock
99
144
  FileUtils.rm_f(@lock)
100
145
  end
@@ -107,9 +152,66 @@ class RuAUR
107
152
  ensure
108
153
  unlock
109
154
  end
155
+
156
+ def self.validate_options(options)
157
+ valid = {
158
+ RuAUR::Operation::Query => {
159
+ "valid" => [
160
+ RuAUR::Options::Info,
161
+ RuAUR::Options::Owns
162
+ ]
163
+ },
164
+ RuAUR::Operation::Remove => {
165
+ "valid" => [
166
+ RuAUR::Options::NoSave
167
+ ]
168
+ },
169
+ RuAUR::Operation::Sync => {
170
+ "valid" => [
171
+ RuAUR::Options::Clean,
172
+ RuAUR::Options::Download,
173
+ RuAUR::Options::NamesOnly,
174
+ RuAUR::Options::NoConfirm,
175
+ RuAUR::Options::Search,
176
+ RuAUR::Options::Upgrade
177
+ ],
178
+ RuAUR::Options::Clean => [
179
+ RuAUR::Options::Clean,
180
+ RuAUR::Options::NoConfirm
181
+ ],
182
+ RuAUR::Options::Download => [
183
+ RuAUR::Options::Download,
184
+ RuAUR::Options::NoConfirm
185
+ ],
186
+ RuAUR::Options::Search => [
187
+ RuAUR::Options::NamesOnly,
188
+ RuAUR::Options::NoConfirm,
189
+ RuAUR::Options::Search
190
+ ],
191
+ RuAUR::Options::Upgrade => [
192
+ RuAUR::Options::NoConfirm,
193
+ RuAUR::Options::Upgrade
194
+ ]
195
+ }
196
+ }
197
+
198
+ return false if (valid[options["operation"]].nil?)
199
+
200
+ valid[options["operation"]].each do |k, v|
201
+ if ((k == "valid") || options["options"].include?(k))
202
+ options["options"].each do |o|
203
+ return false if (!v.include?(o))
204
+ end
205
+ end
206
+ end
207
+
208
+ return true
209
+ end
110
210
  end
111
211
 
112
212
  require "ruaur/aur"
113
213
  require "ruaur/error"
214
+ require "ruaur/operation"
215
+ require "ruaur/options"
114
216
  require "ruaur/package"
115
217
  require "ruaur/pacman"
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.3.5
4
+ version: 1.0.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: 2018-01-31 00:00:00.000000000 Z
11
+ date: 2018-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -130,6 +130,8 @@ files:
130
130
  - lib/ruaur/error/package_not_found_error.rb
131
131
  - lib/ruaur/error/package_not_installed_error.rb
132
132
  - lib/ruaur/error/ruaur_already_running_error.rb
133
+ - lib/ruaur/operation.rb
134
+ - lib/ruaur/options.rb
133
135
  - lib/ruaur/package.rb
134
136
  - lib/ruaur/pacman.rb
135
137
  homepage: https://mjwhitta.github.io/ruaur