mspac 0.1.9 → 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.
- checksums.yaml +4 -4
- data/bin/mspac +72 -24
- data/lib/mspac.rb +24 -19
- data/lib/mspac/pellet.rb +64 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa634c685780667d55fcb7b238ab038b18c7ab55
|
4
|
+
data.tar.gz: 0df6dae9937571241798467cc4a36598fef8a5fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a93ebe91bc62e331ff39731547f06b8f0b9a57198db7cb3dc350dec939284f773ca295962a3adf2787871c0da1608f74cb91719575671309135cc45a421a69f
|
7
|
+
data.tar.gz: 692ece16964d0bc38ed5c8618aa6c0345a87acde1c8525dfaced15bbc6282702cb65742b2b117153cd2f2b513a3aa35406ed2f1418bb325f528cb466dd780b89
|
data/bin/mspac
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "colorize"
|
4
|
+
require "io/wait"
|
4
5
|
require "mspac"
|
5
6
|
require "optparse"
|
6
7
|
|
@@ -9,9 +10,10 @@ class MsPacExit
|
|
9
10
|
INVALID_OPTION = 1
|
10
11
|
INVALID_ARGUMENT = 2
|
11
12
|
MISSING_ARGUMENT = 3
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
EXTRA_ARGUMENTS = 4
|
14
|
+
EXCEPTION = 5
|
15
|
+
INVALID_OPERATION = 6
|
16
|
+
MULTIPLE_OPERATIONS = 7
|
15
17
|
end
|
16
18
|
|
17
19
|
class Operation
|
@@ -27,6 +29,7 @@ end
|
|
27
29
|
def parse(args)
|
28
30
|
options = Hash.new
|
29
31
|
options["operation"] = nil
|
32
|
+
options["verbose"] = false
|
30
33
|
|
31
34
|
# Sync options
|
32
35
|
options["clean"] = false
|
@@ -48,19 +51,7 @@ def parse(args)
|
|
48
51
|
|
49
52
|
opts.on("-h", "--help", "Display this help message") do
|
50
53
|
puts opts
|
51
|
-
exit
|
52
|
-
end
|
53
|
-
|
54
|
-
opts.on("--list-cached", "List cached pellets") do
|
55
|
-
options["operation"] = Operation::LIST_CACHED
|
56
|
-
end
|
57
|
-
|
58
|
-
opts.on("--list-installed", "List installed pellets") do
|
59
|
-
options["operation"] = Operation::LIST_INSTALLED
|
60
|
-
end
|
61
|
-
|
62
|
-
opts.on("--list-pellets", "List available pellets") do
|
63
|
-
options["operation"] = Operation::LIST_PELLETS
|
54
|
+
exit MsPacExit::GOOD
|
64
55
|
end
|
65
56
|
|
66
57
|
opts.on(
|
@@ -99,7 +90,7 @@ def parse(args)
|
|
99
90
|
options["operation"] = Operation::UNLOCK
|
100
91
|
end
|
101
92
|
|
102
|
-
opts.on("", "
|
93
|
+
opts.on("", "SYNC_OPTIONS")
|
103
94
|
|
104
95
|
opts.on(
|
105
96
|
"-c",
|
@@ -135,11 +126,49 @@ def parse(args)
|
|
135
126
|
options["refresh"] = true
|
136
127
|
end
|
137
128
|
|
138
|
-
opts.on("", "
|
129
|
+
opts.on("", "REMOVE_OPTIONS")
|
139
130
|
|
140
131
|
opts.on("-n", "--nosave", "Completely remove pellet") do
|
141
132
|
options["nosave"] = true
|
142
133
|
end
|
134
|
+
|
135
|
+
opts.on("", "MISC_OPTIONS")
|
136
|
+
|
137
|
+
opts.on("--list-cached", "List cached pellets") do
|
138
|
+
if (options["operation"])
|
139
|
+
puts opts
|
140
|
+
exit MsPacExit::MULTIPLE_OPERATIONS
|
141
|
+
end
|
142
|
+
options["operation"] = Operation::LIST_CACHED
|
143
|
+
end
|
144
|
+
|
145
|
+
opts.on("--list-installed", "List installed pellets") do
|
146
|
+
if (options["operation"])
|
147
|
+
puts opts
|
148
|
+
exit MsPacExit::MULTIPLE_OPERATIONS
|
149
|
+
end
|
150
|
+
options["operation"] = Operation::LIST_INSTALLED
|
151
|
+
end
|
152
|
+
|
153
|
+
opts.on("--list-pellets", "List available pellets") do
|
154
|
+
if (options["operation"])
|
155
|
+
puts opts
|
156
|
+
exit MsPacExit::MULTIPLE_OPERATIONS
|
157
|
+
end
|
158
|
+
options["operation"] = Operation::LIST_PELLETS
|
159
|
+
end
|
160
|
+
|
161
|
+
opts.on("--nocolor", "Disable colorized output") do
|
162
|
+
String.disable_colorization = true
|
163
|
+
end
|
164
|
+
|
165
|
+
opts.on(
|
166
|
+
"-v",
|
167
|
+
"--verbose",
|
168
|
+
"Show backtrace when error occurs"
|
169
|
+
) do
|
170
|
+
options["verbose"] = true
|
171
|
+
end
|
143
172
|
end
|
144
173
|
|
145
174
|
begin
|
@@ -282,7 +311,7 @@ end
|
|
282
311
|
options = parse(ARGV)
|
283
312
|
|
284
313
|
begin
|
285
|
-
mspac = MsPac.new
|
314
|
+
mspac = MsPac.new(!String.disable_colorization)
|
286
315
|
|
287
316
|
case options["operation"]
|
288
317
|
when Operation::LIST_CACHED
|
@@ -315,11 +344,30 @@ begin
|
|
315
344
|
when Operation::UNLOCK
|
316
345
|
mspac.unlock(options["pellets"])
|
317
346
|
end
|
318
|
-
|
347
|
+
rescue Interrupt
|
348
|
+
# ^C
|
349
|
+
# Exit gracefully
|
350
|
+
rescue Errno::EPIPE
|
351
|
+
# Do nothing. This can happen if piping to another program such as
|
352
|
+
# less. Usually if less is closed before we're done with STDOUT.
|
319
353
|
rescue MsPac::Error => e
|
320
|
-
puts e.message
|
354
|
+
puts e.message
|
355
|
+
exit MsPacExit::EXCEPTION
|
356
|
+
rescue Exception => e
|
357
|
+
$stderr.puts "Oops! Looks like an error has occured! If the " \
|
358
|
+
"error persists, file a bug at:".word_wrap
|
359
|
+
$stderr.puts
|
360
|
+
$stderr.puts " https://gitlab.com/mjwhitta/mspac/issues"
|
361
|
+
$stderr.puts
|
362
|
+
$stderr.puts "Maybe the message below will help. If not, you " \
|
363
|
+
"can use the --verbose flag to get a backtrace.".word_wrap
|
364
|
+
|
365
|
+
$stderr.puts e.message.white.on_red
|
366
|
+
if (options["verbose"])
|
367
|
+
e.backtrace.each do |line|
|
368
|
+
$stderr.puts line.light_yellow
|
369
|
+
end
|
370
|
+
end
|
321
371
|
exit MsPacExit::EXCEPTION
|
322
|
-
rescue Interrupt => e
|
323
|
-
# ^C
|
324
|
-
puts
|
325
372
|
end
|
373
|
+
exit MsPacExit::GOOD
|
data/lib/mspac.rb
CHANGED
@@ -18,11 +18,23 @@ class MsPac
|
|
18
18
|
# FIXME will miss pellets that get deleted by refresh
|
19
19
|
end
|
20
20
|
|
21
|
+
def colorize_error(error)
|
22
|
+
return error if (!@colorize)
|
23
|
+
return error.light_red
|
24
|
+
end
|
25
|
+
private :colorize_error
|
26
|
+
|
27
|
+
def colorize_status(status)
|
28
|
+
return status if (!@colorize)
|
29
|
+
return status.light_white
|
30
|
+
end
|
31
|
+
private :colorize_status
|
32
|
+
|
21
33
|
def ensure_pellets_repo
|
22
34
|
@pellets_dir = Pathname.new("~/.mspac/pellets").expand_path
|
23
35
|
return if (@pellets_dir && @pellets_dir.exist?)
|
24
36
|
|
25
|
-
puts "Installing MsPac dependencies..."
|
37
|
+
puts colorize_status("Installing MsPac dependencies...")
|
26
38
|
@pm.install(["git"]) if (ScoobyDoo.where_are_you("git").nil?)
|
27
39
|
Dir.chdir(@mspac_dir) do
|
28
40
|
@vcs.clone("https://gitlab.com/mjwhitta/pellets.git")
|
@@ -35,7 +47,8 @@ class MsPac
|
|
35
47
|
end
|
36
48
|
private :ensure_pellets_repo
|
37
49
|
|
38
|
-
def initialize
|
50
|
+
def initialize(colorize = false)
|
51
|
+
@colorize = colorize
|
39
52
|
FileUtils.mkdir_p(Pathname.new("~/.mspac").expand_path)
|
40
53
|
@mspac_dir = Pathname.new("~/.mspac").expand_path
|
41
54
|
@pm = PackageManager.new
|
@@ -78,13 +91,16 @@ class MsPac
|
|
78
91
|
@pellets = Hash.new
|
79
92
|
Dir["#{@pellets_dir}/*.pellet"].each do |pellet|
|
80
93
|
begin
|
81
|
-
p = Pellet.new(
|
94
|
+
p = Pellet.new(
|
95
|
+
JSON.parse(File.read(pellet)),
|
96
|
+
@colorize
|
97
|
+
)
|
82
98
|
@pellets[p.name] = p
|
83
99
|
rescue JSON::ParserError => e
|
84
|
-
puts "#{pellet} is not valid JSON!"
|
85
|
-
puts e.message.
|
100
|
+
puts colorize_error("#{pellet} is not valid JSON!")
|
101
|
+
puts e.message.white.on_red
|
86
102
|
rescue Exception => e
|
87
|
-
puts e.message.
|
103
|
+
puts e.message.white.on_red
|
88
104
|
end
|
89
105
|
end
|
90
106
|
end
|
@@ -109,7 +125,7 @@ class MsPac
|
|
109
125
|
end
|
110
126
|
|
111
127
|
def refresh
|
112
|
-
puts "Refreshing pellets..."
|
128
|
+
puts colorize_status("Refreshing pellets...")
|
113
129
|
Dir.chdir(@pellets_dir) do
|
114
130
|
@vcs.update
|
115
131
|
end
|
@@ -134,18 +150,7 @@ class MsPac
|
|
134
150
|
pellet = @pellets[name]
|
135
151
|
name_match = pellet.name.match(/#{regex}/)
|
136
152
|
desc_match = pellet.desc.match(/#{regex}/)
|
137
|
-
if (name_match || desc_match)
|
138
|
-
print "#{pellet.name}".white
|
139
|
-
if (pellet.installed?)
|
140
|
-
puts " [installed]".green
|
141
|
-
elsif (pellet.cached?)
|
142
|
-
puts " [cached]".blue
|
143
|
-
else
|
144
|
-
puts
|
145
|
-
end
|
146
|
-
puts " #{pellet.repo}"
|
147
|
-
puts " #{pellet.desc}"
|
148
|
-
end
|
153
|
+
puts pellet.to_s if (name_match || desc_match)
|
149
154
|
end
|
150
155
|
end
|
151
156
|
|
data/lib/mspac/pellet.rb
CHANGED
@@ -5,11 +5,50 @@ class MsPac::Pellet < Hash
|
|
5
5
|
@@cache_dir = Pathname("~/.mspac/cache").expand_path
|
6
6
|
@@install_dir = Pathname("~/.mspac/installed").expand_path
|
7
7
|
|
8
|
-
def
|
8
|
+
def colorize_cached(cached)
|
9
|
+
if (!@colorize)
|
10
|
+
return "[cached]" if (cached)
|
11
|
+
else
|
12
|
+
return "[cached]".light_blue if (cached)
|
13
|
+
end
|
14
|
+
return ""
|
15
|
+
end
|
16
|
+
private :colorize_cached
|
17
|
+
|
18
|
+
def colorize_error(error)
|
19
|
+
return error if (!@colorize)
|
20
|
+
return error.light_red
|
21
|
+
end
|
22
|
+
private :colorize_error
|
23
|
+
|
24
|
+
def colorize_installed(installed)
|
25
|
+
if (!@colorize)
|
26
|
+
return "[installed]" if (installed)
|
27
|
+
else
|
28
|
+
return "[installed]".light_green if (installed)
|
29
|
+
end
|
30
|
+
return ""
|
31
|
+
end
|
32
|
+
private :colorize_installed
|
33
|
+
|
34
|
+
def colorize_name(name = @name)
|
35
|
+
return name if (!@colorize)
|
36
|
+
return name.light_white
|
37
|
+
end
|
38
|
+
private :colorize_name
|
39
|
+
|
40
|
+
def colorize_status(status)
|
41
|
+
return status if (!@colorize)
|
42
|
+
return status.light_white
|
43
|
+
end
|
44
|
+
private :colorize_status
|
45
|
+
|
46
|
+
def initialize(json, colorize = false)
|
9
47
|
json.keys.each do |key|
|
10
48
|
self[key] = json[key]
|
11
49
|
end
|
12
50
|
|
51
|
+
@colorize = colorize
|
13
52
|
@pm = MsPac::PackageManager.new
|
14
53
|
@vcs = MsPac::VersionControl.new(self["vcs"])
|
15
54
|
end
|
@@ -20,7 +59,7 @@ class MsPac::Pellet < Hash
|
|
20
59
|
|
21
60
|
def compile
|
22
61
|
return if (self["compile"].empty?)
|
23
|
-
puts "Compiling #{name}..."
|
62
|
+
puts colorize_status("Compiling #{name}...")
|
24
63
|
execute("compile")
|
25
64
|
end
|
26
65
|
private :compile
|
@@ -42,7 +81,7 @@ class MsPac::Pellet < Hash
|
|
42
81
|
|
43
82
|
get_deps
|
44
83
|
|
45
|
-
puts "Fetching #{name}..."
|
84
|
+
puts colorize_status("Fetching #{name}...")
|
46
85
|
if (Pathname.new("#{@@cache_dir}/#{name}").expand_path.exist?)
|
47
86
|
Dir.chdir("#{@@cache_dir}/#{name}") do
|
48
87
|
@vcs.update
|
@@ -56,7 +95,7 @@ class MsPac::Pellet < Hash
|
|
56
95
|
end
|
57
96
|
|
58
97
|
def get_deps
|
59
|
-
puts "Installing dependencies..."
|
98
|
+
puts colorize_status("Installing dependencies...")
|
60
99
|
@pm.install([self["vcs"]].concat(self["deps"][@pm.pkgmgr]))
|
61
100
|
@pm.install(self["deps"]["perl"], "perl")
|
62
101
|
@pm.install(self["deps"]["python2"], "python2")
|
@@ -72,7 +111,7 @@ class MsPac::Pellet < Hash
|
|
72
111
|
link if (!installed?)
|
73
112
|
compile
|
74
113
|
|
75
|
-
puts "Installing #{name}..."
|
114
|
+
puts colorize_status("Installing #{name}...")
|
76
115
|
execute("install")
|
77
116
|
end
|
78
117
|
|
@@ -85,7 +124,7 @@ class MsPac::Pellet < Hash
|
|
85
124
|
raise MsPac::Error::PelletNotInstalledError.new(name)
|
86
125
|
end
|
87
126
|
|
88
|
-
puts "Linking #{name}..."
|
127
|
+
puts colorize_status("Linking #{name}...")
|
89
128
|
FileUtils.ln_sf(
|
90
129
|
"#{@@cache_dir}/#{name}",
|
91
130
|
"#{@@install_dir}/#{name}"
|
@@ -97,7 +136,7 @@ class MsPac::Pellet < Hash
|
|
97
136
|
raise MsPac::Error::PelletNotInstalledError.new(name)
|
98
137
|
end
|
99
138
|
|
100
|
-
puts "Locking #{name}..."
|
139
|
+
puts colorize_status("Locking #{name}...")
|
101
140
|
FileUtils.touch("#{@@install_dir}/#{name}/.mspac_lock")
|
102
141
|
end
|
103
142
|
|
@@ -110,7 +149,7 @@ class MsPac::Pellet < Hash
|
|
110
149
|
raise MsPac::Error::PelletNotInstalledError.new(name)
|
111
150
|
end
|
112
151
|
|
113
|
-
puts "Purging #{name}..."
|
152
|
+
puts colorize_status("Purging #{name}...")
|
114
153
|
FileUtils.rm_rf("#{@@cache_dir}/#{name}")
|
115
154
|
end
|
116
155
|
|
@@ -119,7 +158,7 @@ class MsPac::Pellet < Hash
|
|
119
158
|
raise MsPac::Error::PelletNotInstalledError.new(name)
|
120
159
|
end
|
121
160
|
|
122
|
-
puts "Removing #{name}..."
|
161
|
+
puts colorize_status("Removing #{name}...")
|
123
162
|
execute("remove")
|
124
163
|
unlink
|
125
164
|
purge if (nosave)
|
@@ -129,12 +168,24 @@ class MsPac::Pellet < Hash
|
|
129
168
|
return self["repo"]
|
130
169
|
end
|
131
170
|
|
171
|
+
def to_s
|
172
|
+
header = [
|
173
|
+
colorize_name(name),
|
174
|
+
colorize_installed(installed?) || colorize_cached(cached?)
|
175
|
+
].join(" ")
|
176
|
+
return [
|
177
|
+
header,
|
178
|
+
" #{repo}",
|
179
|
+
" #{desc}"
|
180
|
+
].join("\n")
|
181
|
+
end
|
182
|
+
|
132
183
|
def unlink
|
133
184
|
if (!installed?)
|
134
185
|
raise MsPac::Error::PelletNotInstalledError.new(name)
|
135
186
|
end
|
136
187
|
|
137
|
-
puts "Unlinking #{name}..."
|
188
|
+
puts colorize_status("Unlinking #{name}...")
|
138
189
|
FileUtils.rm_f("#{@@install_dir}/#{name}")
|
139
190
|
end
|
140
191
|
|
@@ -143,7 +194,7 @@ class MsPac::Pellet < Hash
|
|
143
194
|
raise MsPac::Error::PelletNotInstalledError.new(name)
|
144
195
|
end
|
145
196
|
|
146
|
-
puts "Unlocking #{name}..."
|
197
|
+
puts colorize_status("Unlocking #{name}...")
|
147
198
|
FileUtils.rm_f("#{@@install_dir}/#{name}/.mspac_lock")
|
148
199
|
end
|
149
200
|
|
@@ -154,11 +205,11 @@ class MsPac::Pellet < Hash
|
|
154
205
|
|
155
206
|
Dir.chdir("#{@@install_dir}/#{name}") do
|
156
207
|
if (Pathname.new(".mspac_lock").expand_path.exist?)
|
157
|
-
puts "Locked: #{name}"
|
208
|
+
puts colorize_error("Locked: #{name}")
|
158
209
|
return
|
159
210
|
end
|
160
211
|
|
161
|
-
puts "Updating #{name}..."
|
212
|
+
puts colorize_status("Updating #{name}...")
|
162
213
|
tip = @vcs.revision
|
163
214
|
@vcs.update
|
164
215
|
new_tip = @vcs.revision
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mspac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2016-
|
11
|
+
date: 2016-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|