deblank 0.0.1 → 0.2.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/Gemfile +6 -0
- data/README.md +4 -4
- data/Rakefile +22 -27
- data/bin/deblank +3 -2
- data/deblank.gemspec +22 -19
- data/lib/deblank.rb +125 -101
- data/man/deblank.1 +4 -4
- data/test/test_nameconverter.rb +26 -18
- data/test/test_optionparser.rb +20 -26
- metadata +13 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 64eb6816ecca78f248def7e3d9defa6627616337b86a9b67ffb6cd12ade098ab
|
4
|
+
data.tar.gz: 5ae0b56dcf338b04bbc34eb36f678008db547ae57d75f343dd28c24fa9c205f7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06ab50f7edbaa7f9b121913382aa3f9a4a7b4ef4f21ccae9fee7e0d9d4b8e28f8fe0de5e45b820054a7f4b937d73033084936e4b17b34e3f0cb29ac054383565
|
7
|
+
data.tar.gz: e10c7f3ab901c07daf07b70253136da314417fa6651350e618bc122ced915ab36e747c43c32fe7688f96c841481b5f16eaf739172e17c31639bf389a2bf3cf24
|
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -37,7 +37,7 @@ Installation
|
|
37
37
|
|
38
38
|
You can either
|
39
39
|
|
40
|
-
- use `gem install deblank
|
40
|
+
- use `gem install deblank` to install from RubyGems.org,
|
41
41
|
|
42
42
|
- copy `lib/deblank.rb` under the name `deblank` into your search path,
|
43
43
|
|
@@ -51,8 +51,8 @@ Requirements
|
|
51
51
|
|
52
52
|
- No additional Ruby gems are needed to run `deblank`.
|
53
53
|
|
54
|
-
- `deblank` has been tested with Ruby 1
|
55
|
-
and on Windows (command prompt with code page 850).
|
54
|
+
- `deblank` has been tested with Ruby 3.1 or higher
|
55
|
+
on Linux and on Windows (command prompt with code page 850).
|
56
56
|
|
57
57
|
Documentation
|
58
58
|
-------------
|
@@ -77,7 +77,7 @@ Report bugs on the `deblank` home page: <https://github.com/stomar/deblank/>
|
|
77
77
|
License
|
78
78
|
-------
|
79
79
|
|
80
|
-
Copyright © 2012
|
80
|
+
Copyright © 2012-2024 Marcus Stollsteimer
|
81
81
|
|
82
82
|
`deblank` is free software: you can redistribute it and/or modify
|
83
83
|
it under the terms of the GNU General Public License version 3 or later (GPLv3+),
|
data/Rakefile
CHANGED
@@ -1,53 +1,49 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Copyright (C) 2012 Marcus Stollsteimer
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
require
|
3
|
+
require "rake/testtask"
|
6
4
|
|
7
|
-
require
|
5
|
+
require "./lib/deblank"
|
8
6
|
|
9
7
|
PROGNAME = Deblank::PROGNAME
|
10
8
|
HOMEPAGE = Deblank::HOMEPAGE
|
11
9
|
TAGLINE = Deblank::TAGLINE
|
12
10
|
|
13
|
-
BINDIR =
|
14
|
-
MANDIR =
|
11
|
+
BINDIR = "/usr/local/bin"
|
12
|
+
MANDIR = "/usr/local/man/man1"
|
15
13
|
|
16
|
-
HELP2MAN =
|
17
|
-
SED =
|
14
|
+
HELP2MAN = "help2man"
|
15
|
+
SED = "sed"
|
18
16
|
|
19
|
-
BINARY =
|
20
|
-
BINARYNAME =
|
21
|
-
MANPAGE =
|
22
|
-
H2MFILE =
|
17
|
+
BINARY = "lib/deblank.rb"
|
18
|
+
BINARYNAME = "deblank" # install using this name
|
19
|
+
MANPAGE = "man/deblank.1"
|
20
|
+
H2MFILE = "deblank.h2m"
|
23
21
|
|
24
22
|
|
25
23
|
def gemspec_file
|
26
|
-
|
24
|
+
"deblank.gemspec"
|
27
25
|
end
|
28
26
|
|
29
27
|
|
30
|
-
task :
|
28
|
+
task default: [:test]
|
31
29
|
|
32
30
|
Rake::TestTask.new do |t|
|
33
|
-
t.
|
34
|
-
t.pattern = 'test/**/test_*.rb'
|
35
|
-
t.ruby_opts << '-rubygems'
|
31
|
+
t.pattern = "test/**/test_*.rb"
|
36
32
|
t.verbose = true
|
37
33
|
t.warning = true
|
38
34
|
end
|
39
35
|
|
40
36
|
|
41
|
-
desc
|
42
|
-
task :
|
37
|
+
desc "Install binary and man page"
|
38
|
+
task install: [BINARY, MANPAGE] do
|
43
39
|
mkdir_p BINDIR
|
44
40
|
install(BINARY, "#{BINDIR}/#{BINARYNAME}")
|
45
41
|
mkdir_p MANDIR
|
46
|
-
install(MANPAGE, MANDIR, :
|
42
|
+
install(MANPAGE, MANDIR, mode: 0o644)
|
47
43
|
end
|
48
44
|
|
49
45
|
|
50
|
-
desc
|
46
|
+
desc "Uninstall binary and man page"
|
51
47
|
task :uninstall do
|
52
48
|
rm "#{BINDIR}/#{BINARYNAME}"
|
53
49
|
manfile = File.basename(MANPAGE)
|
@@ -55,19 +51,18 @@ task :uninstall do
|
|
55
51
|
end
|
56
52
|
|
57
53
|
|
58
|
-
desc
|
59
|
-
task :
|
54
|
+
desc "Create man page"
|
55
|
+
task man: [MANPAGE]
|
60
56
|
|
61
57
|
file MANPAGE => [BINARY, H2MFILE] do
|
62
58
|
sh "#{HELP2MAN} --no-info --name='#{TAGLINE}' --include=#{H2MFILE} -o #{MANPAGE} ./#{BINARY}"
|
63
|
-
sh "#{SED} -i '/\.PP/{N;s/\.PP\\nOptions/.SH OPTIONS/}' #{MANPAGE}"
|
64
59
|
sh "#{SED} -i 's/^License GPL/.br\\nLicense GPL/;s/There is NO WARRANTY/.br\\nThere is NO WARRANTY/' #{MANPAGE}"
|
65
60
|
sh "#{SED} -i 's!%HOMEPAGE%!#{HOMEPAGE}!g' #{MANPAGE}"
|
66
61
|
sh "#{SED} -i 's!%PROGNAME%!#{PROGNAME}!g' #{MANPAGE}"
|
67
62
|
end
|
68
63
|
|
69
64
|
|
70
|
-
desc
|
71
|
-
task :
|
65
|
+
desc "Build gem"
|
66
|
+
task build: [MANPAGE] do
|
72
67
|
sh "gem build #{gemspec_file}"
|
73
68
|
end
|
data/bin/deblank
CHANGED
data/deblank.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "./lib/deblank"
|
2
4
|
|
3
5
|
version = Deblank::VERSION
|
4
6
|
date = Deblank::DATE
|
@@ -6,38 +8,39 @@ homepage = Deblank::HOMEPAGE
|
|
6
8
|
tagline = Deblank::TAGLINE
|
7
9
|
|
8
10
|
Gem::Specification.new do |s|
|
9
|
-
s.name =
|
11
|
+
s.name = "deblank"
|
10
12
|
s.version = version
|
11
13
|
s.date = date
|
12
|
-
s.rubyforge_project = 'deblank'
|
13
14
|
|
14
|
-
s.description =
|
15
|
-
|
16
|
-
|
15
|
+
s.description = "deblank is a command line tool that " \
|
16
|
+
"renames files and replaces or removes special characters " \
|
17
|
+
"like spaces, parentheses, or umlauts."
|
17
18
|
s.summary = "deblank - #{tagline}"
|
18
19
|
|
19
|
-
s.authors = [
|
20
|
-
s.email =
|
20
|
+
s.authors = ["Marcus Stollsteimer"]
|
21
|
+
s.email = "sto.mar@web.de"
|
21
22
|
s.homepage = homepage
|
22
23
|
|
23
|
-
s.license =
|
24
|
+
s.license = "GPL-3.0"
|
25
|
+
|
26
|
+
s.required_ruby_version = ">= 3.1.0"
|
24
27
|
|
25
|
-
|
28
|
+
s.executables = ["deblank"]
|
29
|
+
s.bindir = "bin"
|
26
30
|
|
27
|
-
s.
|
28
|
-
s.bindir = 'bin'
|
29
|
-
s.require_path = 'lib'
|
30
|
-
s.test_files = Dir.glob('test/**/test_*.rb')
|
31
|
+
s.require_paths = ["lib"]
|
31
32
|
|
32
|
-
s.
|
33
|
+
s.test_files = Dir.glob("test/**/test_*.rb")
|
33
34
|
|
34
|
-
s.files =
|
35
|
+
s.files =
|
36
|
+
%w[
|
35
37
|
README.md
|
36
38
|
Rakefile
|
39
|
+
Gemfile
|
37
40
|
deblank.gemspec
|
38
41
|
deblank.h2m
|
39
|
-
|
40
|
-
Dir.glob(
|
42
|
+
] +
|
43
|
+
Dir.glob("{bin,lib,man,test}/**/*")
|
41
44
|
|
42
|
-
s.
|
45
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
46
|
end
|
data/lib/deblank.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
#
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
3
4
|
# == Name
|
4
5
|
#
|
5
6
|
# deblank - remove special characters from filenames
|
@@ -15,25 +16,27 @@
|
|
15
16
|
#
|
16
17
|
# == Author
|
17
18
|
#
|
18
|
-
# Copyright (C) 2012 Marcus Stollsteimer
|
19
|
+
# Copyright (C) 2012-2024 Marcus Stollsteimer
|
19
20
|
#
|
20
21
|
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
21
22
|
|
22
|
-
require
|
23
|
+
require "optparse"
|
23
24
|
|
24
25
|
# This module contains the classes for the +deblank+ tool.
|
25
26
|
module Deblank
|
26
27
|
|
27
|
-
PROGNAME =
|
28
|
-
VERSION =
|
29
|
-
DATE =
|
30
|
-
HOMEPAGE =
|
31
|
-
TAGLINE =
|
28
|
+
PROGNAME = "deblank"
|
29
|
+
VERSION = "0.2.0"
|
30
|
+
DATE = "2024-01-05"
|
31
|
+
HOMEPAGE = "https://github.com/stomar/deblank"
|
32
|
+
TAGLINE = "remove special characters from filenames"
|
32
33
|
|
33
|
-
COPYRIGHT =
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
COPYRIGHT = <<~TEXT
|
35
|
+
Copyright (C) 2012-2024 Marcus Stollsteimer.
|
36
|
+
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
37
|
+
This is free software: you are free to change and redistribute it.
|
38
|
+
There is NO WARRANTY, to the extent permitted by law.
|
39
|
+
TEXT
|
37
40
|
|
38
41
|
# Parser for the command line options.
|
39
42
|
# The class method parse! does the job.
|
@@ -47,62 +50,62 @@ module Deblank
|
|
47
50
|
#
|
48
51
|
# Returns a hash containing the option parameters.
|
49
52
|
def self.parse!(argv)
|
50
|
-
|
51
53
|
options = {
|
52
|
-
:
|
53
|
-
:
|
54
|
+
files: nil,
|
55
|
+
simulate: false
|
54
56
|
}
|
55
57
|
|
56
58
|
opt_parser = OptionParser.new do |opt|
|
57
59
|
opt.banner = "Usage: #{PROGNAME} [options] file[s]"
|
58
|
-
opt.separator
|
59
|
-
opt.separator
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
opt.separator ""
|
61
|
+
opt.separator <<~DESCRIPTION
|
62
|
+
deblank renames files and replaces or removes special characters
|
63
|
+
like spaces, parentheses, or umlauts.
|
64
|
+
The new filename will only contain the following characters:
|
65
|
+
|
66
|
+
#{NameConverter.default_valid_chars_to_s}
|
67
|
+
|
68
|
+
Spaces are replaced by underscores, German umlauts and eszett are
|
69
|
+
transliterated, all other invalid characters are removed.
|
70
|
+
|
71
|
+
Options:
|
72
|
+
DESCRIPTION
|
70
73
|
|
71
74
|
# process --version and --help first,
|
72
75
|
# exit successfully (GNU Coding Standards)
|
73
|
-
opt.on_tail(
|
76
|
+
opt.on_tail("-h", "--help", "Print a brief help message and exit.") do
|
74
77
|
puts opt_parser
|
75
78
|
puts "\nReport bugs on the #{PROGNAME} home page: <#{HOMEPAGE}>"
|
76
79
|
exit
|
77
80
|
end
|
78
81
|
|
79
|
-
opt.on_tail(
|
80
|
-
|
82
|
+
opt.on_tail("-v", "--version",
|
83
|
+
"Print a brief version information and exit.") do
|
81
84
|
puts "#{PROGNAME} #{VERSION}"
|
82
85
|
puts COPYRIGHT
|
83
86
|
exit
|
84
87
|
end
|
85
88
|
|
86
|
-
opt.on(
|
87
|
-
|
88
|
-
puts NameConverter.
|
89
|
+
opt.on("-l", "--list",
|
90
|
+
"List the used character substitutions.") do
|
91
|
+
puts NameConverter.default_substitutions_to_s
|
89
92
|
exit
|
90
93
|
end
|
91
94
|
|
92
|
-
opt.on(
|
93
|
-
|
95
|
+
opt.on("-n", "--no-act",
|
96
|
+
"Do not rename files, only display what would happen.") do
|
94
97
|
options[:simulate] = true
|
95
98
|
end
|
96
99
|
|
97
|
-
opt.separator
|
100
|
+
opt.separator ""
|
98
101
|
end
|
99
102
|
opt_parser.parse!(argv)
|
100
103
|
|
101
104
|
# only file[s] should be left (at least 1 argument)
|
102
|
-
raise(ArgumentError,
|
105
|
+
raise(ArgumentError, "wrong number of arguments") if argv.empty?
|
103
106
|
|
104
107
|
options[:files] = Array.new(argv).map do |filename|
|
105
|
-
correct_encoding(filename).encode(
|
108
|
+
correct_encoding(filename).encode("UTF-8")
|
106
109
|
end
|
107
110
|
argv.clear
|
108
111
|
|
@@ -120,47 +123,57 @@ module Deblank
|
|
120
123
|
def self.correct_encoding(string)
|
121
124
|
return string unless string.encoding == Encoding::CP850
|
122
125
|
|
123
|
-
string.dup.force_encoding(
|
126
|
+
string.dup.force_encoding("Windows-1252")
|
124
127
|
end
|
125
128
|
end
|
126
129
|
|
127
|
-
# This
|
130
|
+
# This class provides a converter method for filenames
|
128
131
|
# (only the base name is modified).
|
129
|
-
|
132
|
+
class NameConverter
|
130
133
|
|
131
|
-
VALID_CHARS =
|
134
|
+
VALID_CHARS = "A-Za-z0-9._-" # `-' must be last
|
132
135
|
|
133
136
|
SUBSTITUTIONS = {
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
}
|
143
|
-
|
144
|
-
def self.convert(filename)
|
145
|
-
invalid_chars = /[^#{VALID_CHARS.tr(' ', '')}]/
|
146
|
-
basename = File.basename(filename)
|
147
|
-
dir = File.dirname(filename)
|
148
|
-
|
149
|
-
SUBSTITUTIONS.each do |from, to|
|
150
|
-
basename.gsub!(/#{from}/, to)
|
151
|
-
end
|
152
|
-
basename.gsub!(invalid_chars, '')
|
137
|
+
" " => "_",
|
138
|
+
"ä" => "ae",
|
139
|
+
"ö" => "oe",
|
140
|
+
"ü" => "ue",
|
141
|
+
"Ä" => "Ae",
|
142
|
+
"Ö" => "Oe",
|
143
|
+
"Ü" => "Ue",
|
144
|
+
"ß" => "ss"
|
145
|
+
}.freeze
|
153
146
|
|
154
|
-
|
147
|
+
def initialize
|
148
|
+
@valid_characters = VALID_CHARS
|
149
|
+
@substitutions = SUBSTITUTIONS
|
155
150
|
end
|
156
151
|
|
157
|
-
def
|
158
|
-
|
159
|
-
SUBSTITUTIONS.each do |from, to|
|
160
|
-
output << "#{from} => #{to}\n"
|
161
|
-
end
|
152
|
+
def convert(filename)
|
153
|
+
dir, basename = File.dirname(filename), File.basename(filename)
|
162
154
|
|
163
|
-
|
155
|
+
@substitutions.each {|from, to| basename.gsub!(/#{from}/, to) }
|
156
|
+
basename.gsub!(invalid_characters, "")
|
157
|
+
|
158
|
+
dir == "." ? basename : "#{dir}/#{basename}"
|
159
|
+
end
|
160
|
+
|
161
|
+
def invalid?(filename)
|
162
|
+
filename.match?(invalid_characters)
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.default_valid_chars_to_s
|
166
|
+
VALID_CHARS.scan(/.-.|./).join(" ")
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.default_substitutions_to_s
|
170
|
+
SUBSTITUTIONS.map {|from, to| "#{from} => #{to}\n" }.join
|
171
|
+
end
|
172
|
+
|
173
|
+
private
|
174
|
+
|
175
|
+
def invalid_characters
|
176
|
+
/[^#{@valid_characters}]/
|
164
177
|
end
|
165
178
|
end
|
166
179
|
|
@@ -169,16 +182,17 @@ module Deblank
|
|
169
182
|
# It parses the command line arguments and renames the files.
|
170
183
|
class Application
|
171
184
|
|
172
|
-
ERRORCODE = {:
|
185
|
+
ERRORCODE = { general: 1, usage: 2 }.freeze
|
173
186
|
|
174
187
|
def initialize
|
175
188
|
begin
|
176
189
|
options = Optionparser.parse!(ARGV)
|
177
|
-
|
178
|
-
@simulate = options[:simulate]
|
179
|
-
rescue => e
|
190
|
+
rescue StandardError => e
|
180
191
|
usage_fail(e.message)
|
181
192
|
end
|
193
|
+
@files = options[:files]
|
194
|
+
@simulate = options[:simulate]
|
195
|
+
@converter = NameConverter.new
|
182
196
|
end
|
183
197
|
|
184
198
|
# The main program.
|
@@ -187,28 +201,41 @@ module Deblank
|
|
187
201
|
warn "#{message}\n#{'-' * message.size}\n" if @simulate
|
188
202
|
|
189
203
|
@files.each do |filename|
|
190
|
-
unless
|
191
|
-
|
192
|
-
next
|
193
|
-
end
|
204
|
+
next unless file_exist?(filename)
|
205
|
+
next unless invalid?(filename)
|
194
206
|
|
195
|
-
new_filename =
|
207
|
+
new_filename = @converter.convert(filename)
|
208
|
+
secure_rename(filename, new_filename)
|
209
|
+
end
|
210
|
+
end
|
196
211
|
|
197
|
-
|
198
|
-
if new_filename == filename
|
199
|
-
warn("`#{filename}' and `#{new_filename}' are the same file. (Skipped.)")
|
200
|
-
next
|
201
|
-
end
|
212
|
+
private
|
202
213
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
214
|
+
def skip_warn(message)
|
215
|
+
warn "#{message} (Skipped.)"
|
216
|
+
end
|
217
|
+
|
218
|
+
def file_exist?(filename)
|
219
|
+
fail_message = "There is no file `#{filename}'."
|
220
|
+
|
221
|
+
File.exist?(filename) or skip_warn(fail_message)
|
222
|
+
end
|
223
|
+
|
224
|
+
def invalid?(filename)
|
225
|
+
fail_message = "`#{filename}' already is a valid filename."
|
208
226
|
|
209
|
-
|
210
|
-
|
211
|
-
|
227
|
+
@converter.invalid?(filename) or skip_warn(fail_message)
|
228
|
+
end
|
229
|
+
|
230
|
+
def secure_rename(old_filename, new_filename)
|
231
|
+
return if File.exist?(new_filename) && !overwrite?(new_filename)
|
232
|
+
|
233
|
+
warn "Moving from `#{old_filename}' to `#{new_filename}'."
|
234
|
+
File.rename(old_filename, new_filename) unless @simulate
|
235
|
+
end
|
236
|
+
|
237
|
+
def overwrite?(filename)
|
238
|
+
confirm("File `#{filename}' already exists. Overwrite?")
|
212
239
|
end
|
213
240
|
|
214
241
|
# Asks for yes or no (y/n).
|
@@ -216,28 +243,25 @@ module Deblank
|
|
216
243
|
# +question+ - string to be printed
|
217
244
|
#
|
218
245
|
# Returns +true+ if the answer is yes.
|
219
|
-
def
|
246
|
+
def confirm(question)
|
220
247
|
loop do
|
221
248
|
$stderr.print "#{question} [y/n] "
|
222
|
-
reply = $stdin.gets.chomp.downcase # $stdin
|
223
|
-
return
|
224
|
-
|
249
|
+
reply = $stdin.gets.chomp.downcase # $stdin avoids gets/ARGV problem
|
250
|
+
return reply == "y" if reply.match?(/\A[yn]\z/)
|
251
|
+
|
225
252
|
warn "Please answer `y' or `n'."
|
226
253
|
end
|
227
254
|
end
|
228
255
|
|
229
256
|
# Prints an error message and a short help information, then exits.
|
230
|
-
def usage_fail(message)
|
257
|
+
def usage_fail(message)
|
231
258
|
warn "#{PROGNAME}: #{message}"
|
232
259
|
warn "Use `#{PROGNAME} --help' for valid options."
|
233
260
|
exit ERRORCODE[:usage]
|
234
261
|
end
|
235
262
|
end
|
263
|
+
end
|
236
264
|
|
237
265
|
### call main method only if called on command line
|
238
266
|
|
239
|
-
if __FILE__ == $
|
240
|
-
Application.new.run!
|
241
|
-
end
|
242
|
-
|
243
|
-
end # module
|
267
|
+
Deblank::Application.new.run! if __FILE__ == $PROGRAM_NAME
|
data/man/deblank.1
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.
|
2
|
-
.TH DEBLANK "1" "
|
1
|
+
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.1.
|
2
|
+
.TH DEBLANK "1" "January 2024" "deblank 0.2.0" "User Commands"
|
3
3
|
.SH NAME
|
4
4
|
deblank \- remove special characters from filenames
|
5
5
|
.SH SYNOPSIS
|
6
6
|
.B deblank
|
7
|
-
[\
|
7
|
+
[\fI\,options\/\fR] \fI\,file\/\fR[\fI\,s\/\fR]
|
8
8
|
.SH DESCRIPTION
|
9
9
|
deblank renames files and replaces or removes special characters
|
10
10
|
like spaces, parentheses, or umlauts.
|
@@ -30,7 +30,7 @@ Print a brief version information and exit.
|
|
30
30
|
.SH "REPORTING BUGS"
|
31
31
|
Report bugs on the deblank home page: <https://github.com/stomar/deblank>
|
32
32
|
.SH COPYRIGHT
|
33
|
-
Copyright \(co 2012 Marcus Stollsteimer.
|
33
|
+
Copyright \(co 2012\-2024 Marcus Stollsteimer.
|
34
34
|
.br
|
35
35
|
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
36
36
|
.br
|
data/test/test_nameconverter.rb
CHANGED
@@ -1,34 +1,42 @@
|
|
1
|
-
|
2
|
-
# encoding: UTF-8
|
3
|
-
#
|
4
|
-
# test_nameconverter.rb: Unit tests for the deblank script.
|
5
|
-
#
|
6
|
-
# Copyright (C) 2012 Marcus Stollsteimer
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require 'deblank'
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "deblank"
|
11
5
|
|
12
6
|
|
13
7
|
describe Deblank::NameConverter do
|
14
8
|
|
15
9
|
before do
|
16
|
-
@nc = Deblank::NameConverter
|
10
|
+
@nc = Deblank::NameConverter.new
|
17
11
|
end
|
18
12
|
|
19
|
-
it
|
20
|
-
@nc.
|
13
|
+
it "recognizes invalid filenames" do
|
14
|
+
_(@nc.invalid?("path/to/filename with spaces.txt")).must_equal true
|
15
|
+
_(@nc.invalid?("filename_with_ä.txt")).must_equal true
|
16
|
+
_(@nc.invalid?("Valid_filename-1.txt")).must_equal false
|
21
17
|
end
|
22
18
|
|
23
|
-
it
|
24
|
-
@nc.convert(
|
19
|
+
it "does not change the path name" do
|
20
|
+
_(@nc.convert("path with spaces/file.txt")).must_equal "path with spaces/file.txt"
|
25
21
|
end
|
26
22
|
|
27
|
-
it
|
28
|
-
@nc.convert(
|
23
|
+
it "replaces spaces by underscores" do
|
24
|
+
_(@nc.convert("file with spaces.txt")).must_equal "file_with_spaces.txt"
|
29
25
|
end
|
30
26
|
|
31
|
-
it
|
32
|
-
@nc.convert(
|
27
|
+
it "removes parentheses" do
|
28
|
+
_(@nc.convert("file_(another).txt")).must_equal "file_another.txt"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "transliterates umlauts and eszett" do
|
32
|
+
_(@nc.convert("Ä_Ö_Ü_ä_ö_ü_ß.txt")).must_equal "Ae_Oe_Ue_ae_oe_ue_ss.txt"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can return the default valid characters as string" do
|
36
|
+
_(Deblank::NameConverter.default_valid_chars_to_s).must_equal "A-Z a-z 0-9 . _ -"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can return the default substitutions as string" do
|
40
|
+
_(Deblank::NameConverter.default_substitutions_to_s.split("\n")[0]).must_equal " => _"
|
33
41
|
end
|
34
42
|
end
|
data/test/test_optionparser.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
|
2
|
-
# encoding: UTF-8
|
3
|
-
#
|
4
|
-
# test_optionparser.rb: Unit tests for the deblank script.
|
5
|
-
#
|
6
|
-
# Copyright (C) 2012 Marcus Stollsteimer
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require 'deblank'
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "deblank"
|
11
5
|
|
12
6
|
|
13
7
|
describe Deblank::Optionparser do
|
@@ -15,35 +9,35 @@ describe Deblank::Optionparser do
|
|
15
9
|
before do
|
16
10
|
@parser = Deblank::Optionparser
|
17
11
|
@arg = "test_ä.txt"
|
18
|
-
@
|
19
|
-
@
|
12
|
+
@arg_win1252_labeled_as_cp850 = (+"test_\xE4.txt").force_encoding("CP850")
|
13
|
+
@arg_win1252 = (+"test_\xE4.txt").force_encoding("Windows-1252")
|
20
14
|
end
|
21
15
|
|
22
|
-
it
|
23
|
-
arg = @
|
24
|
-
arg.encoding.must_equal Encoding::CP850
|
16
|
+
it "can correct encoding from (seemingly) CP850 to Windows-1252" do
|
17
|
+
arg = @arg_win1252_labeled_as_cp850
|
18
|
+
_(arg.encoding).must_equal Encoding::CP850
|
25
19
|
corrected_arg = @parser.correct_encoding(arg)
|
26
|
-
corrected_arg.encoding.must_equal Encoding::Windows_1252
|
20
|
+
_(corrected_arg.encoding).must_equal Encoding::Windows_1252
|
27
21
|
end
|
28
22
|
|
29
|
-
it
|
30
|
-
options = @parser.parse!([@
|
23
|
+
it "encodes (seemingly) CP850 encoded filenames into UTF-8" do
|
24
|
+
options = @parser.parse!([@arg_win1252_labeled_as_cp850])
|
31
25
|
filename = options[:files].first
|
32
|
-
filename.encoding.must_equal Encoding::UTF_8
|
33
|
-
filename.must_equal @arg
|
26
|
+
_(filename.encoding).must_equal Encoding::UTF_8
|
27
|
+
_(filename).must_equal @arg
|
34
28
|
end
|
35
29
|
|
36
|
-
it
|
37
|
-
options = @parser.parse!([@
|
30
|
+
it "encodes Windows-1252 encoded filenames into UTF-8" do
|
31
|
+
options = @parser.parse!([@arg_win1252])
|
38
32
|
filename = options[:files].first
|
39
|
-
filename.encoding.must_equal Encoding::UTF_8
|
40
|
-
filename.must_equal @arg
|
33
|
+
_(filename.encoding).must_equal Encoding::UTF_8
|
34
|
+
_(filename).must_equal @arg
|
41
35
|
end
|
42
36
|
|
43
|
-
it
|
37
|
+
it "encodes UTF-8 encoded filenames into UTF-8" do
|
44
38
|
options = @parser.parse!([@arg])
|
45
39
|
filename = options[:files].first
|
46
|
-
filename.encoding.must_equal Encoding::UTF_8
|
47
|
-
filename.must_equal @arg
|
40
|
+
_(filename.encoding).must_equal Encoding::UTF_8
|
41
|
+
_(filename).must_equal @arg
|
48
42
|
end
|
49
43
|
end
|
metadata
CHANGED
@@ -1,32 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deblank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Marcus Stollsteimer
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rake
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
11
|
+
date: 2024-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
30
13
|
description: deblank is a command line tool that renames files and replaces or removes
|
31
14
|
special characters like spaces, parentheses, or umlauts.
|
32
15
|
email: sto.mar@web.de
|
@@ -35,42 +18,40 @@ executables:
|
|
35
18
|
extensions: []
|
36
19
|
extra_rdoc_files: []
|
37
20
|
files:
|
21
|
+
- Gemfile
|
38
22
|
- README.md
|
39
23
|
- Rakefile
|
24
|
+
- bin/deblank
|
40
25
|
- deblank.gemspec
|
41
26
|
- deblank.h2m
|
42
|
-
- bin/deblank
|
43
27
|
- lib/deblank.rb
|
44
28
|
- man/deblank.1
|
45
29
|
- test/test_nameconverter.rb
|
46
30
|
- test/test_optionparser.rb
|
47
31
|
homepage: https://github.com/stomar/deblank
|
48
32
|
licenses:
|
49
|
-
- GPL-3
|
33
|
+
- GPL-3.0
|
34
|
+
metadata: {}
|
50
35
|
post_install_message:
|
51
36
|
rdoc_options:
|
52
|
-
- --charset=UTF-8
|
37
|
+
- "--charset=UTF-8"
|
53
38
|
require_paths:
|
54
39
|
- lib
|
55
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
41
|
requirements:
|
58
|
-
- -
|
42
|
+
- - ">="
|
59
43
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
44
|
+
version: 3.1.0
|
61
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
46
|
requirements:
|
64
|
-
- -
|
47
|
+
- - ">="
|
65
48
|
- !ruby/object:Gem::Version
|
66
49
|
version: '0'
|
67
50
|
requirements: []
|
68
|
-
|
69
|
-
rubygems_version: 1.8.24
|
51
|
+
rubygems_version: 3.5.3
|
70
52
|
signing_key:
|
71
|
-
specification_version:
|
53
|
+
specification_version: 4
|
72
54
|
summary: deblank - remove special characters from filenames
|
73
55
|
test_files:
|
74
56
|
- test/test_nameconverter.rb
|
75
57
|
- test/test_optionparser.rb
|
76
|
-
has_rdoc:
|