tartlet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +29 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +114 -0
- data/README.rdoc +115 -0
- data/Rakefile +61 -0
- data/bin/tartlet +95 -0
- data/features/step_definitions/tartlet_steps.rb +146 -0
- data/features/support/env.rb +22 -0
- data/features/tartlet.feature +39 -0
- data/lib/tartlet.rb +37 -0
- data/lib/tartlet/version.rb +3 -0
- data/tartlet.gemspec +115 -0
- data/test/tc_something.rb +7 -0
- metadata +164 -0
data/.gitignore
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
results.html
|
2
|
+
pkg
|
3
|
+
html
|
4
|
+
|
5
|
+
*.gem
|
6
|
+
*.rbc
|
7
|
+
.bundle
|
8
|
+
.config
|
9
|
+
coverage
|
10
|
+
InstalledFiles
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
23
|
+
|
24
|
+
## generic files to ignore
|
25
|
+
*~
|
26
|
+
*.lock
|
27
|
+
*.DS_Store
|
28
|
+
*.swp
|
29
|
+
*.out
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jake M
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Tartlet
|
2
|
+
|
3
|
+
A wrapper for tar that provides sensible defaults
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Tar horror stories. Everyone has one. You used the wrong flags and accidentally
|
8
|
+
overwrote one of your source files without a backup. Or you extracted a tarball
|
9
|
+
over your current directory and deleted half the updates to your project. You
|
10
|
+
spent 30 minutes scouring Google for the right set of flags to extract a zipped
|
11
|
+
tarball instead of an unzipped one. Why are there so many flags!?!
|
12
|
+
|
13
|
+
Enter Tartlet. Tartlet is a small commandline wrapper around tar that handles
|
14
|
+
the obnoxious flags for you. Need to extract an archive?
|
15
|
+
|
16
|
+
tartlet extract thinmints.tar.gz
|
17
|
+
|
18
|
+
Mmmmmmm. Delicious extracted cookies. Need to compress a set of files?
|
19
|
+
|
20
|
+
tartlet compress butter sugar flour --output cookie
|
21
|
+
|
22
|
+
Mmmmmmmmm. Chocolaty compressed cookies. Tartlet makes it easy to make archives
|
23
|
+
(and apparently I'm craving cookies- please hold).
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
|
28
|
+
Install via gem as:
|
29
|
+
|
30
|
+
$ gem install tart
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Tartlet takes a command and then a list of files, with optional flags thrown
|
35
|
+
anywhere.
|
36
|
+
|
37
|
+
### Commands
|
38
|
+
|
39
|
+
* `compress` - takes a list of files, and by default compresses them into
|
40
|
+
gzipped tarball `archive.tar.gz`
|
41
|
+
|
42
|
+
ex:
|
43
|
+
|
44
|
+
$ tartlet compress foo bar baz
|
45
|
+
|
46
|
+
***TODO***: do a clobbering check before making the tarball to ensure file
|
47
|
+
safety
|
48
|
+
|
49
|
+
* `extract` - takes a single zipped tarball and extracts it into the current
|
50
|
+
directory
|
51
|
+
|
52
|
+
ex:
|
53
|
+
|
54
|
+
$ tartlet extract archive.tar.gz
|
55
|
+
|
56
|
+
***TODO***: take a list of tarballs and extract them each into their own
|
57
|
+
folder
|
58
|
+
|
59
|
+
***TODO***: do a clobbering check before extracting the tarball to ensure
|
60
|
+
file safety
|
61
|
+
|
62
|
+
### Options
|
63
|
+
|
64
|
+
Options can be placed anywhere in the command, eg. `tartlet -d compress -o
|
65
|
+
target file1 file2` is the same as `tartlet compress file1 file2 -d -o target`
|
66
|
+
which is the same as `tartlet compress -d file1 -o target file2`. I prefer to
|
67
|
+
put -d before the command, -t after the command but before the files, and -o at
|
68
|
+
the very end, but put them in whatever order makes sense to you.
|
69
|
+
|
70
|
+
* `-o VALUE`, `--output VALUE` - instead of using the default output
|
71
|
+
(archive.tar.gz or the current directory), direct output to **VALUE**. For
|
72
|
+
compression archive name, tartlet will automatically append the proper file
|
73
|
+
suffix (.tar or .tar.gz) if it is not already provided.
|
74
|
+
|
75
|
+
ex:
|
76
|
+
|
77
|
+
# extract contents of archive into folder 'dirname'
|
78
|
+
$ tartlet extract archive.tar.gz -o dirname
|
79
|
+
|
80
|
+
# compress list of files into tarball 'files.tar.gz'
|
81
|
+
$ tartlet compress foo bar baz -o files.tar.gz
|
82
|
+
-- or --
|
83
|
+
$ tartlet compress foo bar baz -o files
|
84
|
+
|
85
|
+
* `--tarball`, `-tar`, or `-t` - treat tarball as not-gzipped, e.g.
|
86
|
+
`archive.tar` (vs the default assumption of a gzipped tarball, eg
|
87
|
+
`archive.tar.gz`)
|
88
|
+
|
89
|
+
ex:
|
90
|
+
|
91
|
+
# extract contents of archive into current directory
|
92
|
+
$ tartlet extract --tarball archive.tar
|
93
|
+
|
94
|
+
# compress files into non-zipped tarball
|
95
|
+
$ tartlet compress --tarball foo bar baz
|
96
|
+
|
97
|
+
* `--dry-run`, `--dry`, `-d` - don't execute any commands, simply print to
|
98
|
+
stdout the tar command that would be produced by tartlet
|
99
|
+
|
100
|
+
ex:
|
101
|
+
|
102
|
+
$ tartlet --dry compress foo bar baz --tarball -o files
|
103
|
+
tar -cf files.tar foo bar baz
|
104
|
+
|
105
|
+
$ tartlet extract --dry-run lotsoffiles.tar.gz -o safefolder
|
106
|
+
tar -xzf lotsoffiles.tar.gz -C safefolder
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
1. Fork it
|
111
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
112
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
113
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
114
|
+
5. Create new Pull Request
|
data/README.rdoc
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
= tartlet - a wrapper for tar that provides sensible defaults
|
2
|
+
|
3
|
+
Author:: Jacob Maskiewicz (jakemaskiewicz@gmail.com)
|
4
|
+
Copyright:: Copyright (c) 2013 Jacob Maskiewicz
|
5
|
+
|
6
|
+
|
7
|
+
== Description
|
8
|
+
|
9
|
+
Tar horror stories. Everyone has one. You used the wrong flags and accidentally
|
10
|
+
overwrote one of your source files without a backup. Or you extracted a tarball
|
11
|
+
over your current directory and deleted half the updates to your project. You
|
12
|
+
spent 30 minutes scouring Google for the right set of flags to extract a zipped
|
13
|
+
tarball instead of an unzipped one. Why are there so many flags!?!
|
14
|
+
|
15
|
+
Enter Tartlet. Tartlet is a small commandline wrapper around tar that handles
|
16
|
+
the obnoxious flags for you. Need to extract an archive?
|
17
|
+
|
18
|
+
tartlet extract thinmints.tar.gz
|
19
|
+
|
20
|
+
Mmmmmmm. Delicious extracted cookies. Need to compress a set of files?
|
21
|
+
|
22
|
+
tartlet compress butter sugar flour --output cookie
|
23
|
+
|
24
|
+
Mmmmmmmmm. Chocolaty compressed cookies. Tartlet makes it easy to make archives
|
25
|
+
(and apparently I'm craving cookies- please hold).
|
26
|
+
|
27
|
+
== Installation
|
28
|
+
|
29
|
+
|
30
|
+
Install via gem as:
|
31
|
+
|
32
|
+
$ gem install tart
|
33
|
+
|
34
|
+
== Usage
|
35
|
+
|
36
|
+
Tartlet takes a command and then a list of files, with optional flags thrown
|
37
|
+
anywhere.
|
38
|
+
|
39
|
+
=== Commands
|
40
|
+
|
41
|
+
* <tt>compress</tt> - takes a list of files, and by default compresses them into gzipped tarball <tt>archive.tar.gz</tt>
|
42
|
+
|
43
|
+
ex:
|
44
|
+
|
45
|
+
$ tartlet compress foo bar baz
|
46
|
+
|
47
|
+
***TODO***: do a clobbering check before making the tarball to ensure file
|
48
|
+
safety
|
49
|
+
|
50
|
+
* <tt>extract</tt> - takes a single zipped tarball and extracts it into the current directory
|
51
|
+
|
52
|
+
ex:
|
53
|
+
|
54
|
+
$ tartlet extract archive.tar.gz
|
55
|
+
|
56
|
+
***TODO***: take a list of tarballs and extract them each into their own
|
57
|
+
folder
|
58
|
+
|
59
|
+
***TODO***: do a clobbering check before extracting the tarball to ensure
|
60
|
+
file safety
|
61
|
+
|
62
|
+
=== Options
|
63
|
+
|
64
|
+
Options can be placed anywhere in the command, eg. <tt>tartlet -d compress -o
|
65
|
+
target file1 file2</tt> is the same as <tt>tartlet compress file1 file2 -d -o target</tt>
|
66
|
+
which is the same as <tt>tartlet compress -d file1 -o target file2</tt>. I prefer to
|
67
|
+
put -d before the command, -t after the command but before the files, and -o at
|
68
|
+
the very end, but put them in whatever order makes sense to you.
|
69
|
+
|
70
|
+
* <tt>-o VALUE</tt>, <tt>--output VALUE</tt> - instead of using the default output (archive.tar.gz or the current directory), direct output to **VALUE**. For compression archive name, tartlet will automatically append the proper file suffix (.tar or .tar.gz) if it is not already provided.
|
71
|
+
|
72
|
+
ex:
|
73
|
+
|
74
|
+
# extract contents of archive into folder 'dirname'
|
75
|
+
$ tartlet extract archive.tar.gz -o dirname
|
76
|
+
|
77
|
+
# compress list of files into tarball 'files.tar.gz'
|
78
|
+
$ tartlet compress foo bar baz -o files.tar.gz
|
79
|
+
-- or --
|
80
|
+
$ tartlet compress foo bar baz -o files
|
81
|
+
|
82
|
+
* <tt>--tarball</tt>, <tt>-tar</tt>, or <tt>-t</tt> - treat tarball as not-gzipped, e.g. <tt>archive.tar</tt> (vs the default assumption of a gzipped tarball, eg <tt>archive.tar.gz</tt>)
|
83
|
+
|
84
|
+
ex:
|
85
|
+
|
86
|
+
# extract contents of archive into current directory
|
87
|
+
$ tartlet extract --tarball archive.tar
|
88
|
+
|
89
|
+
# compress files into non-zipped tarball
|
90
|
+
$ tartlet compress --tarball foo bar baz
|
91
|
+
|
92
|
+
* <tt>--dry-run</tt>, <tt>--dry</tt>, <tt>-d</tt> - don't execute any commands, simply print to stdout the tar command that would be produced by tartlet
|
93
|
+
|
94
|
+
ex:
|
95
|
+
|
96
|
+
$ tartlet --dry compress foo bar baz --tarball -o files
|
97
|
+
tar -cf files.tar foo bar baz
|
98
|
+
|
99
|
+
$ tartlet extract --dry-run lotsoffiles.tar.gz -o safefolder
|
100
|
+
tar -xzf lotsoffiles.tar.gz -C safefolder
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
== Links
|
105
|
+
|
106
|
+
* {Source on Github}[https://github.com/jakemask/tartlet]
|
107
|
+
* RDoc[LINK TO RDOC.INFO]
|
108
|
+
|
109
|
+
== Contributing
|
110
|
+
|
111
|
+
1. Fork the {Github Source}[https://github.com/jakemask/tartlet]
|
112
|
+
2. Create your feature branch (<tt>git checkout -b my-new-feature</tt>)
|
113
|
+
3. Commit your changes (<tt>git commit -am 'Added some feature'</tt>)
|
114
|
+
4. Push to the branch (<tt>git push origin my-new-feature</tt>)
|
115
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
def dump_load_path
|
2
|
+
puts $LOAD_PATH.join("\n")
|
3
|
+
found = nil
|
4
|
+
$LOAD_PATH.each do |path|
|
5
|
+
if File.exists?(File.join(path,"rspec"))
|
6
|
+
puts "Found rspec in #{path}"
|
7
|
+
if File.exists?(File.join(path,"rspec","core"))
|
8
|
+
puts "Found core"
|
9
|
+
if File.exists?(File.join(path,"rspec","core","rake_task"))
|
10
|
+
puts "Found rake_task"
|
11
|
+
found = path
|
12
|
+
else
|
13
|
+
puts "!! no rake_task"
|
14
|
+
end
|
15
|
+
else
|
16
|
+
puts "!!! no core"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
if found.nil?
|
21
|
+
puts "Didn't find rspec/core/rake_task anywhere"
|
22
|
+
else
|
23
|
+
puts "Found in #{path}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
require 'bundler'
|
27
|
+
require 'rake/clean'
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
|
31
|
+
require 'cucumber'
|
32
|
+
require 'cucumber/rake/task'
|
33
|
+
gem 'rdoc' # we need the installed RDoc gem, not the system one
|
34
|
+
require 'rdoc/task'
|
35
|
+
|
36
|
+
include Rake::DSL
|
37
|
+
|
38
|
+
Bundler::GemHelper.install_tasks
|
39
|
+
|
40
|
+
|
41
|
+
Rake::TestTask.new do |t|
|
42
|
+
t.pattern = 'test/tc_*.rb'
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
CUKE_RESULTS = 'results.html'
|
47
|
+
CLEAN << CUKE_RESULTS
|
48
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
49
|
+
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
|
50
|
+
t.fork = false
|
51
|
+
end
|
52
|
+
|
53
|
+
Rake::RDocTask.new do |rd|
|
54
|
+
|
55
|
+
rd.main = "README.rdoc"
|
56
|
+
|
57
|
+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
58
|
+
end
|
59
|
+
|
60
|
+
task :default => [:test,:features]
|
61
|
+
|
data/bin/tartlet
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'methadone'
|
5
|
+
require 'tartlet.rb'
|
6
|
+
|
7
|
+
class App
|
8
|
+
include Methadone::Main
|
9
|
+
include Methadone::CLILogging
|
10
|
+
include Methadone::SH
|
11
|
+
|
12
|
+
COMMANDS = %w(compress extract)
|
13
|
+
|
14
|
+
main do |command, *files| # Add args you want: |like,so|
|
15
|
+
|
16
|
+
##
|
17
|
+
# Begin Execution
|
18
|
+
case command
|
19
|
+
|
20
|
+
## Compress the list of files into the outfile
|
21
|
+
when "compress"
|
22
|
+
|
23
|
+
# When compressing, the -o option changed where the tarball goes
|
24
|
+
outfile = options['output'].nil? ? Tartlet::OUTFILE : options['output']
|
25
|
+
|
26
|
+
# Get the tar command
|
27
|
+
cmd = Tartlet::compressSingle(files,!options['tarball'],outfile)
|
28
|
+
|
29
|
+
# Either output or run the command
|
30
|
+
if options['dry'] then puts cmd else sh cmd end
|
31
|
+
|
32
|
+
## Extract the tarballs into their respective folders
|
33
|
+
when "extract"
|
34
|
+
|
35
|
+
# If we have several files, we need several tar commands (later)
|
36
|
+
if files.length > 1
|
37
|
+
|
38
|
+
# TODO allow for multiple files
|
39
|
+
help_now!("One file at a time, bub!")
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
# Simply extract the only file in the current directory
|
44
|
+
target = options['output'].nil? ? Tartlet::TARGET : options['output']
|
45
|
+
|
46
|
+
# Get the tar command
|
47
|
+
cmd = Tartlet::extractSingle(files[0],!options['tarball'],target)
|
48
|
+
|
49
|
+
# Either output or run the command
|
50
|
+
if options['dry'] then puts cmd else sh cmd end
|
51
|
+
|
52
|
+
end
|
53
|
+
else
|
54
|
+
help_now!("#{command} is not a valid command. Must be one of {#{COMMANDS.join(",")}}")
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# supplemental methods here
|
61
|
+
|
62
|
+
# Declare command-line interface here
|
63
|
+
|
64
|
+
# Accept flags via:
|
65
|
+
# on("--flag VAL","Some flag")
|
66
|
+
# options[flag] will contain VAL
|
67
|
+
#
|
68
|
+
# Specify switches via:
|
69
|
+
# on("--[no-]switch","Some switch")
|
70
|
+
#
|
71
|
+
# Or, just call OptionParser methods on opts
|
72
|
+
#
|
73
|
+
# Require an argument
|
74
|
+
# arg :some_arg
|
75
|
+
#
|
76
|
+
# # Make an argument optional
|
77
|
+
# arg :optional_arg, :optional
|
78
|
+
|
79
|
+
version Tartlet::VERSION
|
80
|
+
|
81
|
+
description 'Wrapper for tar that provides sensible options'
|
82
|
+
|
83
|
+
on("-o VALUE","--output","Output location if different than current directory");
|
84
|
+
on("-t","--tar","--tarball","Do not gzip the tarball after compressing")
|
85
|
+
on("-d","--dry","--dry-run","Do not execute any commands, simply output the commands that would be used.")
|
86
|
+
|
87
|
+
arg :command, "Command to use (#{COMMANDS.join("|")})"
|
88
|
+
|
89
|
+
arg :files, :many, "list of files to act on"
|
90
|
+
|
91
|
+
#use_log_level_option
|
92
|
+
|
93
|
+
go!
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# Default list of files
|
2
|
+
FILES = %w(foo bar baz)
|
3
|
+
TMP = "tmp/aruba"
|
4
|
+
|
5
|
+
##
|
6
|
+
# doTarball
|
7
|
+
#
|
8
|
+
# takes a path to a tarball, and flags for creating said tarball. It will create
|
9
|
+
# a tarball at the given location with files foo, bar, and baz inside.
|
10
|
+
#
|
11
|
+
def doTarball(tarball,zip = true)
|
12
|
+
|
13
|
+
# Save the tarball and file list for later use
|
14
|
+
@tarball = tarball
|
15
|
+
@files = FILES
|
16
|
+
|
17
|
+
# Think out that directory
|
18
|
+
tar_dir = File.dirname(tarball)
|
19
|
+
archive = File.basename(tarball)
|
20
|
+
|
21
|
+
# Go to the directory and make that tarball
|
22
|
+
FileUtils.chdir File.join(TMP,tar_dir),:verbose => true do
|
23
|
+
|
24
|
+
# Confirm the file doesn't exist before touching
|
25
|
+
@files.each do |f|
|
26
|
+
File.exists?(f).should == false
|
27
|
+
FileUtils.touch f, :verbose => true
|
28
|
+
File.exists?(f).should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
# Tar up dem files
|
32
|
+
sh "tar -c#{zip ? 'z' : ''}f #{archive} #{@files.join(' ')}";
|
33
|
+
File.exists?(archive).should == true
|
34
|
+
|
35
|
+
# Remove dem files
|
36
|
+
@files.each do |f|
|
37
|
+
File.exists?(f).should == true
|
38
|
+
FileUtils.rm f, :verbose => true
|
39
|
+
File.exists?(f).should == false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
File.exists?(File.join(TMP,tar_dir,archive)).should == true
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Given 'a zipped tarball "x"'
|
48
|
+
#
|
49
|
+
# creates zipped tarball x with files foo, bar, and baz
|
50
|
+
#
|
51
|
+
Given(/^a zipped tarball "(.*?)"$/) do |tarball|
|
52
|
+
doTarball(tarball,true)
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Given 'a tarball "x"'
|
57
|
+
#
|
58
|
+
# creates tarball x with files foo, bar, and baz
|
59
|
+
#
|
60
|
+
Given(/^a tarball "(.*?)"$/) do |tarball|
|
61
|
+
doTarball(tarball,false)
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Then 'the files should be extracted in the directory "x"'
|
66
|
+
#
|
67
|
+
# asserts that files foo, bar, and baz are present in the given directory
|
68
|
+
#
|
69
|
+
Then(/^the files should be extracted in the directory "(.*?)"$/) do |dir|
|
70
|
+
|
71
|
+
#go to the directory and determine that each file exists
|
72
|
+
Dir.chdir File.join(TMP,dir) do
|
73
|
+
@files.each do |file|
|
74
|
+
File.exist?(file).should == true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Given 'a list of files "x" at "y"'
|
81
|
+
#
|
82
|
+
# creates files from space delimited list x in directory y
|
83
|
+
#
|
84
|
+
Given(/^a list of files "(.*?)"$/) do |files|
|
85
|
+
|
86
|
+
# Save dem files
|
87
|
+
@files = files.split(' ')
|
88
|
+
|
89
|
+
# Go to dat folder
|
90
|
+
Dir.chdir TMP do
|
91
|
+
|
92
|
+
# For each file, touch it
|
93
|
+
@files.each do |f|
|
94
|
+
File.exists?(f).should == false
|
95
|
+
FileUtils.touch f, :verbose => true
|
96
|
+
File.exists?(f).should == true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# filesInTarball
|
103
|
+
#
|
104
|
+
# Determines that a tarball has @files in it when extracted with given flags.
|
105
|
+
#
|
106
|
+
def filesInTarball(tarball,zip=true)
|
107
|
+
|
108
|
+
#get the directory and the filename
|
109
|
+
tar_dir = File.dirname(tarball)
|
110
|
+
archive = File.basename(tarball)
|
111
|
+
|
112
|
+
#rejoin for the real path
|
113
|
+
targz = File.join(tar_dir,archive)
|
114
|
+
|
115
|
+
#dat targz should exist
|
116
|
+
File.exists?(File.join(TMP,targz)).should == true
|
117
|
+
|
118
|
+
#go to the directory
|
119
|
+
FileUtils.chdir File.join(TMP,tar_dir), :verbose => true do
|
120
|
+
|
121
|
+
# Extract the files
|
122
|
+
files = `tar -t#{zip ? 'z' : ''}f #{archive}`.split("\n");
|
123
|
+
|
124
|
+
(files.sort == @files.sort).should == true
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# Then 'the files should be compressed into a zipped tarball at "x"'
|
132
|
+
#
|
133
|
+
# Determines that the zipped tarball contains @files
|
134
|
+
#
|
135
|
+
Then(/^the files should be compressed into a zipped tarball at "(.*?)"$/) do |tarball|
|
136
|
+
filesInTarball(tarball,true)
|
137
|
+
end
|
138
|
+
|
139
|
+
##
|
140
|
+
# Then 'the files should be compressed into a tarball at "x"'
|
141
|
+
#
|
142
|
+
# Determines that the tarball contains @files
|
143
|
+
#
|
144
|
+
Then(/^the files should be compressed into a tarball at "(.*?)"$/) do |tarball|
|
145
|
+
filesInTarball(tarball,false)
|
146
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
require 'methadone/cucumber'
|
3
|
+
|
4
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
5
|
+
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
|
6
|
+
|
7
|
+
Before do
|
8
|
+
# Using "announce" causes massive warnings on 1.9.2
|
9
|
+
@puts = true
|
10
|
+
@original_rubylib = ENV['RUBYLIB']
|
11
|
+
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
12
|
+
|
13
|
+
@base_dir = FileUtils.pwd
|
14
|
+
|
15
|
+
FileUtils.rm_rf "tmp/aruba", :verbose => true
|
16
|
+
FileUtils.mkdir_p "tmp/aruba", :verbose => true
|
17
|
+
end
|
18
|
+
|
19
|
+
After do
|
20
|
+
ENV['RUBYLIB'] = @original_rubylib
|
21
|
+
FileUtils.chdir @base_dir, :verbose => true
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: Sane Use of tar
|
2
|
+
In order to compress a set of files into a tarball or extract files from a tarball
|
3
|
+
I want a simple command
|
4
|
+
So I don't have to remember tar flags
|
5
|
+
|
6
|
+
Scenario: Basic UI
|
7
|
+
When I get help for "tartlet"
|
8
|
+
Then the exit status should be 0
|
9
|
+
And the banner should be present
|
10
|
+
And there should be a one line summary of what the app does
|
11
|
+
And the banner should include the version
|
12
|
+
And the banner should document that this app takes options
|
13
|
+
And the following options should be documented:
|
14
|
+
|--version|
|
15
|
+
|--output|
|
16
|
+
|--tarball|
|
17
|
+
And the banner should document that this app's arguments are:
|
18
|
+
|command|which is required|
|
19
|
+
|files|which is many|
|
20
|
+
|
21
|
+
Scenario: Extract Zipped Tarball
|
22
|
+
Given a zipped tarball "archive.tar.gz"
|
23
|
+
When I successfully run `tartlet extract archive.tar.gz`
|
24
|
+
Then the files should be extracted in the directory "."
|
25
|
+
|
26
|
+
Scenario: Extract Tarball
|
27
|
+
Given a tarball "archive.tar"
|
28
|
+
When I successfully run `tartlet --tar extract archive.tar`
|
29
|
+
Then the files should be extracted in the directory "."
|
30
|
+
|
31
|
+
Scenario: Compress Zipped Tarball
|
32
|
+
Given a list of files "foo bar baz"
|
33
|
+
When I successfully run `tartlet compress foo bar baz`
|
34
|
+
Then the files should be compressed into a zipped tarball at "archive.tar.gz"
|
35
|
+
|
36
|
+
Scenario: Compress Tarball
|
37
|
+
Given a list of files "foo bar baz"
|
38
|
+
When I successfully run `tartlet --tar compress foo bar baz`
|
39
|
+
Then the files should be compressed into a tarball at "archive.tar"
|
data/lib/tartlet.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "tartlet/version"
|
2
|
+
|
3
|
+
module Tartlet
|
4
|
+
|
5
|
+
OUTFILE = "archive"
|
6
|
+
TARGET = "."
|
7
|
+
|
8
|
+
def Tartlet.extractSingle(file, zip = true, target = TARGET)
|
9
|
+
|
10
|
+
# Generate the command
|
11
|
+
command = "tar -x#{zip ? 'z' : ''}f #{file}"
|
12
|
+
|
13
|
+
# Add the new target destination
|
14
|
+
command += " -C #{target}" unless target == "."
|
15
|
+
|
16
|
+
# Output or Run
|
17
|
+
return command
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def Tartlet.compressSingle(files, zip = true, target = OUTFILE)
|
23
|
+
|
24
|
+
# Add the .tar if it's not there
|
25
|
+
target += ".tar" if target[/(\.tar)(\.gz)?\z/].nil?
|
26
|
+
|
27
|
+
# Add the .gz if it's not there and we're zipping
|
28
|
+
target += ".gz" if target[/\.(gz)\z/].nil? and zip
|
29
|
+
|
30
|
+
# Generate the command
|
31
|
+
command = "tar -c#{zip ? 'z' : ''}f #{target} #{files.join(' ')}"
|
32
|
+
|
33
|
+
# Output or Run
|
34
|
+
return command
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/tartlet.gemspec
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/tartlet/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jake M"]
|
6
|
+
gem.email = ["jakemaskiewicz@gmail.com"]
|
7
|
+
gem.description = %q{
|
8
|
+
## Description
|
9
|
+
|
10
|
+
Tar horror stories. Everyone has one. You used the wrong flags and accidentally
|
11
|
+
overwrote one of your source files without a backup. Or you extracted a tarball
|
12
|
+
over your current directory and deleted half the updates to your project. You
|
13
|
+
spent 30 minutes scouring Google for the right set of flags to extract a zipped
|
14
|
+
tarball instead of an unzipped one. Why are there so many flags!?!
|
15
|
+
|
16
|
+
Enter Tartlet. Tartlet is a small commandline wrapper around tar that handles
|
17
|
+
the obnoxious flags for you. Need to extract an archive?
|
18
|
+
|
19
|
+
tartlet extract thinmints.tar.gz
|
20
|
+
|
21
|
+
Mmmmmmm. Delicious extracted cookies. Need to compress a set of files?
|
22
|
+
|
23
|
+
tartlet compress butter sugar flour --output cookie
|
24
|
+
|
25
|
+
Mmmmmmmmm. Chocolaty compressed cookies. Tartlet makes it easy to make archives
|
26
|
+
(and apparently I'm craving cookies- please hold).
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
|
31
|
+
Install via gem as:
|
32
|
+
|
33
|
+
$ gem install tart
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
Tartlet takes a command and then a list of files, with optional flags thrown
|
38
|
+
anywhere.
|
39
|
+
|
40
|
+
### Commands
|
41
|
+
|
42
|
+
* `compress` - takes a list of files, and by default compresses them into
|
43
|
+
gzipped tarball `archive.tar.gz`
|
44
|
+
|
45
|
+
ex:
|
46
|
+
|
47
|
+
$ tartlet compress foo bar baz
|
48
|
+
|
49
|
+
* `extract` - takes a single zipped tarball and extracts it into the current
|
50
|
+
directory
|
51
|
+
|
52
|
+
ex:
|
53
|
+
|
54
|
+
$ tartlet extract archive.tar.gz
|
55
|
+
|
56
|
+
### Options
|
57
|
+
|
58
|
+
Options can be placed anywhere in the command, eg. `tartlet -d compress -o
|
59
|
+
target file1 file2` is the same as `tartlet compress file1 file2 -d -o target`
|
60
|
+
which is the same as `tartlet compress -d file1 -o target file2`. I prefer to
|
61
|
+
put -d before the command, -t after the command but before the files, and -o at
|
62
|
+
the very end, but put them in whatever order makes sense to you.
|
63
|
+
|
64
|
+
* `-o VALUE`, `--output VALUE` - instead of using the default output
|
65
|
+
(archive.tar.gz or the current directory), direct output to **VALUE**. For
|
66
|
+
compression archive name, tartlet will automatically append the proper file
|
67
|
+
suffix (.tar or .tar.gz) if it is not already provided.
|
68
|
+
|
69
|
+
ex:
|
70
|
+
|
71
|
+
# extract contents of archive into folder 'dirname'
|
72
|
+
$ tartlet extract archive.tar.gz -o dirname
|
73
|
+
|
74
|
+
# compress list of files into tarball 'files.tar.gz'
|
75
|
+
$ tartlet compress foo bar baz -o files.tar.gz
|
76
|
+
-- or --
|
77
|
+
$ tartlet compress foo bar baz -o files
|
78
|
+
|
79
|
+
* `--tarball`, `-tar`, or `-t` - treat tarball as not-gzipped, e.g.
|
80
|
+
`archive.tar` (vs the default assumption of a gzipped tarball, eg
|
81
|
+
`archive.tar.gz`)
|
82
|
+
|
83
|
+
ex:
|
84
|
+
|
85
|
+
# extract contents of archive into current directory
|
86
|
+
$ tartlet extract --tarball archive.tar
|
87
|
+
|
88
|
+
# compress files into non-zipped tarball
|
89
|
+
$ tartlet compress --tarball foo bar baz
|
90
|
+
|
91
|
+
* `--dry-run`, `--dry`, `-d` - don't execute any commands, simply print to
|
92
|
+
stdout the tar command that would be produced by tartlet
|
93
|
+
|
94
|
+
ex:
|
95
|
+
|
96
|
+
$ tartlet --dry compress foo bar baz --tarball -o files
|
97
|
+
tar -cf files.tar foo bar baz
|
98
|
+
|
99
|
+
$ tartlet extract --dry-run lotsoffiles.tar.gz -o safefolder
|
100
|
+
tar -xzf lotsoffiles.tar.gz -C safefolder
|
101
|
+
}
|
102
|
+
gem.summary = %q{A wrapper for tar that provides sensible defaults}
|
103
|
+
gem.homepage = "https://github.com/jakemask/tartlet"
|
104
|
+
|
105
|
+
gem.files = `git ls-files`.split($\)
|
106
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
107
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
108
|
+
gem.name = "tartlet"
|
109
|
+
gem.require_paths = ["lib"]
|
110
|
+
gem.version = Tartlet::VERSION
|
111
|
+
gem.add_development_dependency('rdoc')
|
112
|
+
gem.add_development_dependency('aruba')
|
113
|
+
gem.add_development_dependency('rake', '~> 0.9.2')
|
114
|
+
gem.add_dependency('methadone', '~> 1.2.6')
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tartlet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jake M
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rdoc
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: aruba
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: methadone
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.2.6
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.2.6
|
78
|
+
description: ! "\n## Description\n\nTar horror stories. Everyone has one. You used
|
79
|
+
the wrong flags and accidentally\noverwrote one of your source files without a backup.
|
80
|
+
Or you extracted a tarball\nover your current directory and deleted half the updates
|
81
|
+
to your project. You\nspent 30 minutes scouring Google for the right set of flags
|
82
|
+
to extract a zipped\ntarball instead of an unzipped one. Why are there so many flags!?!\n\nEnter
|
83
|
+
Tartlet. Tartlet is a small commandline wrapper around tar that handles\nthe obnoxious
|
84
|
+
flags for you. Need to extract an archive?\n\n tartlet extract thinmints.tar.gz\n\nMmmmmmm.
|
85
|
+
Delicious extracted cookies. Need to compress a set of files?\n\n tartlet compress
|
86
|
+
butter sugar flour --output cookie\n\nMmmmmmmmm. Chocolaty compressed cookies. Tartlet
|
87
|
+
makes it easy to make archives\n(and apparently I'm craving cookies- please hold).\n\n##
|
88
|
+
Installation\n\n\nInstall via gem as:\n\n $ gem install tart\n\n## Usage\n\nTartlet
|
89
|
+
takes a command and then a list of files, with optional flags thrown\nanywhere.\n\n###
|
90
|
+
Commands\n\n* `compress` - takes a list of files, and by default compresses them
|
91
|
+
into\ngzipped tarball `archive.tar.gz`\n\n ex:\n\n $ tartlet compress
|
92
|
+
foo bar baz\n\n* `extract` - takes a single zipped tarball and extracts it into
|
93
|
+
the current\ndirectory\n\n ex:\n\n $ tartlet extract archive.tar.gz\n\n###
|
94
|
+
Options\n\nOptions can be placed anywhere in the command, eg. `tartlet -d compress
|
95
|
+
-o\ntarget file1 file2` is the same as `tartlet compress file1 file2 -d -o target`\nwhich
|
96
|
+
is the same as `tartlet compress -d file1 -o target file2`. I prefer to\nput -d
|
97
|
+
before the command, -t after the command but before the files, and -o at\nthe very
|
98
|
+
end, but put them in whatever order makes sense to you.\n\n* `-o VALUE`, `--output
|
99
|
+
VALUE` - instead of using the default output\n(archive.tar.gz or the current directory),
|
100
|
+
direct output to **VALUE**. For\ncompression archive name, tartlet will automatically
|
101
|
+
append the proper file\nsuffix (.tar or .tar.gz) if it is not already provided.\n\n
|
102
|
+
\ ex:\n\n # extract contents of archive into folder 'dirname'\n $
|
103
|
+
tartlet extract archive.tar.gz -o dirname\n\n # compress list of files into
|
104
|
+
tarball 'files.tar.gz'\n $ tartlet compress foo bar baz -o files.tar.gz\n
|
105
|
+
\ -- or --\n $ tartlet compress foo bar baz -o files\n\n* `--tarball`,
|
106
|
+
`-tar`, or `-t` - treat tarball as not-gzipped, e.g.\n`archive.tar` (vs the default
|
107
|
+
assumption of a gzipped tarball, eg\n`archive.tar.gz`)\n\n ex:\n\n # extract
|
108
|
+
contents of archive into current directory\n $ tartlet extract --tarball
|
109
|
+
archive.tar\n\n # compress files into non-zipped tarball\n $ tartlet
|
110
|
+
compress --tarball foo bar baz\n\n* `--dry-run`, `--dry`, `-d` - don't execute any
|
111
|
+
commands, simply print to\nstdout the tar command that would be produced by tartlet\n\n
|
112
|
+
\ ex:\n\n $ tartlet --dry compress foo bar baz --tarball -o files\n tar
|
113
|
+
-cf files.tar foo bar baz\n\n $ tartlet extract --dry-run lotsoffiles.tar.gz
|
114
|
+
-o safefolder\n tar -xzf lotsoffiles.tar.gz -C safefolder\n "
|
115
|
+
email:
|
116
|
+
- jakemaskiewicz@gmail.com
|
117
|
+
executables:
|
118
|
+
- tartlet
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files: []
|
121
|
+
files:
|
122
|
+
- .gitignore
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- README.rdoc
|
127
|
+
- Rakefile
|
128
|
+
- bin/tartlet
|
129
|
+
- features/step_definitions/tartlet_steps.rb
|
130
|
+
- features/support/env.rb
|
131
|
+
- features/tartlet.feature
|
132
|
+
- lib/tartlet.rb
|
133
|
+
- lib/tartlet/version.rb
|
134
|
+
- tartlet.gemspec
|
135
|
+
- test/tc_something.rb
|
136
|
+
homepage: https://github.com/jakemask/tartlet
|
137
|
+
licenses: []
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.8.25
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: A wrapper for tar that provides sensible defaults
|
160
|
+
test_files:
|
161
|
+
- features/step_definitions/tartlet_steps.rb
|
162
|
+
- features/support/env.rb
|
163
|
+
- features/tartlet.feature
|
164
|
+
- test/tc_something.rb
|