ddollar-sweeper 0.1.1
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.
- data/README +0 -0
- data/bin/sweep +20 -0
- data/lib/core_ext/fixnum.rb +7 -0
- data/lib/sweeper/sweeper.rb +54 -0
- data/lib/sweeper.rb +49 -0
- metadata +59 -0
data/README
ADDED
File without changes
|
data/bin/sweep
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'sweeper'))
|
4
|
+
|
5
|
+
if ARGV.length < 1 || !File.exists?(ARGV.first)
|
6
|
+
puts "usage: sweep <path>"
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
|
10
|
+
SWEEP_PATH = ARGV.first
|
11
|
+
|
12
|
+
SWEEPERS = {
|
13
|
+
'_Day' => 1.day,
|
14
|
+
'_Week' => 1.week,
|
15
|
+
'_Month' => 1.month,
|
16
|
+
'_Trash' => 2.months
|
17
|
+
}
|
18
|
+
|
19
|
+
sweeper = Sweeper::Engine.new(SWEEPERS)
|
20
|
+
sweeper.sweep(SWEEP_PATH)
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class Fixnum
|
2
|
+
def minute; self * 60; end; def minutes; minute; end
|
3
|
+
def hour; self * 60.minutes; end; def hours; hour; end
|
4
|
+
def day; self * 24.hours; end; def days; day; end
|
5
|
+
def week; self * 7.days; end; def weeks; week; end
|
6
|
+
def month; self * 30.days; end; def months; month; end
|
7
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Sweeper
|
5
|
+
class Engine
|
6
|
+
|
7
|
+
def initialize(sweepers)
|
8
|
+
@sweepers = sweepers
|
9
|
+
end
|
10
|
+
|
11
|
+
def sweep(path)
|
12
|
+
|
13
|
+
@sweep_path = path
|
14
|
+
@sweepers_by_path = {}
|
15
|
+
@sweepers_by_interval = []
|
16
|
+
|
17
|
+
@sweepers.each do |sweeper, interval|
|
18
|
+
sweeper_path = File.join(path, sweeper)
|
19
|
+
FileUtils.mkdir_p(sweeper_path)
|
20
|
+
@sweepers_by_path[sweeper_path] = interval
|
21
|
+
@sweepers_by_interval << [interval, sweeper_path]
|
22
|
+
end
|
23
|
+
|
24
|
+
@sweepers_by_interval = @sweepers_by_path.to_a.sort_by { |s| s[1] }.reverse
|
25
|
+
|
26
|
+
sweep_path(path)
|
27
|
+
@sweepers.each do |dir, interval|
|
28
|
+
sweep_path(File.join(path, dir))
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
private ##################################################################
|
34
|
+
|
35
|
+
def sweep_path(path)
|
36
|
+
|
37
|
+
Dir[File.join(path, '*')].each do |file|
|
38
|
+
next if @sweepers_by_path[file]
|
39
|
+
atime = File.new(file).atime
|
40
|
+
file_sweeper = @sweep_path
|
41
|
+
@sweepers_by_interval.each do |sweeper, interval|
|
42
|
+
if (Time.now - interval) > atime
|
43
|
+
file_sweeper = sweeper
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
new_path = File.join(file_sweeper, File.basename(file))
|
48
|
+
File.rename(file, new_path) unless file == new_path
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/lib/sweeper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Equivalent to a header guard in C/C++
|
2
|
+
# Used to prevent the class/module from being loaded more than once
|
3
|
+
unless defined? Sweeper
|
4
|
+
|
5
|
+
module Sweeper
|
6
|
+
|
7
|
+
# :stopdoc:
|
8
|
+
VERSION = '0.1.1'
|
9
|
+
LIBPATH = File.expand_path(File.dirname(__FILE__)) + File::SEPARATOR
|
10
|
+
PATH = File.dirname(LIBPATH) + File::SEPARATOR
|
11
|
+
# :startdoc:
|
12
|
+
|
13
|
+
# Returns the version string for the library.
|
14
|
+
#
|
15
|
+
def self.version
|
16
|
+
VERSION
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns the library path for the module. If any arguments are given,
|
20
|
+
# they will be joined to the end of the libray path using
|
21
|
+
# <tt>File.join</tt>.
|
22
|
+
#
|
23
|
+
def self.libpath( *args )
|
24
|
+
args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the lpath for the module. If any arguments are given,
|
28
|
+
# they will be joined to the end of the path using
|
29
|
+
# <tt>File.join</tt>.
|
30
|
+
#
|
31
|
+
def self.path( *args )
|
32
|
+
args.empty? ? PATH : ::File.join(PATH, *args)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Utility method used to rquire all files ending in .rb that lie in the
|
36
|
+
# directory below this file that has the same name as the filename passed
|
37
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
38
|
+
# the _filename_ does not have to be equivalent to the directory.
|
39
|
+
#
|
40
|
+
def self.require_all_libs_relative_to(fname)
|
41
|
+
search_me = File.expand_path(File.join(File.dirname(fname), '**', '*.rb'))
|
42
|
+
Dir.glob(search_me).sort.each { |rb| require rb }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
Sweeper.require_all_libs_relative_to __FILE__
|
48
|
+
|
49
|
+
end # unless defined?
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ddollar-sweeper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Dollar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: ddollar@gmail.com
|
18
|
+
executables:
|
19
|
+
- sweep
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- bin/sweep
|
26
|
+
- lib/core_ext
|
27
|
+
- lib/core_ext/fixnum.rb
|
28
|
+
- lib/sweeper
|
29
|
+
- lib/sweeper/sweeper.rb
|
30
|
+
- lib/sweeper.rb
|
31
|
+
- README
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://peervoice.com/software/sweeper
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project: sweeper
|
54
|
+
rubygems_version: 1.2.0
|
55
|
+
signing_key:
|
56
|
+
specification_version: 2
|
57
|
+
summary: Sweep a directory into subdirectories by age
|
58
|
+
test_files: []
|
59
|
+
|