archiver 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,2 +1,9 @@
1
- rvm:
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
2
5
  - 1.9.3
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
data/Gemfile CHANGED
@@ -2,7 +2,6 @@
2
2
  # Copyright (c) 2012. All rights reserved.
3
3
 
4
4
  source 'http://rubygems.org'
5
- gem 'thor', '~> 0.14.6'
6
5
  gem 'exifr', '~> 1.1.2'
7
6
  gem 'progressbar', '~> 0.10.0'
8
7
 
data/Rakefile CHANGED
@@ -25,8 +25,8 @@ Jeweler::Tasks.new do |gem|
25
25
  gem.version = Archiver::Version::STRING
26
26
  gem.homepage = 'https://github.com/tbpro/archiver'
27
27
  gem.license = 'MIT'
28
- gem.summary = %Q{Archiver is a simple gem to rename photos and videos}
29
- gem.description = %Q{Archiver is a simple gem to rename photos and videos depending on creation date and exif informations and it sorts out duplicate files}
28
+ gem.summary = %Q{Archiver is a simple gem to rename photos and videos and archive them}
29
+ gem.description = %Q{Archiver is a simple gem to rename photos and videos depending on creation date and exif informations to archive directories in subfolders by year. It sorts out duplicate files to}
30
30
  gem.email = 'tboerger@tbpro.de'
31
31
  gem.authors = ['Thomas Boerger']
32
32
  end
data/archiver.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "archiver"
8
- s.version = "0.1.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Thomas Boerger"]
12
- s.date = "2012-03-18"
13
- s.description = "Archiver is a simple gem to rename photos and videos depending on creation date and exif informations and it sorts out duplicate files"
12
+ s.date = "2012-11-02"
13
+ s.description = "Archiver is a simple gem to rename photos and videos depending on creation date and exif informations to archive directories in subfolders by year. It sorts out duplicate files to"
14
14
  s.email = "tboerger@tbpro.de"
15
15
  s.executables = ["archiver"]
16
16
  s.extra_rdoc_files = [
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
18
18
  "README.md"
19
19
  ]
20
20
  s.files = [
21
- ".rvmrc",
22
21
  ".travis.yml",
23
22
  "Gemfile",
24
23
  "LICENSE.md",
@@ -27,34 +26,26 @@ Gem::Specification.new do |s|
27
26
  "archiver.gemspec",
28
27
  "bin/archiver",
29
28
  "lib/archiver.rb",
30
- "lib/archiver/action.rb",
31
- "lib/archiver/action/renaming.rb",
32
29
  "lib/archiver/cli.rb",
33
- "lib/archiver/error.rb",
34
- "lib/archiver/error/invalid_directory.rb",
35
- "lib/archiver/output.rb",
36
- "lib/archiver/output/cli.rb",
37
30
  "lib/archiver/record.rb",
38
31
  "lib/archiver/version.rb"
39
32
  ]
40
33
  s.homepage = "https://github.com/tbpro/archiver"
41
34
  s.licenses = ["MIT"]
42
35
  s.require_paths = ["lib"]
43
- s.rubygems_version = "1.8.10"
44
- s.summary = "Archiver is a simple gem to rename photos and videos"
36
+ s.rubygems_version = "1.8.24"
37
+ s.summary = "Archiver is a simple gem to rename photos and videos and archive them"
45
38
 
46
39
  if s.respond_to? :specification_version then
47
40
  s.specification_version = 3
48
41
 
49
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<thor>, ["~> 0.14.6"])
51
43
  s.add_runtime_dependency(%q<exifr>, ["~> 1.1.2"])
52
44
  s.add_runtime_dependency(%q<progressbar>, ["~> 0.10.0"])
53
45
  s.add_development_dependency(%q<redcarpet>, ["~> 2.1.0"])
54
46
  s.add_development_dependency(%q<yard>, ["~> 0.7.5"])
55
47
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
56
48
  else
57
- s.add_dependency(%q<thor>, ["~> 0.14.6"])
58
49
  s.add_dependency(%q<exifr>, ["~> 1.1.2"])
59
50
  s.add_dependency(%q<progressbar>, ["~> 0.10.0"])
60
51
  s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
@@ -62,7 +53,6 @@ Gem::Specification.new do |s|
62
53
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
63
54
  end
64
55
  else
65
- s.add_dependency(%q<thor>, ["~> 0.14.6"])
66
56
  s.add_dependency(%q<exifr>, ["~> 1.1.2"])
67
57
  s.add_dependency(%q<progressbar>, ["~> 0.10.0"])
68
58
  s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
data/bin/archiver CHANGED
@@ -3,11 +3,12 @@
3
3
  # Created by Thomas Boerger on 2012-03-16.
4
4
  # Copyright (c) 2012. All rights reserved.
5
5
 
6
- $:.push File.expand_path('../../lib', __FILE__)
7
-
8
6
  require 'rubygems'
9
- require 'archiver'
7
+ require 'bundler'
10
8
 
11
- trap('INT') { exit 0 }
9
+ Bundler.setup(:default)
10
+
11
+ $:.push File.expand_path('../../lib', __FILE__)
12
+ require 'archiver'
12
13
 
13
- Archiver::Cli.start
14
+ Archiver::Cli.new(ARGV, STDOUT, STDERR)
data/lib/archiver/cli.rb CHANGED
@@ -3,40 +3,111 @@
3
3
  # Created by Thomas Boerger on 2012-03-16.
4
4
  # Copyright (c) 2012. All rights reserved.
5
5
 
6
- require 'thor'
6
+ require 'optparse'
7
7
  require 'progressbar'
8
8
 
9
9
  module Archiver
10
- class Cli < Thor
11
- include Thor::Actions
10
+ class Cli
11
+ attr_accessor :stdout
12
+ attr_accessor :stderr
13
+ attr_accessor :config
14
+ attr_accessor :parser
15
+
16
+ def initialize(argv, stdout, stderr)
17
+ @stdout = stdout
18
+ @stderr = stderr
19
+
20
+ @config = {
21
+ :verbose => false
22
+ }
23
+
24
+ @parser = OptionParser.new do |opt|
25
+ opt.banner = "Usage: archiver [options] <fromdir> <intodir>"
26
+
27
+ opt.on("-V", "--verbose", "Verbose output format") do
28
+ @config[:verbose] = true
29
+ end
30
+
31
+ opt.on("-h", "--help", "Show this help message") do
32
+ puts @parser
33
+ exit 0
34
+ end
35
+
36
+ opt.on("-v", "--version", "Show current version") do
37
+ puts "archiver v#{Version::STRING}"
38
+ exit 0
39
+ end
40
+ end
41
+
42
+ unless argv.size == 2
43
+ puts @parser
44
+ exit 1
45
+ end
46
+
47
+ @config[:fromdir] = argv.shift
48
+ @config[:intodir] = argv.shift
49
+
50
+ @parser.parse!
51
+
52
+ checks
53
+ process
54
+ end
55
+
56
+ def checks
57
+ unless File.directory? config[:fromdir]
58
+ error "Fromdir does not exist"
59
+ end
12
60
 
13
- method_option :verbose, :type => :boolean, :aliases => '-V', :default => false
14
- method_option :source, :type => :string, :aliases => '-s', :default => '.'
61
+ unless File.directory? config[:intodir]
62
+ error "Intodir does not exist"
63
+ end
15
64
 
16
- desc 'renaming [DESTINATION]', 'Rename all files in the defined directory'
17
- def renaming(destination)
18
- source = options['source']
19
- verbose = options['verbose']
65
+ config[:fromdir_real] = File.realpath config[:fromdir]
66
+ config[:intodir_real] = File.realpath config[:intodir]
67
+ end
68
+
69
+ def process
70
+ unless config[:verbose]
71
+ progress = ProgressBar.new('Archiver', records.count)
72
+ end
20
73
 
21
- output = Archiver::Output::Cli.new(verbose)
22
-
23
- begin
24
- action = Archiver::Action::Renaming.new(
25
- source,
26
- destination,
27
- output
28
- )
29
-
30
- action.process
31
- rescue Archiver::Error::InvalidDirectory => e
32
- raise Thor::Error.new 'Directories does not exist!'
33
- rescue => e
34
- if verbose
35
- raise Thor::Error.new "Some action failed: #{e.message}"
74
+ records.each do |record|
75
+ next unless record.process?
76
+ record.move config[:intodir_real]
77
+
78
+ if config[:verbose]
79
+ puts "#{record.path} -> #{record.filename}"
36
80
  else
37
- raise Thor::Error.new 'Some action failed!'
81
+ progress.inc
38
82
  end
39
83
  end
84
+
85
+ if config[:verbose]
86
+ puts "Processed #{records.count} records!"
87
+ else
88
+ progress.finish
89
+ end
90
+ rescue SystemExit, Interrupt
91
+ progress.finish if progress
92
+ exit 1
93
+ end
94
+
95
+ def records
96
+ @records ||= begin
97
+ rows = []
98
+ Dir.glob(File.join(config[:fromdir_real], '**', '*')).each do |row|
99
+ next if File.directory? row
100
+ rows << Record.new(row)
101
+ end
102
+
103
+ rows
104
+ end
105
+ end
106
+
107
+ def error(message)
108
+ puts "Error: #{message}"
109
+ puts @parser
110
+ exit 1
40
111
  end
41
112
  end
42
113
  end
@@ -1,126 +1,134 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # Created by Thomas Boerger on 2012-03-16.
4
- # Copyright (c) 2012. All rights reserved.
5
-
6
- require 'exifr'
7
- require 'digest/md5'
8
-
9
- module Archiver
10
- class Record
11
- attr_accessor :path
12
-
13
- def initialize(path)
14
- @path = path
15
- end
16
-
17
- def filename(counter = 0)
18
- append = if counter > 0
19
- sprintf('-%03d', counter)
20
- else
21
- nil
22
- end
23
-
24
- [
25
- created.strftime('%Y%m%d-%H%M%S'),
26
- append,
27
- extension
28
- ].compact.join
29
- end
30
-
31
- def extension
32
- if mime_type.match /^image\/jpeg$/i
33
- return '.jpg'
34
- end
35
-
36
- if mime_type.match /^image\/gif$/i
37
- return '.gif'
38
- end
39
-
40
- if mime_type.match /^image\/png$/i
41
- return '.png'
42
- end
43
-
44
- if mime_type.match /^video\/3gpp$/i
45
- return '.mp4'
46
- end
47
-
48
- File.extname(path).downcase
49
- end
50
-
51
- def created
52
- if exif_data and exif_data.date_time_original
53
- exif_data.date_time_original
54
- else
55
- File.mtime(path)
56
- end
57
- end
58
-
59
- def checksum
60
- @checksum ||= Digest::MD5.hexdigest(File.read(path))
61
- end
62
-
63
- def mime_type
64
- @mime_type ||= mime_detect
65
- .split(';')
66
- .first
67
- .strip
68
- end
69
-
70
- def exif_data
71
- @exif_data ||= exif_detect
72
- end
73
-
74
- def process?
75
- image? or video?
76
- end
77
-
78
- def image?
79
- !!(mime_type.match /^image\/.*/i)
80
- end
81
-
82
- def video?
83
- !!(mime_type.match /^video\/.*/i)
84
- end
85
-
86
- def same?(other)
87
- if other.is_a? Record
88
- checksum == other.checksum
89
- else
90
- checksum == Digest::MD5.hexdigest(File.read(other))
91
- end
92
- end
93
-
94
- def move(directory, counter = 0)
95
- destination = File.join(directory, filename(counter))
96
-
97
- if File.exists? destination
98
- if same? destination
99
- FileUtils.rm_rf path
100
- else
101
- move(directory, counter + 1)
102
- end
103
- else
104
- FileUtils.cp path, destination
105
- FileUtils.rm_rf path
106
- end
107
- end
108
-
109
- protected
110
- def mime_detect
111
- `/usr/bin/env file --brief --mime "#{path}"`
112
- end
113
-
114
- def exif_detect
115
- if mime_type.match(/^image\/jpeg/i)
116
- return EXIFR::JPEG.new(path)
117
- end
118
-
119
- if mime_type.match(/^image\/tiff/i)
120
- return EXIFR::TIFF.new(path)
121
- end
122
-
123
- nil
124
- end
125
- end
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ # Created by Thomas Boerger on 2012-03-16.
4
+ # Copyright (c) 2012. All rights reserved.
5
+
6
+ require 'exifr'
7
+ require 'digest/md5'
8
+
9
+ module Archiver
10
+ class Record
11
+ attr_accessor :path
12
+
13
+ def initialize(path)
14
+ @path = path
15
+ end
16
+
17
+ def filename(counter = 0)
18
+ append = if counter > 0
19
+ sprintf('-%03d', counter)
20
+ else
21
+ nil
22
+ end
23
+
24
+ [
25
+ created.strftime('%Y%m%d-%H%M%S'),
26
+ append,
27
+ extension
28
+ ].compact.join
29
+ end
30
+
31
+ def extension
32
+ if mime_type.match /^image\/jpeg$/i
33
+ return '.jpg'
34
+ end
35
+
36
+ if mime_type.match /^image\/gif$/i
37
+ return '.gif'
38
+ end
39
+
40
+ if mime_type.match /^image\/png$/i
41
+ return '.png'
42
+ end
43
+
44
+ if mime_type.match /^video\/3gpp$/i
45
+ return '.mp4'
46
+ end
47
+
48
+ File.extname(path).downcase
49
+ end
50
+
51
+ def created
52
+ if exif_data and exif_data.date_time_original
53
+ exif_data.date_time_original
54
+ else
55
+ File.mtime(path)
56
+ end
57
+ end
58
+
59
+ def checksum
60
+ @checksum ||= Digest::MD5.hexdigest(File.read(path))
61
+ end
62
+
63
+ def mime_type
64
+ @mime_type ||= mime_detect
65
+ .split(';')
66
+ .first
67
+ .strip
68
+ end
69
+
70
+ def exif_data
71
+ @exif_data ||= exif_detect
72
+ end
73
+
74
+ def process?
75
+ image? or video?
76
+ end
77
+
78
+ def image?
79
+ !!(mime_type.match /^image\/.*/i)
80
+ end
81
+
82
+ def video?
83
+ !!(mime_type.match /^video\/.*/i)
84
+ end
85
+
86
+ def same?(other)
87
+ if other.is_a? Record
88
+ checksum == other.checksum
89
+ else
90
+ checksum == Digest::MD5.hexdigest(File.read(other))
91
+ end
92
+ end
93
+
94
+ def move(directory, counter = 0)
95
+ destination = File.join(directory, segment, filename(counter))
96
+
97
+ unless File.directory? File.dirname(destination)
98
+ FileUtils.mkdir_p File.dirname(destination)
99
+ end
100
+
101
+ if File.exists? destination
102
+ if same? destination
103
+ FileUtils.rm_rf path
104
+ else
105
+ move(directory, counter + 1)
106
+ end
107
+ else
108
+ FileUtils.cp path, destination
109
+ FileUtils.rm_rf path
110
+ end
111
+ end
112
+
113
+ def segment
114
+ created.strftime('%Y')
115
+ end
116
+
117
+ protected
118
+ def mime_detect
119
+ `/usr/bin/env file --brief --mime "#{path}"`
120
+ end
121
+
122
+ def exif_detect
123
+ if mime_type.match(/^image\/jpeg/i)
124
+ return EXIFR::JPEG.new(path)
125
+ end
126
+
127
+ if mime_type.match(/^image\/tiff/i)
128
+ return EXIFR::TIFF.new(path)
129
+ end
130
+
131
+ nil
132
+ end
133
+ end
126
134
  end
@@ -5,8 +5,8 @@
5
5
 
6
6
  module Archiver
7
7
  module Version
8
- MAJOR = 0
9
- MINOR = 1
8
+ MAJOR = 1
9
+ MINOR = 0
10
10
  PATCH = 0
11
11
  BUILD = nil
12
12
 
data/lib/archiver.rb CHANGED
@@ -6,8 +6,5 @@
6
6
  module Archiver
7
7
  autoload :Version, 'archiver/version'
8
8
  autoload :Cli, 'archiver/cli'
9
- autoload :Error, 'archiver/error'
10
- autoload :Action, 'archiver/action'
11
9
  autoload :Record, 'archiver/record'
12
- autoload :Output, 'archiver/output'
13
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archiver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-18 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: thor
16
- requirement: &70302533002720 !ruby/object:Gem::Requirement
15
+ name: exifr
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.14.6
21
+ version: 1.1.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70302533002720
25
- - !ruby/object:Gem::Dependency
26
- name: exifr
27
- requirement: &70302533001980 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
28
25
  none: false
29
26
  requirements:
30
27
  - - ~>
31
28
  - !ruby/object:Gem::Version
32
29
  version: 1.1.2
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70302533001980
36
30
  - !ruby/object:Gem::Dependency
37
31
  name: progressbar
38
- requirement: &70302533000800 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
34
  requirements:
41
35
  - - ~>
@@ -43,10 +37,15 @@ dependencies:
43
37
  version: 0.10.0
44
38
  type: :runtime
45
39
  prerelease: false
46
- version_requirements: *70302533000800
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.10.0
47
46
  - !ruby/object:Gem::Dependency
48
47
  name: redcarpet
49
- requirement: &70302532999960 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
50
49
  none: false
51
50
  requirements:
52
51
  - - ~>
@@ -54,10 +53,15 @@ dependencies:
54
53
  version: 2.1.0
55
54
  type: :development
56
55
  prerelease: false
57
- version_requirements: *70302532999960
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
58
62
  - !ruby/object:Gem::Dependency
59
63
  name: yard
60
- requirement: &70302532999420 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
61
65
  none: false
62
66
  requirements:
63
67
  - - ~>
@@ -65,10 +69,15 @@ dependencies:
65
69
  version: 0.7.5
66
70
  type: :development
67
71
  prerelease: false
68
- version_requirements: *70302532999420
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.7.5
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: jeweler
71
- requirement: &70302532998880 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
72
81
  none: false
73
82
  requirements:
74
83
  - - ~>
@@ -76,9 +85,15 @@ dependencies:
76
85
  version: 1.8.3
77
86
  type: :development
78
87
  prerelease: false
79
- version_requirements: *70302532998880
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.3
80
94
  description: Archiver is a simple gem to rename photos and videos depending on creation
81
- date and exif informations and it sorts out duplicate files
95
+ date and exif informations to archive directories in subfolders by year. It sorts
96
+ out duplicate files to
82
97
  email: tboerger@tbpro.de
83
98
  executables:
84
99
  - archiver
@@ -87,7 +102,6 @@ extra_rdoc_files:
87
102
  - LICENSE.md
88
103
  - README.md
89
104
  files:
90
- - .rvmrc
91
105
  - .travis.yml
92
106
  - Gemfile
93
107
  - LICENSE.md
@@ -96,13 +110,7 @@ files:
96
110
  - archiver.gemspec
97
111
  - bin/archiver
98
112
  - lib/archiver.rb
99
- - lib/archiver/action.rb
100
- - lib/archiver/action/renaming.rb
101
113
  - lib/archiver/cli.rb
102
- - lib/archiver/error.rb
103
- - lib/archiver/error/invalid_directory.rb
104
- - lib/archiver/output.rb
105
- - lib/archiver/output/cli.rb
106
114
  - lib/archiver/record.rb
107
115
  - lib/archiver/version.rb
108
116
  homepage: https://github.com/tbpro/archiver
@@ -120,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
128
  version: '0'
121
129
  segments:
122
130
  - 0
123
- hash: -885210058386209972
131
+ hash: 3630215323667943547
124
132
  required_rubygems_version: !ruby/object:Gem::Requirement
125
133
  none: false
126
134
  requirements:
@@ -129,8 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
137
  version: '0'
130
138
  requirements: []
131
139
  rubyforge_project:
132
- rubygems_version: 1.8.10
140
+ rubygems_version: 1.8.24
133
141
  signing_key:
134
142
  specification_version: 3
135
- summary: Archiver is a simple gem to rename photos and videos
143
+ summary: Archiver is a simple gem to rename photos and videos and archive them
136
144
  test_files: []
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3-head@archiver --create
@@ -1,61 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # Created by Thomas Boerger on 2012-03-16.
4
- # Copyright (c) 2012. All rights reserved.
5
-
6
- module Archiver
7
- module Action
8
- class Renaming
9
- attr_accessor :source
10
- attr_accessor :destination
11
- attr_accessor :output
12
-
13
- attr_accessor :records
14
-
15
- def initialize(source, destination, output)
16
- @source = source
17
- @destination = destination
18
- @output = output
19
-
20
- @records = []
21
-
22
- check_directories
23
- load_records
24
- end
25
-
26
- def process
27
- records.each do |record|
28
- next unless record.process?
29
-
30
- record.move destination
31
- output.process record
32
- end
33
-
34
- output.finish!
35
- end
36
-
37
- protected
38
- def check_directories
39
- unless File.directory? source
40
- raise Archiver::Error::InvalidDirectory
41
- end
42
-
43
- unless File.directory? destination
44
- raise Archiver::Error::InvalidDirectory
45
- end
46
-
47
- @source = File.realpath source
48
- @destination = File.realpath destination
49
- end
50
-
51
- def load_records
52
- Dir.glob([source, '**', '*'].join('/')).each do |record|
53
- next if File.directory? record
54
- @records << Archiver::Record.new(record)
55
- end
56
-
57
- output.count = records.count
58
- end
59
- end
60
- end
61
- end
@@ -1,10 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # Created by Thomas Boerger on 2012-03-16.
4
- # Copyright (c) 2012. All rights reserved.
5
-
6
- module Archiver
7
- module Action
8
- autoload :Renaming, 'archiver/action/renaming'
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # Created by Thomas Boerger on 2012-03-16.
4
- # Copyright (c) 2012. All rights reserved.
5
-
6
- module Archiver
7
- module Error
8
- class InvalidDirectory < StandardError
9
- end
10
- end
11
- end
@@ -1,10 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # Created by Thomas Boerger on 2012-03-16.
4
- # Copyright (c) 2012. All rights reserved.
5
-
6
- module Archiver
7
- module Error
8
- autoload :InvalidDirectory, 'archiver/error/invalid_directory'
9
- end
10
- end
@@ -1,46 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # Created by Thomas Boerger on 2012-03-16.
4
- # Copyright (c) 2012. All rights reserved.
5
-
6
- require 'progressbar'
7
-
8
- module Archiver
9
- class Output
10
- class Cli
11
- attr_accessor :verbose
12
- attr_accessor :count
13
- attr_accessor :working
14
- attr_accessor :progress
15
-
16
- def initialize(verbose)
17
- @verbose = verbose
18
- @count = 0
19
- @working = 0
20
- end
21
-
22
- def count=(value)
23
- @progress = ProgressBar.new('Archiver', value) unless verbose
24
- @count = value
25
- end
26
-
27
- def process(record)
28
- @working += 1
29
-
30
- if verbose
31
- puts "#{sprintf('%05d', @working)}/#{sprintf('%05d', count)}: #{record.path} -> #{record.filename}"
32
- else
33
- progress.inc
34
- end
35
- end
36
-
37
- def finish!
38
- if verbose
39
- puts "Processed #{count} records!"
40
- else
41
- progress.finish
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,10 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # Created by Thomas Boerger on 2012-03-16.
4
- # Copyright (c) 2012. All rights reserved.
5
-
6
- module Archiver
7
- class Output
8
- autoload :Cli, 'archiver/output/cli'
9
- end
10
- end