AbsoluteRenamer 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,94 +1,33 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/absolute_renamer/version", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{AbsoluteRenamer}
8
- s.version = "1.1.0"
5
+ s.name = "AbsoluteRenamer"
6
+ s.version = AbsoluteRenamer::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Simon COURTOIS"]
9
+ s.email = ["happynoff@free.fr"]
10
+ s.homepage = "http://github.com/simonc/AbsoluteRenamer"
11
+ s.summary = "AbsoluteRenamer is a very powerful tool that helps files " \
12
+ "and directories renaming using the Krename syntax."
13
+ s.description = "AbsoluteRenamer is a very powerful tool that helps files " \
14
+ "and directories renaming using the Krename syntax. Unlike " \
15
+ "many batch renaming tools, AbsoluteRenamer is able to " \
16
+ "rename folders. AbsoluteRenamer is modular and can be " \
17
+ "extended to adapt itself to any kind of file or to add " \
18
+ "new options and features."
9
19
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Simon COURTOIS"]
12
- s.date = %q{2009-11-02}
13
- s.default_executable = %q{absrenamer}
14
- s.description = %q{AbsoluteRenamer is a very powerful tool that helps files and directories renaming using the Krename syntax. Unlike many batch renaming tools, AbsoluteRenamer is able to rename folders. AbsoluteRenamer is modular and can be extended to adapt itself to any kind of file or to add new options and features.}
15
- s.email = %q{happynoff@free.fr}
16
- s.executables = ["absrenamer"]
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README.rdoc"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".gitignore",
24
- "AbsoluteRenamer.gemspec",
25
- "LICENSE",
26
- "README.rdoc",
27
- "Rakefile",
28
- "VERSION",
29
- "bin/absrenamer",
30
- "conf/absrenamer/absrenamer.conf",
31
- "lib/absolute_renamer.rb",
32
- "lib/absolute_renamer/config.rb",
33
- "lib/absolute_renamer/core-packages/core-case/module.rb",
34
- "lib/absolute_renamer/core-packages/core-general/module.rb",
35
- "lib/absolute_renamer/core-packages/core-general/parser.rb",
36
- "lib/absolute_renamer/core-packages/core-interactive/parser.rb",
37
- "lib/absolute_renamer/core-packages/core-interactive/plugin.rb",
38
- "lib/absolute_renamer/core-packages/core-listing/parser.rb",
39
- "lib/absolute_renamer/core-packages/core-listing/plugin.rb",
40
- "lib/absolute_renamer/core-packages/core-packages.rb",
41
- "lib/absolute_renamer/external.rb",
42
- "lib/absolute_renamer/file_info.rb",
43
- "lib/absolute_renamer/imodule.rb",
44
- "lib/absolute_renamer/iparser.rb",
45
- "lib/absolute_renamer/iplugin.rb",
46
- "lib/absolute_renamer/libs/file.rb",
47
- "lib/absolute_renamer/libs/hash.rb",
48
- "lib/absolute_renamer/libs/string.rb",
49
- "lib/absolute_renamer/parser.rb",
50
- "lib/absolute_renamer/use_config.rb",
51
- "lib/absolute_renamer/with_children.rb",
52
- "test/absolute_renamer_test.rb",
53
- "test/config_test.rb",
54
- "test/file_info_test.rb",
55
- "test/file_test.rb",
56
- "test/hash_test.rb",
57
- "test/imodule_test.rb",
58
- "test/iplugin_test.rb",
59
- "test/parser_test.rb",
60
- "test/string_test.rb",
61
- "test/test_helper.rb"
62
- ]
63
- s.homepage = %q{http://github.com/simonc/AbsoluteRenamer}
64
- s.rdoc_options = ["--charset=UTF-8"]
65
- s.require_paths = ["lib"]
66
- s.rubyforge_project = %q{absrenamer}
67
- s.rubygems_version = %q{1.3.5}
68
- s.summary = %q{AbsoluteRenamer is a very powerful tool that helps files and directories renaming using the Krename syntax.}
69
- s.test_files = [
70
- "test/string_test.rb",
71
- "test/file_test.rb",
72
- "test/iplugin_test.rb",
73
- "test/absolute_renamer_test.rb",
74
- "test/test_helper.rb",
75
- "test/config_test.rb",
76
- "test/hash_test.rb",
77
- "test/imodule_test.rb",
78
- "test/parser_test.rb",
79
- "test/file_info_test.rb"
80
- ]
20
+ s.required_rubygems_version = ">= 1.3.6"
21
+ s.rubyforge_project = "absrenamer"
22
+
23
+ s.add_development_dependency "bundler", ">= 1.0.0"
24
+ s.add_development_dependency "thoughtbot-shoulda", ">= 0"
81
25
 
82
- if s.respond_to? :specification_version then
83
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
84
- s.specification_version = 3
26
+ s.files = `git ls-files`.split("\n")
27
+ s.executables = `git ls-files`.split("\n").map {|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
28
+ s.require_path = 'lib'
29
+ s.test_files = `git ls-files`.split("\n").map{|f| f =~ /^test\/.*/ ? f : nil}.compact
30
+ s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
85
31
 
86
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
87
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
88
- else
89
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
90
- end
91
- else
92
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
93
- end
32
+ s.rdoc_options = ["--charset=UTF-8"]
94
33
  end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in AbsoluteRenamer.gemspec
4
+ gemspec
@@ -18,7 +18,9 @@ For instance, the following line will rename all IMG*.JPG files in photo_01.jpg,
18
18
 
19
19
  You can simply install AbsoluteRenamer with gem :
20
20
 
21
- sudo gem install simonc-AbsoluteRenamer
21
+ sudo gem install gemcutter
22
+ sudo gem tumble
23
+ sudo gem install AbsoluteRenamer
22
24
 
23
25
  == Documentation
24
26
 
data/Rakefile CHANGED
@@ -1,59 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "AbsoluteRenamer"
8
- gem.summary = %Q{AbsoluteRenamer is a very powerful tool that helps files and directories renaming using the Krename syntax.}
9
- gem.description = %Q{AbsoluteRenamer is a very powerful tool that helps files and directories renaming using the Krename syntax. \
10
- Unlike many batch renaming tools, AbsoluteRenamer is able to rename folders. \
11
- AbsoluteRenamer is modular and can be extended to adapt itself to any kind of file or to add new options and features.}
12
- gem.email = "happynoff@free.fr"
13
- gem.homepage = "http://github.com/simonc/AbsoluteRenamer"
14
- gem.authors = ["Simon COURTOIS"]
15
- gem.add_development_dependency "thoughtbot-shoulda"
16
- gem.rubyforge_project = "absrenamer"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
- end
22
-
23
- require 'rake/testtask'
24
- Rake::TestTask.new(:test) do |test|
25
- test.libs << 'lib' << 'test'
26
- test.pattern = 'test/**/*_test.rb'
27
- test.verbose = true
28
- end
29
-
30
- begin
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/*_test.rb'
35
- test.verbose = true
36
- end
37
- rescue LoadError
38
- task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
- end
41
- end
42
-
43
- task :test => :check_dependencies
44
-
45
- task :default => :test
46
-
47
- require 'rake/rdoctask'
48
- Rake::RDocTask.new do |rdoc|
49
- if File.exist?('VERSION')
50
- version = File.read('VERSION')
51
- else
52
- version = ""
53
- end
54
-
55
- rdoc.rdoc_dir = 'rdoc'
56
- rdoc.title = "AbsoluteRenamer #{version}"
57
- rdoc.rdoc_files.include('README*')
58
- rdoc.rdoc_files.include('lib/**/*.rb')
59
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -43,13 +43,11 @@ require 'absolute_renamer/config'
43
43
  require 'absolute_renamer/parser'
44
44
  require 'absolute_renamer/external'
45
45
 
46
- config_path = File.dirname(__FILE__)+'/../conf/absrenamer/absrenamer.conf'
47
- global_conf = '/etc/absrenamer/absrenamer.conf'
48
- custom_conf = '~/.absrenamerrc'
46
+ default_conf = File.dirname(__FILE__) + '/../conf/absrenamer/absrenamer.conf'
47
+ global_conf = '/etc/absrenamer/absrenamer.conf'
48
+ custom_conf = '~/.absrenamerrc'
49
49
 
50
- AbsoluteRenamer::Config.load(config_path)
51
- AbsoluteRenamer::Config.load(global_conf) if File.exists? global_conf
52
- AbsoluteRenamer::Config.load(custom_conf) if File.exists? custom_conf
50
+ AbsoluteRenamer::Config.load([default_conf, global_conf, custom_conf])
53
51
 
54
52
  AbsoluteRenamer::External.load_gems
55
53
  AbsoluteRenamer::External.load_core
@@ -1,4 +1,4 @@
1
- :debug: false
1
+ :debug: false
2
2
 
3
3
  :options:
4
4
  # Prompt :never, :once or :always before renaming
@@ -1,6 +1,6 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
1
+ $:.unshift(File.dirname(__FILE__))
3
2
 
3
+ require 'absolute_renamer/version'
4
4
  require 'absolute_renamer/config'
5
5
  require 'absolute_renamer/with_children'
6
6
  require 'absolute_renamer/external'
@@ -13,114 +13,110 @@ require 'absolute_renamer/use_config'
13
13
 
14
14
  # top level module of AbsoluteRenamer.
15
15
  module AbsoluteRenamer
16
- version_file_path = File.join(File.dirname(__FILE__), '/../VERSION')
17
- File.open(version_file_path) do |f|
18
- VERSION = f.read
19
- end
16
+ # The main class of AbsoluteRenamer.
17
+ #
18
+ # Organizes the files and directories renaming process.
19
+ class Processor
20
+ class << self
21
+ include AbsoluteRenamer::UseConfig
20
22
 
21
- # The main class of AbsoluteRenamer.
22
- #
23
- # Organizes the files and directories renaming process.
24
- class Processor
25
- class << self
26
- include AbsoluteRenamer::UseConfig
23
+ # Creates the new names for each file passed to AbsoluteRenamer.
24
+ #
25
+ # Asks to each module if it as something to replace
26
+ # in the name of each file.
27
+ #
28
+ # Calls the +before_names_generation+ entry point.
29
+ def create_names_list
30
+ call_entry_point(:before_names_generation)
27
31
 
28
- # Creates the new names for each file passed to AbsoluteRenamer.
29
- #
30
- # Asks to each module if he as something to replace
31
- # in the name of each file.
32
- #
33
- # Calls the +before_names_generation+ entry point.
34
- def create_names_list
35
- call_entry_point(:before_names_generation)
36
- return if conf[:files].empty?
37
- mods = {}
38
- conf[:files].each do |file|
39
- name = conf[:options][:format].clone
40
- ext = conf[:options][:ext_format].clone
41
- do_replacements(file.name, :before)
42
- AbsoluteRenamer::IModule.children.each do |mod|
43
- mod_sym = mod.symbol
44
- mods[mod_sym] ||= mod.new
45
- name = mods[mod_sym].process(file, name)
46
- ext = mods[mod_sym].process(file, ext, :ext) unless file.dir
47
- end
48
- do_replacements(name, :after)
49
- file.new_name = name
50
- file.new_name << '.' << ext unless (file.dir or file.ext.empty?)
51
- end
52
- if (conf[:options][:dir] and conf[:options][:rec])
53
- conf[:files].sort! { |a, b| AbsoluteRenamer::FileInfo.compare_level(a, b) }
54
- end
55
- mods.clear
56
- end
32
+ name_format = conf[:options][:format]
33
+ ext_format = conf[:options][:ext_format]
57
34
 
58
- # For each file/dir replaces his name by his new name.
59
- #
60
- # Calls the following entry points :
61
- # - before_batch_renaming ;
62
- # - before_file_renaming ;
63
- # - after_file_renaming ;
64
- # - after_batch_renaming.
65
- def do_renaming
66
- if call_entry_point(:before_batch_renaming)
67
- conf[:files].each do |file|
68
- if call_entry_point(:before_file_renaming, :file => file)
69
- if file.respond_to?(conf[:options][:mode])
70
- file.send(conf[:options][:mode])
71
- end
72
- call_entry_point(:after_file_renaming, :file => file)
73
- end
74
- end
75
- call_entry_point(:after_batch_renaming)
76
- end
77
- end
35
+ conf[:files].each do |file|
36
+ do_replacements(file.name, :before)
37
+ name, ext = AbsoluteRenamer::IModule.process(file, name_format.clone, ext_format.clone)
38
+ do_replacements(name, :after)
78
39
 
79
- # Loads the plugins list in the @plugins variable.
80
- def load_plugins
81
- @plugins = {}
82
- AbsoluteRenamer::IPlugin.children.each do |plugin|
83
- @plugins[plugin.symbol] = plugin.new
84
- end
85
- end
40
+ file.new_name = name
41
+ unless ext.empty? or file.dir or file.ext.empty? or conf[:options][:no_ext]
42
+ file.new_name << ".#{ext}"
43
+ end
44
+ end
86
45
 
87
- # Calls the given entry point for each plugin available
88
- #
89
- # Ask to each plugin if it implements the entry point
90
- # and calls it with params if it isn't null.
91
- # It keeps going will all plugins return true.
92
- #
93
- # returns true if all plugins returned true
94
- def call_entry_point(ep, params = nil)
95
- puts "Plugin Entry Point: #{ep}" if conf[:debug]
96
- keep_going = true
97
- @plugins.each_value do |plugin|
98
- if plugin.respond_to?(ep)
99
- keep_going &= params.nil? ? plugin.send(ep) : plugin.send(ep, params)
100
- end
101
- end
102
- keep_going
103
- end
46
+ conf[:files].sort! if (conf[:options][:dir] and conf[:options][:rec])
47
+ end
104
48
 
105
- # Applies replacements
106
- #
107
- # The replacements are stored in conf[options][replacements][moment]
108
- # and are provided as command line paramters.
109
- #
110
- # format represents the string in which the replacements are done
111
- # moment determines which replacements are done (on old or new name)
112
- def do_replacements(format, moment)
113
- begin
114
- replacements = conf[:options][:replacements][moment]
115
- rescue NoMethodError
116
- replacements = nil
117
- end
118
- unless replacements.nil?
119
- replacements.each do |repl|
120
- format.gsub!(repl[:pattern], repl[:replace])
121
- end
122
- end
49
+ # For each file/dir replaces his name by his new name.
50
+ #
51
+ # Calls the following entry points :
52
+ # - before_batch_renaming ;
53
+ # - before_file_renaming ;
54
+ # - after_file_renaming ;
55
+ # - after_batch_renaming.
56
+ def do_renaming
57
+ surround_with_entry_points(:batch_renaming) do
58
+ conf[:files].each do |file|
59
+ surround_with_entry_points(:file_renaming, :file => file) do
60
+ file.send(conf[:options][:mode]) if file.respond_to? conf[:options][:mode]
61
+ {:file => file}
123
62
  end
63
+ end
64
+ end
65
+ end
66
+
67
+ # Loads the plugins list in the @plugins variable.
68
+ def load_plugins
69
+ @plugins = {}
70
+ AbsoluteRenamer::IPlugin.children.each do |plugin|
71
+ @plugins[plugin.symbol] = plugin.new
72
+ end
73
+ end
74
+
75
+ def surround_with_entry_points(ep, params = nil)
76
+ if call_entry_point("before_#{ep}".to_sym, params)
77
+ result = yield
78
+ call_entry_point("after_#{ep}".to_sym, result)
79
+ end
80
+ end
81
+
82
+ # Calls the given entry point for each plugin available
83
+ #
84
+ # Ask to each plugin if it implements the entry point
85
+ # and calls it with params if it isn't null.
86
+ # It keeps going while all plugins return true.
87
+ #
88
+ # returns true if all plugins returned true
89
+ def call_entry_point(ep, params = nil)
90
+ puts "Plugin Entry Point: #{ep}" if conf[:debug]
91
+ keep_going = true
92
+ @plugins.each_value do |plugin|
93
+ if plugin.respond_to?(ep)
94
+ keep_going &= params.nil? ? plugin.send(ep) : plugin.send(ep, params)
95
+ end
96
+ end
97
+ keep_going
98
+ end
99
+
100
+ # Applies replacements
101
+ #
102
+ # The replacements are stored in conf[options][replacements][moment]
103
+ # and are provided as command line paramters.
104
+ #
105
+ # format represents the string in which the replacements are done
106
+ # moment determines which replacements are done (on old or new name)
107
+ def do_replacements(format, moment)
108
+ begin
109
+ replacements = conf[:options][:replacements][moment]
110
+ rescue NoMethodError
111
+ replacements = nil
112
+ end
113
+
114
+ unless replacements.nil?
115
+ replacements.each do |repl|
116
+ format.gsub!(repl[:pattern], repl[:replace])
117
+ end
124
118
  end
119
+ end
125
120
  end
121
+ end
126
122
  end
@@ -1,44 +1,53 @@
1
1
  require 'yaml'
2
2
 
3
3
  module AbsoluteRenamer
4
- # Class handeling the configuration.
5
- class Config
6
- class << self
7
- # Open and load a Yaml file into the +@conf+ variable.
8
- # config_path: path of the file to load.
9
- def load(config_path)
10
- @conf ||= {}
4
+ # Class handeling the configuration.
5
+ class Config
6
+ class << self
7
+ # Opens and loads a list of Yaml files into the +@conf+ variable.
8
+ # config_paths: list of files to load.
9
+ def load(config_paths)
10
+ @conf ||= {
11
+ :options => {
12
+ :dots => 1,
13
+ :ext_format => '$',
14
+ :format => '$',
15
+ :interactive => :never,
16
+ :maxdepth => 0,
17
+ :mode => :rename
18
+ }
19
+ }
11
20
 
12
- if tmp_conf = YAML::load_file(config_path)
13
- @conf.deep_merge! tmp_conf
14
- end
15
-
16
- @conf[:options] ||= {}
17
- @conf[:options][:format] ||= '$'
18
- @conf[:options][:ext_format] ||= '$'
21
+ config_paths.each do |conf_file|
22
+ if File.exists?(conf_file)
23
+ if tmp_conf = YAML::load_file(conf_file)
24
+ @conf.deep_merge!(tmp_conf)
19
25
  end
26
+ end
27
+ end
28
+ end
20
29
 
21
- # Returns a configuration value identified by +key+.
22
- # If +key+ is ignored, returns the +@conf+ hash.
23
- def get(key = nil)
24
- return @conf[key] if (key and @conf.has_key?(key))
25
- return @conf if key.nil?
26
- end
30
+ # Returns a configuration value identified by +key+.
31
+ # If +key+ is ignored, returns the +@conf+ hash.
32
+ def get(key = nil)
33
+ return @conf[key] if (key and @conf.has_key?(key))
34
+ return @conf if key.nil?
35
+ end
27
36
 
28
- # Sets a configuration value in the +@conf+ variable.
29
- def set(key, value = '')
30
- @conf[key] = value unless key.nil?
31
- end
37
+ # Sets a configuration value in the +@conf+ variable.
38
+ def set(key, value = '')
39
+ @conf[key] = value unless key.nil?
40
+ end
32
41
 
33
- # Returns a configuration value identified by +key+.
34
- def [](key)
35
- @conf[key]
36
- end
42
+ # Returns a configuration value identified by +key+.
43
+ def [](key)
44
+ @conf[key]
45
+ end
37
46
 
38
- # Sets a configuration value in the +@conf+ variable.
39
- def []=(key, value)
40
- @conf[key] = value
41
- end
42
- end
47
+ # Sets a configuration value in the +@conf+ variable.
48
+ def []=(key, value)
49
+ @conf[key] = value
50
+ end
43
51
  end
44
- end
52
+ end
53
+ end