geoffreywiseman-prune 1.2.0 → 1.3.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 +7 -0
- data/Rakefile +1 -1
- data/lib/prune/archiver.rb +32 -2
- data/lib/prune/meta.rb +4 -1
- data/lib/prune/pruner.rb +3 -1
- data/spec/pruner_spec.rb +2 -2
- metadata +13 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89c920f4af989a1bba3db2478a1237a3cc0603b2
|
4
|
+
data.tar.gz: a6ad83bb456149beafbea78df830742be3129b78
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00b0dfc00922b298475fc4e69e3c7c22c9a6ade2af0faffc8a24547888af4e3977003293ff4644034f7ef2b4b57a78c651c1db311907d0358e4f8fc7f08a5865
|
7
|
+
data.tar.gz: 44ed5f208033ba8c1fd4e070a264a633c2c126905ff163076389e342b42e53d621c53678d6f15a04cb6d9541499a95e5b0e6067d53017a8e86fae058409546ec
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ end
|
|
23
23
|
spec = Gem::Specification.new do |spec|
|
24
24
|
spec.name = 'geoffreywiseman-prune'
|
25
25
|
spec.version = Prune::VERSION
|
26
|
-
spec.date =
|
26
|
+
spec.date = Prune::RELEASE_DATE
|
27
27
|
spec.summary = 'Prunes files from a folder based on a retention policy, often time-based.'
|
28
28
|
spec.description = 'Prune is meant to analyze a folder full of files, run them against a retention policy and decide which to keep, which to remove and which to archive. It is extensible and embeddable.'
|
29
29
|
spec.author = 'Geoffrey Wiseman'
|
data/lib/prune/archiver.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/ruby
|
2
2
|
require 'rubygems'
|
3
3
|
require 'date'
|
4
4
|
require 'zlib'
|
@@ -8,18 +8,28 @@ include Archive::Tar
|
|
8
8
|
|
9
9
|
module Prune
|
10
10
|
|
11
|
-
# Responsible for making or updating archives based on a list of files.
|
11
|
+
# Responsible for making or updating archives based on a list of files.
|
12
12
|
#
|
13
13
|
# This is essentially a wrapper around tar/zlib.
|
14
14
|
class Archiver
|
15
|
+
|
16
|
+
# The destination folder to which archives will be written.
|
15
17
|
attr_reader :destination
|
16
18
|
|
19
|
+
# Initialize an archiver.
|
20
|
+
#
|
21
|
+
# @param [string] source the source folder from which files should be archived.
|
22
|
+
# @param [boolean] verbose indicates if the output should be verbose
|
23
|
+
# @param [string, nil] destination The destination folder to which archives should be written.
|
17
24
|
def initialize( destination, source, verbose )
|
18
25
|
@source = source
|
19
26
|
@verbose = verbose
|
20
27
|
@destination = destination || get_default_dir
|
21
28
|
end
|
22
29
|
|
30
|
+
# Get the default directory for the archiver, based on the source folder, but with '-archives' appended.
|
31
|
+
#
|
32
|
+
# @return the default directory
|
23
33
|
def get_default_dir
|
24
34
|
absolute = File.expand_path @source
|
25
35
|
path = File.dirname absolute
|
@@ -27,6 +37,9 @@ module Prune
|
|
27
37
|
File.join( path, "#{name}-archives" )
|
28
38
|
end
|
29
39
|
|
40
|
+
# Make the destination directory by creating it if it doesn't already exist.
|
41
|
+
#
|
42
|
+
# @raise IOError if the folder doesn't exist and can't be created
|
30
43
|
def make_destination_dir
|
31
44
|
begin
|
32
45
|
Dir.mkdir @destination unless File.exists? @destination
|
@@ -35,10 +48,19 @@ module Prune
|
|
35
48
|
end
|
36
49
|
end
|
37
50
|
|
51
|
+
# Get a list of all filenames that are not directories within a root folder.
|
52
|
+
#
|
53
|
+
# @param [String] root the folder in which to look for files
|
54
|
+
# @return an array of folders
|
38
55
|
def get_filenames( root )
|
39
56
|
Dir.entries( root ).map { |tmpfile| File.join( root, tmpfile ) }.reject { |path| File.directory? path }
|
40
57
|
end
|
41
58
|
|
59
|
+
# Update an archive file by adding additional files to it. This is done by extracting the contents to a
|
60
|
+
# temporary folder, then reassembling the archive with the existing and new contents.
|
61
|
+
#
|
62
|
+
# @param [String] archive_path the path to the archive file
|
63
|
+
# @param [Array] paths a list of paths to include in the archive
|
42
64
|
def update_archive( archive_path, paths )
|
43
65
|
puts "Archive file #{archive_path} exists." if @verbose
|
44
66
|
Dir.mktmpdir do |tmp_dir|
|
@@ -52,12 +74,20 @@ module Prune
|
|
52
74
|
end
|
53
75
|
end
|
54
76
|
|
77
|
+
# Create a new archive file, and add some files to it.
|
78
|
+
#
|
79
|
+
# @param [String] archive_path the full filename of the archive file to be created
|
80
|
+
# @param [Array] paths the paths of the files to add to the archive
|
55
81
|
def create_archive( archive_path, paths )
|
56
82
|
tgz = Zlib::GzipWriter.new( File.open( archive_path, 'wb' ) )
|
57
83
|
Minitar.pack( paths, tgz )
|
58
84
|
puts "Compressed #{paths.size} file(s) into #{archive_path} archive." if @verbose
|
59
85
|
end
|
60
86
|
|
87
|
+
# Archive a group of files by creating an archive or updating an existing one.
|
88
|
+
#
|
89
|
+
# @param [String] group_name the name of the group , which will be used in deciding the name of the archive
|
90
|
+
# @param [Array] files the files to be added to the archive
|
61
91
|
def archive( group_name, files )
|
62
92
|
make_destination_dir
|
63
93
|
archive_path = File.join( @destination, "archive-#{group_name}.tar.gz")
|
data/lib/prune/meta.rb
CHANGED
@@ -5,5 +5,8 @@
|
|
5
5
|
# @author Geoffrey Wiseman
|
6
6
|
module Prune
|
7
7
|
# The version of the prune gem and all the associated code.
|
8
|
-
VERSION = Gem::Version.new '1.
|
8
|
+
VERSION = Gem::Version.new '1.3.0'
|
9
|
+
|
10
|
+
# The release date associated with the version
|
11
|
+
RELEASE_DATE = '2016-06-24'
|
9
12
|
end
|
data/lib/prune/pruner.rb
CHANGED
@@ -93,8 +93,10 @@ module Prune
|
|
93
93
|
"No files categorized to be removed."
|
94
94
|
else
|
95
95
|
paths = files.map { |file| File.join folder_name, file }
|
96
|
+
|
96
97
|
begin
|
97
|
-
|
98
|
+
paths.each { |path| FileUtils.remove_entry( path, true ) }
|
99
|
+
|
98
100
|
"#{files.size} file(s) deleted"
|
99
101
|
rescue
|
100
102
|
raise IOError, "Could not remove file(s): #{$!}"
|
data/spec/pruner_spec.rb
CHANGED
@@ -118,12 +118,12 @@ describe Prune::Pruner do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should delete file" do
|
121
|
-
|
121
|
+
FileUtils.should_receive( :remove_entry ).with( File.join( PRUNE_PATH, FILENAME ), true )
|
122
122
|
subject.prune PRUNE_PATH
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should display file deleted message" do
|
126
|
-
|
126
|
+
FileUtils.should_receive( :remove_entry ).with( File.join( PRUNE_PATH, FILENAME ), true )
|
127
127
|
subject.prune PRUNE_PATH
|
128
128
|
@messages.should include_match( /file\(s\) deleted/ )
|
129
129
|
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoffreywiseman-prune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Geoffrey Wiseman
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: minitar
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.5.3
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.5.3
|
30
27
|
description: Prune is meant to analyze a folder full of files, run them against a
|
@@ -36,6 +33,10 @@ executables:
|
|
36
33
|
extensions: []
|
37
34
|
extra_rdoc_files: []
|
38
35
|
files:
|
36
|
+
- Rakefile
|
37
|
+
- UNLICENSE
|
38
|
+
- bin/prune
|
39
|
+
- lib/prune.rb
|
39
40
|
- lib/prune/archiver.rb
|
40
41
|
- lib/prune/category.rb
|
41
42
|
- lib/prune/cli.rb
|
@@ -45,7 +46,6 @@ files:
|
|
45
46
|
- lib/prune/meta.rb
|
46
47
|
- lib/prune/pruner.rb
|
47
48
|
- lib/prune/retention.rb
|
48
|
-
- lib/prune.rb
|
49
49
|
- spec/archiver_spec.rb
|
50
50
|
- spec/cli_spec.rb
|
51
51
|
- spec/configurer_spec.rb
|
@@ -53,34 +53,27 @@ files:
|
|
53
53
|
- spec/pruner_spec.rb
|
54
54
|
- spec/retention_spec.rb
|
55
55
|
- spec/spec_helper.rb
|
56
|
-
- bin/prune
|
57
|
-
- Rakefile
|
58
|
-
- UNLICENSE
|
59
56
|
homepage: http://geoffreywiseman.github.com/prune
|
60
57
|
licenses: []
|
58
|
+
metadata: {}
|
61
59
|
post_install_message:
|
62
60
|
rdoc_options: []
|
63
61
|
require_paths:
|
64
62
|
- lib
|
65
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
64
|
requirements:
|
68
|
-
- -
|
65
|
+
- - ">="
|
69
66
|
- !ruby/object:Gem::Version
|
70
67
|
version: '0'
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
hash: -394753839533755841
|
74
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
69
|
requirements:
|
77
|
-
- -
|
70
|
+
- - ">="
|
78
71
|
- !ruby/object:Gem::Version
|
79
72
|
version: '0'
|
80
73
|
requirements: []
|
81
74
|
rubyforge_project:
|
82
|
-
rubygems_version:
|
75
|
+
rubygems_version: 2.2.2
|
83
76
|
signing_key:
|
84
|
-
specification_version:
|
77
|
+
specification_version: 4
|
85
78
|
summary: Prunes files from a folder based on a retention policy, often time-based.
|
86
79
|
test_files: []
|