nrename 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +22 -0
- data/README.md +55 -0
- data/features/options_processing.feature +6 -1
- data/features/renaming_files.feature +2 -1
- data/features/support/env.rb +4 -0
- data/lib/nrename.rb +3 -4
- data/lib/nrename/directory.rb +3 -3
- data/lib/nrename/options.rb +6 -0
- data/lib/nrename/version.rb +1 -1
- data/spec/nrename/directory_spec.rb +5 -5
- metadata +38 -29
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Victor Deryagin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/vderyagin/nrename.png)](http://travis-ci.org/vderyagin/nrename)
|
2
|
+
[![Dependency Status](https://gemnasium.com/vderyagin/nrename.png)](https://gemnasium.com/vderyagin/nrename)
|
3
|
+
|
4
|
+
# Nrename
|
5
|
+
|
6
|
+
Command-line utility for renaming numbered files.
|
7
|
+
|
8
|
+
## Installation ##
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install nrename
|
12
|
+
```
|
13
|
+
|
14
|
+
## Description ##
|
15
|
+
|
16
|
+
|
17
|
+
When you have a set of files like:
|
18
|
+
|
19
|
+
```
|
20
|
+
1.txt
|
21
|
+
2.txt
|
22
|
+
10.txt
|
23
|
+
11.txt
|
24
|
+
99.txt
|
25
|
+
100.txt
|
26
|
+
```
|
27
|
+
|
28
|
+
it's hard to get a list of them in order (from `1.txt` to `100.txt`). Shell of
|
29
|
+
file manager will usually sort them starting from first symbol in filename,
|
30
|
+
like this:
|
31
|
+
|
32
|
+
```
|
33
|
+
1.txt
|
34
|
+
10.txt
|
35
|
+
100.txt
|
36
|
+
11.txt
|
37
|
+
2.txt
|
38
|
+
99.txt
|
39
|
+
```
|
40
|
+
|
41
|
+
Nrename lets you rename such files so that they have equal number of digits in
|
42
|
+
names:
|
43
|
+
|
44
|
+
```
|
45
|
+
001.txt
|
46
|
+
002.txt
|
47
|
+
010.txt
|
48
|
+
011.txt
|
49
|
+
099.txt
|
50
|
+
100.txt
|
51
|
+
```
|
52
|
+
|
53
|
+
## Usage ##
|
54
|
+
|
55
|
+
See `nrename --help`
|
@@ -8,6 +8,11 @@ Feature: Options processing
|
|
8
8
|
Then the exit status should be 0
|
9
9
|
And the stdout should contain "Usage: nrename "
|
10
10
|
|
11
|
+
Scenario: Displaying help when run without options
|
12
|
+
When I run `nrename`
|
13
|
+
Then the exit status should be 0
|
14
|
+
And the stdout should contain "Usage: nrename "
|
15
|
+
|
11
16
|
Scenario: Displaying help when run without any options
|
12
17
|
When I run `nrename`
|
13
18
|
Then the exit status should be 0
|
@@ -16,7 +21,7 @@ Feature: Options processing
|
|
16
21
|
Scenario: Displaying version
|
17
22
|
When I run `nrename --version`
|
18
23
|
Then the exit status should be 0
|
19
|
-
And the stdout should match /^(\d+)
|
24
|
+
And the stdout should match /^(\d+)\.(\d+)\.(\d+)$/
|
20
25
|
|
21
26
|
Scenario: Passing valid directory name
|
22
27
|
Given a directory named "foo_bar"
|
@@ -39,8 +39,9 @@ Feature: Renaming files
|
|
39
39
|
| 10.txt |
|
40
40
|
| 0023.txt |
|
41
41
|
When I cd to "dir"
|
42
|
-
When I run `nrename
|
42
|
+
When I run `nrename .`
|
43
43
|
Then the exit status should be 0
|
44
|
+
And the stderr should contain "No renaming is done. Run with -X option to perform actual changes."
|
44
45
|
And the following files should exist:
|
45
46
|
| 1.txt |
|
46
47
|
| 10.txt |
|
data/features/support/env.rb
CHANGED
@@ -19,6 +19,10 @@ Then(/^the following files should exist inside directory "([^"]*)":$/) do |direc
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
Before do
|
23
|
+
@aruba_timeout_seconds = 10 # account for slow JVM startup
|
24
|
+
end
|
25
|
+
|
22
26
|
After do
|
23
27
|
FileUtils.rm_rf File.expand_path('../../../tmp', __FILE__)
|
24
28
|
end
|
data/lib/nrename.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
libdir = File.expand_path(File.dirname __FILE__)
|
2
|
+
$:.push libdir unless $:.include? libdir
|
2
3
|
|
3
4
|
require 'nrename/version'
|
4
5
|
require 'nrename/directory'
|
@@ -13,8 +14,6 @@ module Nrename
|
|
13
14
|
def self.run(args=[])
|
14
15
|
@options = Options.parse args
|
15
16
|
|
16
|
-
options.dirs
|
17
|
-
.map { |dir| Directory.new dir }
|
18
|
-
.each &:normalize
|
17
|
+
options.dirs.map { |dir| Directory.new dir }.each &:normalize
|
19
18
|
end
|
20
19
|
end
|
data/lib/nrename/directory.rb
CHANGED
@@ -15,9 +15,9 @@ module Nrename
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def numbered_files
|
18
|
-
@numbered_files ||= @dir.children
|
19
|
-
.
|
20
|
-
|
18
|
+
@numbered_files ||= @dir.children.select { |file|
|
19
|
+
!file.directory? && file.basename.to_s =~ @pattern
|
20
|
+
}
|
21
21
|
end
|
22
22
|
|
23
23
|
def num_field_length
|
data/lib/nrename/options.rb
CHANGED
@@ -63,6 +63,12 @@ module Nrename
|
|
63
63
|
end
|
64
64
|
end.parse!(args)
|
65
65
|
|
66
|
+
if !options.execute && executable_name == 'nrename'
|
67
|
+
at_exit do
|
68
|
+
warn 'No renaming is done. Run with -X option to perform actual changes.'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
66
72
|
args.each do |arg|
|
67
73
|
dir = File.expand_path arg
|
68
74
|
if File.directory? dir
|
data/lib/nrename/version.rb
CHANGED
@@ -85,7 +85,7 @@ describe Nrename::Directory do
|
|
85
85
|
|
86
86
|
describe '#normalize' do
|
87
87
|
before do
|
88
|
-
Nrename.options.stub execute
|
88
|
+
Nrename.options.stub :execute => true, :verbose => false
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'renames files so than they can be sorted properly' do
|
@@ -106,16 +106,16 @@ describe Nrename::Directory do
|
|
106
106
|
it 'returns normalized name for file' do
|
107
107
|
dir = Nrename::Directory.new test_dir
|
108
108
|
file = Pathname.new(test_dir) + 'b1.txt'
|
109
|
-
dir.stub num_field_length
|
109
|
+
dir.stub :num_field_length => 4
|
110
110
|
new_name = dir.normalized_name_for(file).basename.to_s
|
111
111
|
new_name.should be == 'b0001.txt'
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'returns bare number if numbers_only options is provided' do
|
115
|
-
Nrename.options.stub numbers_only
|
115
|
+
Nrename.options.stub :numbers_only => true
|
116
116
|
dir = Nrename::Directory.new test_dir
|
117
117
|
file = Pathname.new(test_dir) + 'b1.txt'
|
118
|
-
dir.stub num_field_length
|
118
|
+
dir.stub :num_field_length => 4
|
119
119
|
new_name = dir.normalized_name_for(file).basename.to_s
|
120
120
|
new_name.should be == '0001.txt'
|
121
121
|
end
|
@@ -140,7 +140,7 @@ describe Nrename::Directory do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
dir = Nrename::Directory.new test_dir
|
143
|
-
dir.stub num_field_length
|
143
|
+
dir.stub :num_field_length => 6
|
144
144
|
file = dir.numbered_files.first
|
145
145
|
dir.adjusted_number_string_for(file).should be == '000032'
|
146
146
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nrename
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,31 +9,43 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &72697810 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.2
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *72697810
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: rspec
|
16
|
-
requirement: &
|
27
|
+
requirement: &72697580 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
|
-
- -
|
30
|
+
- - ~>
|
20
31
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
32
|
+
version: 2.8.0
|
22
33
|
type: :development
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *72697580
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: aruba
|
27
|
-
requirement: &
|
38
|
+
requirement: &72697350 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
|
-
- -
|
41
|
+
- - ~>
|
31
42
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
43
|
+
version: 0.4.11
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
description:
|
46
|
+
version_requirements: *72697350
|
47
|
+
description: Nrename lets you rename set of numbered files so that they can be sorted
|
48
|
+
correctly in any shell or file manager.
|
37
49
|
email:
|
38
50
|
- vderyagin@gmail.com
|
39
51
|
executables:
|
@@ -41,19 +53,22 @@ executables:
|
|
41
53
|
extensions: []
|
42
54
|
extra_rdoc_files: []
|
43
55
|
files:
|
56
|
+
- MIT-LICENSE
|
57
|
+
- README.md
|
44
58
|
- bin/nrename
|
59
|
+
- features/options_processing.feature
|
60
|
+
- features/renaming_files.feature
|
61
|
+
- features/support/env.rb
|
62
|
+
- lib/nrename.rb
|
63
|
+
- lib/nrename/directory.rb
|
45
64
|
- lib/nrename/options.rb
|
46
65
|
- lib/nrename/version.rb
|
47
|
-
- lib/nrename/directory.rb
|
48
|
-
- lib/nrename.rb
|
49
|
-
- spec/spec_helper.rb
|
50
|
-
- spec/nrename/options_spec.rb
|
51
66
|
- spec/nrename/directory_spec.rb
|
52
|
-
-
|
53
|
-
-
|
54
|
-
|
55
|
-
|
56
|
-
|
67
|
+
- spec/nrename/options_spec.rb
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
homepage: https://github.com/vderyagin/nrename
|
70
|
+
licenses:
|
71
|
+
- MIT
|
57
72
|
post_install_message:
|
58
73
|
rdoc_options: []
|
59
74
|
require_paths:
|
@@ -69,18 +84,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
84
|
requirements:
|
70
85
|
- - ! '>='
|
71
86
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
87
|
+
version: 1.3.6
|
73
88
|
requirements: []
|
74
89
|
rubyforge_project: nrename
|
75
90
|
rubygems_version: 1.8.10
|
76
91
|
signing_key:
|
77
92
|
specification_version: 3
|
78
|
-
summary:
|
79
|
-
test_files:
|
80
|
-
- spec/spec_helper.rb
|
81
|
-
- spec/nrename/options_spec.rb
|
82
|
-
- spec/nrename/directory_spec.rb
|
83
|
-
- features/renaming_files.feature
|
84
|
-
- features/support/env.rb
|
85
|
-
- features/options_processing.feature
|
93
|
+
summary: Command-line utility for renaming numbered files.
|
94
|
+
test_files: []
|
86
95
|
has_rdoc:
|