fixnames 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +2 -0
- data/COPYING +18 -0
- data/LICENSE.txt +20 -0
- data/README.md +28 -0
- data/README.rdoc +17 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/bin/fixdirs +148 -0
- data/bin/fixnames +148 -0
- data/fixnames.gemspec +92 -0
- data/lib/fixnames.rb +12 -0
- data/lib/fixnames/debug.rb +43 -0
- data/lib/fixnames/engine.rb +86 -0
- data/lib/fixnames/engine/scan_dir.rb +34 -0
- data/lib/fixnames/filters.rb +79 -0
- data/lib/fixnames/helpers.rb +41 -0
- data/lib/fixnames/interface.rb +41 -0
- data/lib/fixnames/option.rb +163 -0
- data/lib/fixnames/version.rb +10 -0
- data/spec/fixnames/banners_spec.rb +36 -0
- data/spec/fixnames/brackets_spec.rb +26 -0
- data/spec/fixnames/camelcase_spec.rb +24 -0
- data/spec/fixnames/charstrip_spec.rb +20 -0
- data/spec/fixnames/checksums_spec.rb +29 -0
- data/spec/fixnames/fixdots_spec.rb +35 -0
- data/spec/fixnames/hack_and_spec.rb +24 -0
- data/spec/fixnames/lowercase_spec.rb +28 -0
- data/spec/fixnames/semicolon_spec.rb +24 -0
- data/spec/fixnames/whitespace_spec.rb +65 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/should_fix_helpers.rb +19 -0
- data/test/helper.rb +34 -0
- data/test/test_charstrip.rb +35 -0
- data/test/test_hack_and.rb +17 -0
- data/test/test_lowercase.rb +20 -0
- data/test/test_semicolon.rb +18 -0
- data/test/test_whitespace.rb +110 -0
- metadata +145 -0
data/.document
ADDED
data/.rspec
ADDED
data/COPYING
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2006 why the lucky stiff
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Brent Sanders
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# fixnames
|
2
|
+
|
3
|
+
Fix filenames to be bash-script safe and easy to type.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
See the {Fixnames::Option} for the various settings.
|
8
|
+
|
9
|
+
fixnames [options] <files>
|
10
|
+
fixdirs [options] <directories>
|
11
|
+
|
12
|
+
### examples
|
13
|
+
|
14
|
+
cleanup a dir:
|
15
|
+
fixnames -fvv somedir/*
|
16
|
+
|
17
|
+
Remove all "`xyzzy`" from filenames:
|
18
|
+
fixnames -x xyzzy *
|
19
|
+
|
20
|
+
Remove all *digits* from filenames and replace them with "`X`":
|
21
|
+
fixnames -x \[0-9] -r X *
|
22
|
+
|
23
|
+
|
24
|
+
## Copyright
|
25
|
+
|
26
|
+
Copyright (c) 2011 Brent Sanders. See LICENSE.txt for
|
27
|
+
further details.
|
28
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= fixnames
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Brent Sanders. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
begin
|
6
|
+
require 'psych'
|
7
|
+
rescue ::LoadError
|
8
|
+
end
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
require 'jeweler'
|
12
|
+
require './lib/fixnames/version.rb'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
gem.name = "fixnames"
|
15
|
+
gem.version = Fixnames::Version::STRING
|
16
|
+
gem.homepage = "http://github.com/pdkl95/fixnames"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Filename cleanup for script compatability}
|
19
|
+
gem.description = %Q{Cleans up filenames so they can easily be used
|
20
|
+
in scripts, without annoyances such as spaces or other bad characters}
|
21
|
+
gem.email = "git@thoughtnoise.net"
|
22
|
+
gem.authors = ["Brent Sanders"]
|
23
|
+
gem.executables = ["fixnames", "fixdirs"]
|
24
|
+
gem.add_runtime_dependency "term-ansicolor", ">= 1.0.6"
|
25
|
+
gem.add_development_dependency "yard", ">= 0.6.0"
|
26
|
+
gem.add_development_dependency "rspec", ">= 2.3.0"
|
27
|
+
gem.add_development_dependency "jeweler", ">= 1.6.4"
|
28
|
+
gem.add_development_dependency "simplecov", ">= 0"
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
task :default => :spec
|
39
|
+
|
40
|
+
# require 'yard'
|
41
|
+
# YARD::Rake::YardocTask.new do |t|
|
42
|
+
# t.files = ['lib/**/*.rb']
|
43
|
+
# t.files += ['bin/*']
|
44
|
+
# #t.files += ['spec/**/*_spec.rb']
|
45
|
+
# #t.options += ['--plugin', 'yard-rspec']
|
46
|
+
# t.options += ['--markup', 'markdown']
|
47
|
+
# t.options += ['--debug']
|
48
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/fixdirs
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
6
|
+
require 'fixnames'
|
7
|
+
|
8
|
+
$fixmode = $0 =~ /dir/ ? :dir : :file
|
9
|
+
|
10
|
+
options = Fixnames::Option.new
|
11
|
+
|
12
|
+
case $fixmode
|
13
|
+
when :file
|
14
|
+
$banner = "Filename fixer to enforce bash-friendly filenames"
|
15
|
+
when :dir
|
16
|
+
$banner = "Whole-directory filename fixer to enforce bash-friendly filenames"
|
17
|
+
options.recursive = true
|
18
|
+
end
|
19
|
+
|
20
|
+
optparse = OptionParser.new do |opts|
|
21
|
+
opts.banner = $banner
|
22
|
+
opts.define_head "Usage: #{$0} [options] <file> [<file> ... ]"
|
23
|
+
|
24
|
+
opts.separator ''
|
25
|
+
opts.separator ' DIRECTORIES:'
|
26
|
+
|
27
|
+
opts.on('-g', '--glob=GLOB_STRING',
|
28
|
+
'Filename glob inside each directory (default: #{options[:glob]})'
|
29
|
+
) { |val| options.dir_glob = val }
|
30
|
+
|
31
|
+
opts.on('-R', '--[no-]recursive',
|
32
|
+
'Recursively descend into directories'
|
33
|
+
) { |val| options.recursive = val }
|
34
|
+
|
35
|
+
opts.separator ''
|
36
|
+
opts.separator ' FILTERS:'
|
37
|
+
|
38
|
+
opts.on('-A', '--[no-]hack_and',
|
39
|
+
'Replace "&" with "_and_"'
|
40
|
+
) { |val| options.hack_and = val }
|
41
|
+
|
42
|
+
opts.on('-C', '--[no-]semicolon',
|
43
|
+
'Replace ";" with "-"'
|
44
|
+
) { |val| options.semicolon = val }
|
45
|
+
|
46
|
+
opts.on('-B', '--[no-]banners',
|
47
|
+
'Trims [FOO] style advert prefixs from the beginning'
|
48
|
+
) { |val| options.banners = val }
|
49
|
+
|
50
|
+
opts.on('-b', '--[no-]brackets',
|
51
|
+
'Trims (round) or [square] bracket regions'
|
52
|
+
) { |val| options.brackets = val }
|
53
|
+
|
54
|
+
opts.on('-k', '--[no-]checksums',
|
55
|
+
'Trims [0A1B2C3D] CRC32 checksums from names. ( [] or () )'
|
56
|
+
) { |val| options.checksums = val }
|
57
|
+
|
58
|
+
opts.on('-d', '--[no-]dots',
|
59
|
+
'Trims excessive dots from files (before the .extention)'
|
60
|
+
) { |val| options.fix_dots = val }
|
61
|
+
|
62
|
+
opts.on('-D', '--[no-]dashes',
|
63
|
+
'Trims redundant dashes, and leading/trailing dashes'
|
64
|
+
) { |val| options.fix_dashes = val }
|
65
|
+
|
66
|
+
opts.on('-c', '--[no-]camelcase',
|
67
|
+
'Undo camelCase with underscores. "aB" becomes "a_b"'
|
68
|
+
) { |val| options.camelcase = val }
|
69
|
+
|
70
|
+
opts.on('-l', '--[no-]lowercase',
|
71
|
+
'Forces all letters to lowercase'
|
72
|
+
) { |val| options.lowercase = val }
|
73
|
+
|
74
|
+
opts.separator ''
|
75
|
+
opts.separator ' CHARACTERS:'
|
76
|
+
|
77
|
+
opts.on('-w', '--whitespace=CHARLIST',
|
78
|
+
"Characters to treat as whitespace, to be replaced with underscores."
|
79
|
+
) { |val| options.whitespace = val }
|
80
|
+
|
81
|
+
opts.on('-W', '--no-whitespace',
|
82
|
+
'Do not parse any character as whitespace'
|
83
|
+
) { options.whitespace = nil }
|
84
|
+
|
85
|
+
opts.on('-s', '--strip=CHARLIST',
|
86
|
+
"Characters to strip from names. default: #{options.charstrip}"
|
87
|
+
) { |val| options.charstrip = val }
|
88
|
+
|
89
|
+
opts.on('-S', '--no-strip',
|
90
|
+
'Do not strip any specific characters'
|
91
|
+
) { options.charstrip = nil }
|
92
|
+
|
93
|
+
opts.separator ''
|
94
|
+
opts.separator ' REGEX-REPLACE:'
|
95
|
+
|
96
|
+
opts.on('-x', '--expunge=REGEX',
|
97
|
+
'Expung a regexp from all filenames'
|
98
|
+
) { |val| options.expunge = val }
|
99
|
+
|
100
|
+
opts.on('-r', '--replace=STRING',
|
101
|
+
'Replace expunged text with'
|
102
|
+
) { |val| options.mendstr = val }
|
103
|
+
|
104
|
+
opts.separator ''
|
105
|
+
opts.separator ' COLLECTIONS:'
|
106
|
+
|
107
|
+
opts.on('-f', '--full',
|
108
|
+
'All filters are turned on!'
|
109
|
+
) do
|
110
|
+
Fixnames::Option::FLAG_FILTERS.each do |f|
|
111
|
+
options.send(f, true)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
opts.separator ''
|
116
|
+
opts.separator ' META:'
|
117
|
+
|
118
|
+
opts.on('-p', '--pretend',
|
119
|
+
'Pretend to run; no filesystem changes are made'
|
120
|
+
) { options.pretend = true }
|
121
|
+
|
122
|
+
opts.on('-v', '--verbose',
|
123
|
+
'Verbose mode -- repeat for more output'
|
124
|
+
) { options.verbose += 1 }
|
125
|
+
|
126
|
+
Term::ANSIColor::coloring = STDOUT.isatty
|
127
|
+
opts.on('-n', '--no-color',
|
128
|
+
'Suppress ANSI escape codes in the output'
|
129
|
+
) { Term::ANSIColor::coloring = false }
|
130
|
+
|
131
|
+
opts.on('-h', '--help', 'Show this help message') do
|
132
|
+
puts opts
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
optparse.parse!
|
138
|
+
|
139
|
+
if options.verbose > 2
|
140
|
+
puts "FIXMODE: #{$fixmode}"
|
141
|
+
end
|
142
|
+
|
143
|
+
filelist = ARGV
|
144
|
+
filelist = Dir['*'] if ARGV.length < 1
|
145
|
+
|
146
|
+
Fixnames::FixFile.fix_list! filelist, options
|
147
|
+
|
148
|
+
|
data/bin/fixnames
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
6
|
+
require 'fixnames'
|
7
|
+
|
8
|
+
$fixmode = $0 =~ /dir/ ? :dir : :file
|
9
|
+
|
10
|
+
options = Fixnames::Option.new
|
11
|
+
|
12
|
+
case $fixmode
|
13
|
+
when :file
|
14
|
+
$banner = "Filename fixer to enforce bash-friendly filenames"
|
15
|
+
when :dir
|
16
|
+
$banner = "Whole-directory filename fixer to enforce bash-friendly filenames"
|
17
|
+
options.recursive = true
|
18
|
+
end
|
19
|
+
|
20
|
+
optparse = OptionParser.new do |opts|
|
21
|
+
opts.banner = $banner
|
22
|
+
opts.define_head "Usage: #{$0} [options] <file> [<file> ... ]"
|
23
|
+
|
24
|
+
opts.separator ''
|
25
|
+
opts.separator ' DIRECTORIES:'
|
26
|
+
|
27
|
+
opts.on('-g', '--glob=GLOB_STRING',
|
28
|
+
'Filename glob inside each directory (default: #{options[:glob]})'
|
29
|
+
) { |val| options.dir_glob = val }
|
30
|
+
|
31
|
+
opts.on('-R', '--[no-]recursive',
|
32
|
+
'Recursively descend into directories'
|
33
|
+
) { |val| options.recursive = val }
|
34
|
+
|
35
|
+
opts.separator ''
|
36
|
+
opts.separator ' FILTERS:'
|
37
|
+
|
38
|
+
opts.on('-A', '--[no-]hack_and',
|
39
|
+
'Replace "&" with "_and_"'
|
40
|
+
) { |val| options.hack_and = val }
|
41
|
+
|
42
|
+
opts.on('-C', '--[no-]semicolon',
|
43
|
+
'Replace ";" with "-"'
|
44
|
+
) { |val| options.semicolon = val }
|
45
|
+
|
46
|
+
opts.on('-B', '--[no-]banners',
|
47
|
+
'Trims [FOO] style advert prefixs from the beginning'
|
48
|
+
) { |val| options.banners = val }
|
49
|
+
|
50
|
+
opts.on('-b', '--[no-]brackets',
|
51
|
+
'Trims (round) or [square] bracket regions'
|
52
|
+
) { |val| options.brackets = val }
|
53
|
+
|
54
|
+
opts.on('-k', '--[no-]checksums',
|
55
|
+
'Trims [0A1B2C3D] CRC32 checksums from names. ( [] or () )'
|
56
|
+
) { |val| options.checksums = val }
|
57
|
+
|
58
|
+
opts.on('-d', '--[no-]dots',
|
59
|
+
'Trims excessive dots from files (before the .extention)'
|
60
|
+
) { |val| options.fix_dots = val }
|
61
|
+
|
62
|
+
opts.on('-D', '--[no-]dashes',
|
63
|
+
'Trims redundant dashes, and leading/trailing dashes'
|
64
|
+
) { |val| options.fix_dashes = val }
|
65
|
+
|
66
|
+
opts.on('-c', '--[no-]camelcase',
|
67
|
+
'Undo camelCase with underscores. "aB" becomes "a_b"'
|
68
|
+
) { |val| options.camelcase = val }
|
69
|
+
|
70
|
+
opts.on('-l', '--[no-]lowercase',
|
71
|
+
'Forces all letters to lowercase'
|
72
|
+
) { |val| options.lowercase = val }
|
73
|
+
|
74
|
+
opts.separator ''
|
75
|
+
opts.separator ' CHARACTERS:'
|
76
|
+
|
77
|
+
opts.on('-w', '--whitespace=CHARLIST',
|
78
|
+
"Characters to treat as whitespace, to be replaced with underscores."
|
79
|
+
) { |val| options.whitespace = val }
|
80
|
+
|
81
|
+
opts.on('-W', '--no-whitespace',
|
82
|
+
'Do not parse any character as whitespace'
|
83
|
+
) { options.whitespace = nil }
|
84
|
+
|
85
|
+
opts.on('-s', '--strip=CHARLIST',
|
86
|
+
"Characters to strip from names. default: #{options.charstrip}"
|
87
|
+
) { |val| options.charstrip = val }
|
88
|
+
|
89
|
+
opts.on('-S', '--no-strip',
|
90
|
+
'Do not strip any specific characters'
|
91
|
+
) { options.charstrip = nil }
|
92
|
+
|
93
|
+
opts.separator ''
|
94
|
+
opts.separator ' REGEX-REPLACE:'
|
95
|
+
|
96
|
+
opts.on('-x', '--expunge=REGEX',
|
97
|
+
'Expung a regexp from all filenames'
|
98
|
+
) { |val| options.expunge = val }
|
99
|
+
|
100
|
+
opts.on('-r', '--replace=STRING',
|
101
|
+
'Replace expunged text with'
|
102
|
+
) { |val| options.mendstr = val }
|
103
|
+
|
104
|
+
opts.separator ''
|
105
|
+
opts.separator ' COLLECTIONS:'
|
106
|
+
|
107
|
+
opts.on('-f', '--full',
|
108
|
+
'All filters are turned on!'
|
109
|
+
) do
|
110
|
+
Fixnames::Option::FLAG_FILTERS.each do |f|
|
111
|
+
options.send(f, true)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
opts.separator ''
|
116
|
+
opts.separator ' META:'
|
117
|
+
|
118
|
+
opts.on('-p', '--pretend',
|
119
|
+
'Pretend to run; no filesystem changes are made'
|
120
|
+
) { options.pretend = true }
|
121
|
+
|
122
|
+
opts.on('-v', '--verbose',
|
123
|
+
'Verbose mode -- repeat for more output'
|
124
|
+
) { options.verbose += 1 }
|
125
|
+
|
126
|
+
Term::ANSIColor::coloring = STDOUT.isatty
|
127
|
+
opts.on('-n', '--no-color',
|
128
|
+
'Suppress ANSI escape codes in the output'
|
129
|
+
) { Term::ANSIColor::coloring = false }
|
130
|
+
|
131
|
+
opts.on('-h', '--help', 'Show this help message') do
|
132
|
+
puts opts
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
optparse.parse!
|
138
|
+
|
139
|
+
if options.verbose > 2
|
140
|
+
puts "FIXMODE: #{$fixmode}"
|
141
|
+
end
|
142
|
+
|
143
|
+
filelist = ARGV
|
144
|
+
filelist = Dir['*'] if ARGV.length < 1
|
145
|
+
|
146
|
+
Fixnames::FixFile.fix_list! filelist, options
|
147
|
+
|
148
|
+
|