phtools 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +7 -1
- data/README.md +22 -3
- data/TODO.md +3 -1
- data/exe/phbackup +31 -0
- data/exe/phrename +11 -11
- data/lib/phbackup.rb +33 -1
- data/lib/phmove.rb +17 -2
- data/lib/phrename.rb +30 -18
- data/lib/phtools/runner.rb +3 -4
- data/lib/phtools/utils/dir.rb +9 -0
- data/lib/phtools/utils/os_unix.rb +2 -1
- data/lib/phtools/utils/os_win.rb +1 -1
- data/lib/phtools/utils.rb +7 -0
- data/lib/phtools/version.rb +1 -1
- data/lib/phtools.rb +2 -4
- metadata +5 -2
- data/lib/phclname.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 750f4b068327ffb6e442bd159b3954bc6a4e05a9
|
4
|
+
data.tar.gz: 0c3dd2cf633fc173198db39b52bf0158b2b4cb83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67221245339260073f68931c40fcc7c032733c29a82b66e9c2f2515d68d9c91a42f187c06b634e69175bc6e99ef0f2a9231daa3db670c6ba92c561931789d8be
|
7
|
+
data.tar.gz: b7783f37b130f55dae57a95f285bdee3bf0e65b7ac077e3d46ef01601d83f74ae1dc8e113917ef9ad05bbff2bb3cecb714af14f602ce00fe330465ed684d069e
|
data/History.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# RELEASED
|
2
2
|
|
3
|
+
## [v0.4.0](https://github.com/andrewbiz/phtools/compare/v0.3.0.pre.alpha...v0.4.0)
|
4
|
+
* Added description to README.md
|
5
|
+
* Changed phls - option -R instead of -r (ls compatibility)
|
6
|
+
* Added phmove command
|
7
|
+
* Added phrename command
|
8
|
+
|
3
9
|
## [v0.3.0.pre.alpha](https://github.com/andrewbiz/phtools/compare/v0.2.4...v0.3.0.pre.alpha)
|
4
10
|
|
5
|
-
* Improved
|
11
|
+
* Improved phls - now it supports DIRs and FILEMASKs parameters
|
6
12
|
* Added aruba (cucumber) tests for phls
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ A bundle of small CLI tools for arranging, renaming, tagging of the photo and vi
|
|
5
5
|
## Rationale
|
6
6
|
PHTOOLS is an instrument intended for photographers\photo enthusiasts who:
|
7
7
|
* own tons of photo-video files and want to keep it in order
|
8
|
-
* really don't like the way how digital cameras name the files: P1193691.JPG, IMP_1409.JPG, _DSC1459.ARW etc.
|
8
|
+
* really don't like the way how digital cameras name the files: P1193691.JPG, IMP_1409.JPG, \_DSC1459.ARW etc.
|
9
9
|
* for photo storage prefer usage of traditional File System (folder structure) instead of "black box" databases of media managers (like iPhoto, Photoshop etc.)
|
10
10
|
* would like to have date-time-original info in the name of the file
|
11
11
|
* expects that sorting folder content "by name" will arrange photo-video assets in chronological order
|
@@ -56,11 +56,31 @@ And all videos are moved to `~/Desktop/assets_staging/VIDEO`.
|
|
56
56
|
|
57
57
|
And all raw photo-files are moved to `~/Desktop/assets_staging/RAW`.
|
58
58
|
|
59
|
+
### Use Case 2. Mass rename photos in accordance with PHTOOLS standard (and don't forget to backup before)
|
60
|
+
|
61
|
+
#### Given
|
62
|
+
I have dozens of photo-files in my working folder `~/Desktop/assets_staging`.
|
63
|
+
|
64
|
+
And my friend Alex it the author of the photos (nikname ALX).
|
65
|
+
|
66
|
+
#### When
|
67
|
+
I run:
|
68
|
+
```sh
|
69
|
+
cd ~/Desktop/assets_staging
|
70
|
+
phls | phbackup | phrename -a alx
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Then
|
74
|
+
I get all photos in `~/Desktop/assets_staging` renamed according to PHTOOLS standard.
|
75
|
+
|
76
|
+
And I have all original photo-files are backed-up to `~/Desktop/assets_staging/backup`.
|
77
|
+
|
78
|
+
|
59
79
|
## PHTOOLS concepts
|
60
80
|
### PHTOOLS Standard file name
|
61
81
|
PHTOOLS standard file name looks like this: **`YYYYmmdd-HHMMSS_AAA ORIGINAL.EXT`**, where
|
62
82
|
|
63
|
-
**YYYYmmdd-HHMMSS** - photo creation datestamp (year-month-day-hours-minutes-seconds). By default PHTOOLS use the value of EXIF tag `DateTimeOriginal` or `CreateDate` for this purpose.
|
83
|
+
**YYYYmmdd-HHMMSS** - photo creation datestamp (year-month-day-hours-minutes-seconds). By default PHTOOLS use the value of EXIF tag `DateTimeOriginal` or `CreateDate` for this purpose.
|
64
84
|
|
65
85
|
**AAA** - author nikname. 3 character long, only latin alphabet supported.
|
66
86
|
|
@@ -68,4 +88,3 @@ PHTOOLS standard file name looks like this: **`YYYYmmdd-HHMMSS_AAA ORIGINAL.EXT`
|
|
68
88
|
|
69
89
|
For example, the digital camera photo file `P1193691.JPG`, taken by AndrewBiz (aka ANB), after PHTOOLS processing will look like:
|
70
90
|
`20160902-174939_ANB P1193691.JPG`
|
71
|
-
|
data/TODO.md
CHANGED
@@ -5,5 +5,7 @@
|
|
5
5
|
- [x] phmove: create phmove tool based on ftarrange code (see ftools repo)
|
6
6
|
- [x] phmove: make target_folder as parameter not an option
|
7
7
|
- [x] phmove: -a (--arrange) parameter means to put photo, video, raw files into separate folders inside target. If -a is not set all files are moved to root of target directory (plain collection of files)
|
8
|
-
- [
|
8
|
+
- [x] phmove: delete unused empty RAW and VIDEO folders
|
9
9
|
- [ ] phmove: make options to set video, raw folder names
|
10
|
+
- [x] phrename: add -c --clean option (based on ftclname functionality)
|
11
|
+
- [ ] phrename: add -s --shift_time option (based on ftfixdate functionality)
|
data/exe/phbackup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# (c) ANB Andrew Bizyaev
|
4
|
+
|
5
|
+
module PhTools
|
6
|
+
tool_name = File.basename(__FILE__)
|
7
|
+
require "#{tool_name}"
|
8
|
+
|
9
|
+
file_type = FILE_TYPE_IMAGE + FILE_TYPE_VIDEO + FILE_TYPE_AUDIO
|
10
|
+
usage = <<DOCOPT
|
11
|
+
***************************************************
|
12
|
+
phtools - *Keep Your Photos In Order* (c) ANB
|
13
|
+
***************************************************
|
14
|
+
#{tool_name} copies the input file to backup directory.
|
15
|
+
Optimized to be used with other *phtools* via pipes.
|
16
|
+
Example: phls | #{tool_name} | phrename ...
|
17
|
+
|
18
|
+
Usage:
|
19
|
+
#{tool_name} [--backup DIR] [-D]
|
20
|
+
#{tool_name} -h | --help
|
21
|
+
#{tool_name} -v | --version
|
22
|
+
|
23
|
+
Options:
|
24
|
+
-b DIR --backup=DIR Sets the backup directory [Default: ./backup]
|
25
|
+
-D --debug Turn on debugging (verbose) mode
|
26
|
+
-h --help Show this screen.
|
27
|
+
-v --version Show version.
|
28
|
+
DOCOPT
|
29
|
+
|
30
|
+
PhTools.const_get(tool_name.capitalize).new(usage, file_type).run!
|
31
|
+
end
|
data/exe/phrename
CHANGED
@@ -23,23 +23,23 @@ Example: input file DSC03455.JPG will be renamed to 20130108-124145_ANB DSC03455
|
|
23
23
|
phls | #{tool_name} -a anb
|
24
24
|
|
25
25
|
This program uses external utility ExifTool by Phil Harvey
|
26
|
-
(http://www.sno.phy.queensu.ca/~phil/exiftool/).
|
26
|
+
(http://www.sno.phy.queensu.ca/~phil/exiftool/).
|
27
27
|
|
28
28
|
Usage:
|
29
|
-
#{tool_name} -a
|
29
|
+
#{tool_name} -a NICK [-D] [-t TAG]
|
30
|
+
#{tool_name} -c [-D]
|
30
31
|
#{tool_name} -h | --help
|
31
32
|
#{tool_name} -v | --version
|
32
33
|
|
33
34
|
Options:
|
34
|
-
-a
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
using command `phls filename|phmtags -f`
|
35
|
+
-a NICK --author=NICK Author nickname size should be #{PhFile::NICKNAME_SIZE} chars,
|
36
|
+
supports only latin ASCII chars (e.g. ANB).
|
37
|
+
No digits, no spaces, no other non-word chars allowed.
|
38
|
+
-t TAG --tag_date=TAG Set the TAG name containing Date_Time creation
|
39
|
+
info. The TAG value will be used instead of
|
40
|
+
standard DateTimeOriginal tag. All existing tags you
|
41
|
+
can get using command `phls filename|phmtags -f`
|
42
|
+
-c --clean Rename file(s) back to original name(s)
|
43
43
|
-D --debug Turn on debugging (verbose) mode
|
44
44
|
-h --help Show this screen.
|
45
45
|
-v --version Show version.
|
data/lib/phbackup.rb
CHANGED
@@ -6,8 +6,40 @@ require 'phtools/runner'
|
|
6
6
|
|
7
7
|
module PhTools
|
8
8
|
class Phbackup < Runner
|
9
|
+
|
9
10
|
def self.about
|
10
|
-
"
|
11
|
+
"copies input files to backup folder"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def validate_options
|
17
|
+
@backup_dir = @options_cli['--backup'] || ''
|
18
|
+
fail PhTools::Error, 'backup dir is not defined' if @backup_dir.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_before
|
22
|
+
if File.exist?(@backup_dir)
|
23
|
+
fail PhTools::Error, "#{@backup_dir} is not a directory" unless
|
24
|
+
File.directory?(@backup_dir)
|
25
|
+
fail PhTools::Error, "#{@backup_dir} is not writable" unless
|
26
|
+
File.writable?(@backup_dir)
|
27
|
+
else
|
28
|
+
begin
|
29
|
+
Dir.mkdir @backup_dir
|
30
|
+
rescue
|
31
|
+
raise PhTools::Error, "Unable to make dir '#{@backup_dir}'"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_file(phfile)
|
37
|
+
backup_path = File.join(@backup_dir,
|
38
|
+
phfile.basename + phfile.extname)
|
39
|
+
FileUtils.cp(phfile.filename, backup_path, verbose: PhTools.debug)
|
40
|
+
phfile
|
41
|
+
rescue
|
42
|
+
raise PhTools::Error, "file copying to #{@backup_dir}"
|
11
43
|
end
|
12
44
|
end
|
13
45
|
end
|
data/lib/phmove.rb
CHANGED
@@ -9,6 +9,7 @@ module PhTools
|
|
9
9
|
def self.about
|
10
10
|
"moves input files to target folder"
|
11
11
|
end
|
12
|
+
|
12
13
|
private
|
13
14
|
|
14
15
|
def validate_options
|
@@ -27,8 +28,10 @@ module PhTools
|
|
27
28
|
fail PhTools::Error, "#{@target_folder} does not exist" unless File.exist?(@target_folder)
|
28
29
|
fail PhTools::Error, "#{@target_folder} is not a directory" unless File.directory?(@target_folder)
|
29
30
|
begin
|
30
|
-
|
31
|
-
|
31
|
+
if @arrange
|
32
|
+
Dir.mkdir @raw_folder unless Dir.exist?(@raw_folder)
|
33
|
+
Dir.mkdir @video_folder unless Dir.exist?(@video_folder)
|
34
|
+
end
|
32
35
|
rescue
|
33
36
|
raise PhTools::Error, "Unable to make dir inside '#{@target_folder}'"
|
34
37
|
end
|
@@ -53,5 +56,17 @@ module PhTools
|
|
53
56
|
rescue SystemCallError => e
|
54
57
|
raise PhTools::Error, 'file moving - ' + e.message
|
55
58
|
end
|
59
|
+
|
60
|
+
def process_after
|
61
|
+
if @arrange
|
62
|
+
Dir.delete @raw_folder if (Dir.exist?(@raw_folder) and
|
63
|
+
Utils.dir_empty?(@raw_folder))
|
64
|
+
Dir.delete @video_folder if (Dir.exist?(@video_folder) and
|
65
|
+
Utils.dir_empty?(@video_folder))
|
66
|
+
end
|
67
|
+
rescue
|
68
|
+
raise PhTools::Error, "Unable to delete dir"
|
69
|
+
end
|
70
|
+
|
56
71
|
end
|
57
72
|
end
|
data/lib/phrename.rb
CHANGED
@@ -14,30 +14,42 @@ module PhTools
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def validate_options
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
if @options_cli['--author']
|
18
|
+
@mode = :rename
|
19
|
+
@author = @options_cli['--author'].upcase
|
20
|
+
ok, msg = PhFile.validate_author(@author)
|
21
|
+
fail PhTools::Error, msg unless ok
|
22
|
+
@user_tag_date = @options_cli['--tag_date'] || ''
|
23
|
+
elsif @options_cli['--clean']
|
24
|
+
@mode = :clean
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
28
|
def process_file(phfile)
|
24
29
|
phfile_out = phfile.clone
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
case @mode
|
31
|
+
when :rename
|
32
|
+
begin
|
33
|
+
tag = MiniExiftool.new(phfile.filename, timestamps: DateTime)
|
34
|
+
rescue
|
35
|
+
raise PhTools::Error, 'EXIF tags reading'
|
36
|
+
end
|
37
|
+
if @user_tag_date.empty?
|
38
|
+
dto = tag.date_time_original || tag.create_date || PhFile::ZERO_DATE
|
39
|
+
else
|
40
|
+
fail PhTools::Error, "tag #{@user_tag_date} is not found" unless tag[@user_tag_date]
|
41
|
+
fail PhTools::Error, "tag #{@user_tag_date} is not a DateTime type" unless tag[@user_tag_date].kind_of?(DateTime)
|
42
|
+
dto = tag[@user_tag_date] || PhFile::ZERO_DATE
|
43
|
+
end
|
44
|
+
phfile_out.standardize!(date_time: dto, author: @author)
|
45
|
+
|
46
|
+
when :clean
|
47
|
+
phfile_out.cleanse!
|
36
48
|
end
|
37
|
-
|
38
|
-
FileUtils.mv(phfile.filename, phfile_out.filename) unless
|
39
|
-
phfile == phfile_out
|
49
|
+
|
50
|
+
FileUtils.mv(phfile.filename, phfile_out.filename) unless phfile == phfile_out
|
40
51
|
phfile_out
|
52
|
+
|
41
53
|
rescue => e
|
42
54
|
raise PhTools::Error, 'file renaming - ' + e.message
|
43
55
|
end
|
data/lib/phtools/runner.rb
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
# (c) ANB Andrew Bizyaev
|
4
4
|
|
5
|
-
require 'phtools/version'
|
6
5
|
require 'phtools/utils/ruby_version.rb'
|
7
|
-
require 'phtools/
|
8
|
-
require 'phtools/utils
|
6
|
+
require 'phtools/version'
|
7
|
+
require 'phtools/utils'
|
9
8
|
require 'phtools/error.rb'
|
10
9
|
require 'phtools/ph_file.rb'
|
11
10
|
require 'docopt'
|
@@ -37,7 +36,7 @@ module PhTools
|
|
37
36
|
|
38
37
|
rescue Docopt::Exit => e
|
39
38
|
STDERR.puts e.message
|
40
|
-
exit
|
39
|
+
exit 1
|
41
40
|
rescue => e
|
42
41
|
PhTools.puts_error "FATAL: #{e.message}", e
|
43
42
|
exit 1
|
data/lib/phtools/utils/os_win.rb
CHANGED
data/lib/phtools/version.rb
CHANGED
data/lib/phtools.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
# (c) ANB Andrew Bizyaev
|
4
4
|
require 'phtools/version'
|
5
5
|
require 'phbackup'
|
6
|
-
require 'phclname'
|
7
6
|
require 'phevent'
|
8
7
|
require 'phfixdate'
|
9
8
|
require 'phfixfmd'
|
@@ -19,15 +18,14 @@ module PhTools
|
|
19
18
|
phtools v#{VERSION} is a bundle of small CLI tools for arranging, renaming, tagging
|
20
19
|
of the photo and video files. Helps to keep your photo-video assets in order.
|
21
20
|
Please run phtools in a terminal via CLI commands:
|
21
|
+
phls\t(#{Phls::about}),
|
22
22
|
phmove\t(#{Phmove::about}),
|
23
23
|
phbackup\t(#{Phbackup::about}),
|
24
|
-
|
24
|
+
phrename\t(#{Phrename::about}),
|
25
25
|
phevent\t(#{Phevent::about}),
|
26
26
|
phfixdate\t(#{Phfixdate::about}),
|
27
27
|
phfixfmd\t(#{Phfixfmd::about}),
|
28
|
-
phls\t(#{Phls::about}),
|
29
28
|
phmtags\t(#{Phmtags::about}),
|
30
|
-
phrename\t(#{Phrename::about}),
|
31
29
|
phtagset\t(#{Phtagset::about}).
|
32
30
|
For more information run these commands with -h option.
|
33
31
|
General info about phtools usage see at https://github.com/AndrewBiz/phtools.git
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phtools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Bizyaev
|
@@ -239,6 +239,7 @@ description: A bundle of small CLI tools for arranging, renaming, tagging of the
|
|
239
239
|
email:
|
240
240
|
- andrew.bizyaev@gmail.com
|
241
241
|
executables:
|
242
|
+
- phbackup
|
242
243
|
- phls
|
243
244
|
- phmove
|
244
245
|
- phrename
|
@@ -259,12 +260,12 @@ files:
|
|
259
260
|
- bin/console
|
260
261
|
- bin/setup
|
261
262
|
- bin/stmux
|
263
|
+
- exe/phbackup
|
262
264
|
- exe/phls
|
263
265
|
- exe/phmove
|
264
266
|
- exe/phrename
|
265
267
|
- exe/phtools
|
266
268
|
- lib/phbackup.rb
|
267
|
-
- lib/phclname.rb
|
268
269
|
- lib/phevent.rb
|
269
270
|
- lib/phfixdate.rb
|
270
271
|
- lib/phfixfmd.rb
|
@@ -278,6 +279,8 @@ files:
|
|
278
279
|
- lib/phtools/mini_exiftool-2.3.0anb.rb
|
279
280
|
- lib/phtools/ph_file.rb
|
280
281
|
- lib/phtools/runner.rb
|
282
|
+
- lib/phtools/utils.rb
|
283
|
+
- lib/phtools/utils/dir.rb
|
281
284
|
- lib/phtools/utils/os.rb
|
282
285
|
- lib/phtools/utils/os_unix.rb
|
283
286
|
- lib/phtools/utils/os_win.rb
|