ccu 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +3 -1
- data/bin/ccu +30 -8
- data/ccu.gemspec +1 -1
- data/spec/_spec.rb +103 -6
- data/spec/files/_spec.rb +5 -1
- data/spec/files/unknown +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6623afccf6a92ac93d097bf9cd793ecc39523a80
|
4
|
+
data.tar.gz: b97884414cbba53123358bd2339d4e5a67168c78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0512c4a6195e8ad924b9278a15eacd60f2f66e74051be8af7fac313e4c99a4b5cda59e3f2c76224623c6e9054de4dd887cfdf3d860e57cd0d0b60ad2abfe4530
|
7
|
+
data.tar.gz: a543db2c6e3e5109454050a623b3c154f871601b0a7d48bdc2c8e8821e7110351c650a6e65339cf97aa5bf9bf2dc66e3e6188f7d4dfe9222c020c8cf8b665767
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/bin/ccu
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
STDOUT.sync = true
|
4
|
+
|
3
5
|
# TODO: to use http://ruby-doc.org/stdlib-2.2.0/libdoc/optparse/rdoc/OptionParser.html
|
4
6
|
|
5
|
-
Signal.trap(
|
7
|
+
Signal.trap(:INT){ puts "\n(interrupted by SIGINT)"; exit 0 }
|
6
8
|
|
7
|
-
|
9
|
+
abort "\tCCU usage:\tccu <file[s]>" if !ARGV.first || ARGV.first[/^-*(v(ersion)?|h(elp)?)$/]
|
8
10
|
|
9
11
|
expect = lambda do |command, expectation|
|
10
12
|
output = `#{command}`
|
@@ -17,12 +19,32 @@ end
|
|
17
19
|
|
18
20
|
# ARGV.first =~ /(?<basename>.*)\.(?<extension>.+)/
|
19
21
|
filename = ARGV.first
|
20
|
-
abort "ERROR: can't run without parameters"
|
21
22
|
extension = File.extname filename
|
22
|
-
ARGV.clear
|
23
|
-
|
23
|
+
ARGV.clear # to stop #gets read from ARGF
|
24
|
+
|
25
|
+
# exit p [filename, File.expand_path(filename), File.exist?(filename), File.directory?(filename)]
|
26
|
+
|
27
|
+
# TODO: use Shellwords.escape
|
28
|
+
# TODO: chomp ?/
|
29
|
+
|
30
|
+
if File.directory? filename
|
31
|
+
puts "\tIt is a directory."
|
32
|
+
expect[ "file \"#{filename}\"", "#{filename}: directory\n" ]
|
33
|
+
puts "\tWhat would you like to do with it?"
|
34
|
+
newname = filename + ".tar.gz"
|
35
|
+
begin puts "\t[a] - archive to \"./%s\"" % newname end until gets == "a\n" || puts("WUT?")
|
36
|
+
expect[ "tar --version", /^bsdtar 2\.8\.3 -/ ]
|
37
|
+
abort "ERROR: file %p already exists" % newname if File.exist? newname
|
38
|
+
cmd = "tar czf \"#{newname}\" \"#{filename}\""
|
39
|
+
puts "\tPress Enter to proceed or ^C to cancel this shell command:\n\t\t#{cmd}"
|
40
|
+
gets
|
41
|
+
system cmd
|
42
|
+
system "file \"#{newname}\""
|
43
|
+
exit
|
44
|
+
end
|
24
45
|
|
25
|
-
|
46
|
+
case extension.downcase
|
47
|
+
when ".zip___"
|
26
48
|
puts "\tAssuming it is a ZIP archive."
|
27
49
|
expect[ "file \"#{filename}\"", "#{filename}: Zip archive data, at least v1.0 to extract\n" ]
|
28
50
|
expect[ "unzip -v", /^UnZip 5\.52 / ]
|
@@ -37,7 +59,7 @@ when ".zip"
|
|
37
59
|
gets
|
38
60
|
system cmd
|
39
61
|
system "ls -1 | grep \"^#{basename}\""
|
40
|
-
when ".
|
62
|
+
when ".gif___"
|
41
63
|
puts "\tAssuming it is a GIF image."
|
42
64
|
expect[ "file \"#{filename}\"", /^#{filename}: GIF image data, version 89a, \d+ x \d+\n$/ ]
|
43
65
|
expect[ "sips --help", /^sips 10\.4\.4 / ]
|
@@ -65,5 +87,5 @@ when ".gif"
|
|
65
87
|
system cmd
|
66
88
|
system "sips -g all \"#{newname}\""
|
67
89
|
else
|
68
|
-
abort "
|
90
|
+
abort "Unknown file extension %p" % extension
|
69
91
|
end
|
data/ccu.gemspec
CHANGED
data/spec/_spec.rb
CHANGED
@@ -1,10 +1,107 @@
|
|
1
1
|
# require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
# TODO: check for test files existence before and after
|
4
|
+
|
5
|
+
describe "ccu" do
|
6
|
+
require "open3"
|
7
|
+
let(:binary){ Shellwords.escape File.join __dir__, "../bin/ccu" }
|
8
|
+
# before(:suite){ Dir.chdir "#{__dir__}/files" }
|
9
|
+
|
10
|
+
# # around hook variable sharing hack (c) Nakilon
|
11
|
+
# let(:temp_dir_var){ [] }
|
12
|
+
# def temp_dir setting = nil
|
13
|
+
# temp_dir_var[0] = setting || temp_dir_var[0]
|
14
|
+
# end
|
15
|
+
around do |example|
|
16
|
+
require "tmpdir"
|
17
|
+
Dir.mktmpdir do |dir|
|
18
|
+
# temp_dir dir
|
19
|
+
Dir.chdir(dir) do
|
20
|
+
require "fileutils"
|
21
|
+
FileUtils.cp_r "#{__dir__}/files", "./† †"
|
22
|
+
expect(Dir.pwd).to match(/^\/private\/var\/folders\//)
|
23
|
+
expected_files = Dir.chdir(__dir__){ Dir["**/*"] }.map do |file|
|
24
|
+
file.sub! /^files(\/|$)/, '† †\1'
|
25
|
+
end.compact
|
26
|
+
expect(Dir["**/*"]).to eq(expected_files),
|
27
|
+
"didn't add `/files' directory to temp dir"
|
28
|
+
example.run
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "<ctrl> + C" do
|
34
|
+
# threads = Open3.pipeline_start "#{binary} files"
|
35
|
+
_, output, thread = Open3.popen2e "#{binary} ."
|
36
|
+
sleep 0.1 # waiting for Trap to be prepared
|
37
|
+
expect{ Process.kill "INT", thread.pid }.not_to raise_error,
|
38
|
+
->{ "couldn't kill process, waiting got ^C because: %p" % output.read }
|
39
|
+
string, status = output.read, thread.value
|
40
|
+
expect(string).to include("interrupted"),
|
41
|
+
"didn't tell about interruption"
|
42
|
+
expect(string).not_to include("Interrupt"),
|
43
|
+
"didn't trap SIGINT"
|
44
|
+
expect(status).to be_success
|
45
|
+
end
|
46
|
+
it "no params" do
|
47
|
+
string, status = Open3.capture2e "#{binary}"
|
48
|
+
expect(string).to include("usage")
|
49
|
+
expect(status).not_to be_success
|
9
50
|
end
|
51
|
+
it "unknown extension" do
|
52
|
+
# threads = Open3.pipeline "#{binary} unknown"
|
53
|
+
string, status = Open3.capture2e "#{binary} unknown"
|
54
|
+
expect(string).to include("Unknown file extension")
|
55
|
+
expect(status).not_to be_success
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "directory" do
|
59
|
+
let( :input_var){ [] }; def input setting = nil; input_var[0] = setting || input_var[0]; end
|
60
|
+
let(:output_var){ [] }; def output setting = nil; output_var[0] = setting || output_var[0]; end
|
61
|
+
let(:pid_var){ [] }
|
62
|
+
def read_moar
|
63
|
+
sleep 1 # otherwise we need rescue Errno::EAGAIN
|
64
|
+
IO.select [output]
|
65
|
+
string = ""
|
66
|
+
expect{ output.read_nonblock 100500, string }.not_to raise_error,
|
67
|
+
"unexpected error -- probably end of communication"
|
68
|
+
# rescue EOFError
|
69
|
+
string
|
70
|
+
end
|
71
|
+
before do
|
72
|
+
i, o, t = Open3.popen2e "#{binary} \"† †\""
|
73
|
+
input i
|
74
|
+
output o
|
75
|
+
pid_var[0] = t.pid
|
76
|
+
expect(read_moar).to include("is a directory")
|
77
|
+
end
|
78
|
+
it "empty command" do
|
79
|
+
input.puts ""
|
80
|
+
expect(read_moar).to include("WUT?")
|
81
|
+
end
|
82
|
+
it "bullshit command" do
|
83
|
+
input.puts "bullshit"
|
84
|
+
expect(read_moar).to include("WUT?")
|
85
|
+
end
|
86
|
+
describe "[a]rchive" do
|
87
|
+
before do
|
88
|
+
skip "tar isn't installed" unless `tar --version`[/^bsdtar 2\.8\.3 -/]
|
89
|
+
input.puts "a"
|
90
|
+
string = read_moar
|
91
|
+
expect(string).to include("Press Enter to proceed")
|
92
|
+
expect(string).to include("tar czf")
|
93
|
+
end
|
94
|
+
it "<ctrl> + C" do
|
95
|
+
Process.kill "INT", pid_var[0]
|
96
|
+
sleep 1
|
97
|
+
expect(File.exist?("† †.tar.gz")).to be_falsy
|
98
|
+
end
|
99
|
+
it "Enter" do
|
100
|
+
input.puts ?\n
|
101
|
+
expect(read_moar).to include("gzip compressed data")
|
102
|
+
expect(File.exist?("† †.tar.gz")).to be_truthy
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
10
107
|
end
|
data/spec/files/_spec.rb
CHANGED
data/spec/files/unknown
ADDED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ccu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- ccu.gemspec
|
72
72
|
- spec/_spec.rb
|
73
73
|
- spec/files/_spec.rb
|
74
|
+
- spec/files/unknown
|
74
75
|
homepage:
|
75
76
|
licenses:
|
76
77
|
- MIT
|
@@ -98,3 +99,4 @@ summary: Context Console Utility
|
|
98
99
|
test_files:
|
99
100
|
- spec/_spec.rb
|
100
101
|
- spec/files/_spec.rb
|
102
|
+
- spec/files/unknown
|