aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeus Panchenko <zeus@camb.us>2006-05-03 21:59:52 +0000
committerZeus Panchenko <zeus@camb.us>2006-05-03 21:59:52 +0000
commit2dbb147f602abaa3eabb5ccb003a84acfc9c0b95 (patch)
tree56ad554c7202e456636c05e0d5d62367cd5aa876
parent29f01cde1ce5f31ca93429f329c99e9c5d09b2d6 (diff)
downloadrenrot-2dbb147f602abaa3eabb5ccb003a84acfc9c0b95.tar.gz
renrot-2dbb147f602abaa3eabb5ccb003a84acfc9c0b95.tar.bz2
file aggregation via option --aggr-template has been implemented.
control code for file name originality has been moved from template2name() to main(). README edited git-svn-id: file:///svnroot/renrot/trunk@88 fe2816f4-e837-0410-b10a-f608c9d244a1
-rw-r--r--ChangeLog7
-rw-r--r--README9
-rwxr-xr-xrenrot75
3 files changed, 77 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 651959c..15973d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,12 @@
1$Log$ 1$Log$
2Revision 1.57 2006/05/03 21:59:52 zeus
3file aggregation via option --aggr-template has been implemented.
4control code for file name originality has been moved from template2name() to main().
5README edited
6
2Revision 1.56 2006/05/02 19:08:59 zeus 7Revision 1.56 2006/05/02 19:08:59 zeus
3item about aggregation is added to TODO. 8item about aggregation is added to TODO.
4minor language ixes in README 9minor language ixes in README.
5 10
6Revision 1.55 2006/05/02 09:07:02 andy 11Revision 1.55 2006/05/02 09:07:02 andy
7Wrote RESTRICTIONS section in README. 12Wrote RESTRICTIONS section in README.
diff --git a/README b/README
index ec94c27..16a317a 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ of project is short form of 'REName and ROTate' and no other interpretation
8will be used. 8will be used.
9 9
10Renrot is intended to work only in current directory with all files of the 10Renrot is intended to work only in current directory with all files of the
11extension, specified after --ext. You can change the behaviour by specify 11extension, specified after --ext. You can change the behaviour by specifying
12--work-directory option. 12--work-directory option.
13 13
14New template ideology was implemented. It includes flexibility in file name 14New template ideology was implemented. It includes flexibility in file name
@@ -28,6 +28,8 @@ Furthermore, the script can put a comment to:
28 28
29Personal data could be specified via XMP tags defined in configuration file. 29Personal data could be specified via XMP tags defined in configuration file.
30 30
31In addition renrot can aggregate all files in directories according the given
32date/time pattern template, set with --aggr-template.
31 33
32WHY RenRot? 34WHY RenRot?
33 35
@@ -41,6 +43,7 @@ namely RenRot? Because:
41 libjpeg6 (the best open tool to operate JPEG format files, to correctly 43 libjpeg6 (the best open tool to operate JPEG format files, to correctly
42 rotate both, the very file and the thumbnail inside it); 44 rotate both, the very file and the thumbnail inside it);
43 - it has very much flex file naming template engine; 45 - it has very much flex file naming template engine;
46 - it has very much flex file aggregation template engine;
44 - it works in batch mode. 47 - it works in batch mode.
45 48
46 49
@@ -61,6 +64,10 @@ applications of the script:
61 rename each file according to the given template 64 rename each file according to the given template
62 renrot --name-template="01.%c.%Y%m%d%H%M%S.%i.%E%F%W%I" --ext JPG 65 renrot --name-template="01.%c.%Y%m%d%H%M%S.%i.%E%F%W%I" --ext JPG
63 66
67 rename each file according to the given template and files aggregation
68 according the date
69 renrot --name-template="%y%m%d%H%M%S.%i" --aggr-template "%Y%m%d" --ext JPG
70
64 rotate each file and their thumbnail by 90CW in specified directory 71 rotate each file and their thumbnail by 90CW in specified directory
65 renrot --rotate 90 --ext '*.jpg' --work-directory="/tmp/images" 72 renrot --rotate 90 --ext '*.jpg' --work-directory="/tmp/images"
66 73
diff --git a/renrot b/renrot
index 5aa5a64..3fa6e61 100755
--- a/renrot
+++ b/renrot
@@ -19,6 +19,7 @@ my $rotateThumbnail; # define the angle, to rotate on, 90 or 270
19my $noRename; # no rename needed, default is to rename to the YYYYmmddHHMMSS.jpg 19my $noRename; # no rename needed, default is to rename to the YYYYmmddHHMMSS.jpg
20my $noComment; # no comment needed 20my $noComment; # no comment needed
21my $nameTemplate; # template for the filename taken from CLI 21my $nameTemplate; # template for the filename taken from CLI
22my $aggrTemplate; # template for the files aggregation taken from CLI
22my $extentionToProcess; # the extention of files to work with 23my $extentionToProcess; # the extention of files to work with
23my $extentionToProcessLowCase; # lowercased extention of files to work with 24my $extentionToProcessLowCase; # lowercased extention of files to work with
24my $usageOutput = 0; # flag to show the usage 25my $usageOutput = 0; # flag to show the usage
@@ -71,6 +72,7 @@ sub getopt {
71 "no-rename" => \$noRename, 72 "no-rename" => \$noRename,
72 "comment-file=s" => \$comfile, 73 "comment-file=s" => \$comfile,
73 "name-template=s" => \$nameTemplate, 74 "name-template=s" => \$nameTemplate,
75 "aggr-template=s" => \$aggrTemplate,
74 "mtime" => \$mtime, 76 "mtime" => \$mtime,
75 "config-file|c=s" => \$configFile, 77 "config-file|c=s" => \$configFile,
76 "v+" => \$verbose, 78 "v+" => \$verbose,
@@ -247,15 +249,23 @@ foreach $file ( @files ) {
247 # 249 #
248 if ( defined $noRename ) { 250 if ( defined $noRename ) {
249 infomsg ("No renaming asked, filename is left untouched.\n"); 251 infomsg ("No renaming asked, filename is left untouched.\n");
250 $newfilename = $file; 252 if ( ($newfilename) = ( $file =~ /^(.*)\.jpg/ ) ) {
253 $filenameshash{$newfilename} = 1;
254 }
251 } 255 }
252 else { 256 else {
253 $newfilename = sprintf("%s.%s", template2name($NameTemplate), $extentionToProcessLowCase); 257 $newfilename = template2name($NameTemplate);
258 if ( $filenameshash{$newfilename} ) {
259 $newfilename = sprintf("%s.%.4d",$newfilename,$filecounter);
260 }
261 $filenameshash{$newfilename} = 1;
262
263 $newfilename = sprintf("%s.%s", $newfilename, $extentionToProcessLowCase);
254 264
255 if ( $file ne $newfilename ) { 265 if ( $file ne $newfilename ) {
256 if ( -f $newfilename ) { 266 if ( -f $newfilename ) {
257 fatalmsg ("File $newfilename already exists!\n"), die 267 fatalmsg ("File $newfilename already exists!\n"), die;
258 }; 268 }
259 rename ( $file, $newfilename ) 269 rename ( $file, $newfilename )
260 || ( fatalmsg ("Unable to rename $file -> $newfilename.\n"), die ); 270 || ( fatalmsg ("Unable to rename $file -> $newfilename.\n"), die );
261 print "Renamed: $file -> $newfilename\n"; 271 print "Renamed: $file -> $newfilename\n";
@@ -342,6 +352,27 @@ foreach $file ( @files ) {
342 352
343closedir(DIR); 353closedir(DIR);
344 354
355########################################################################################
356#
357# file aggregation if requested
358#
359if ( defined $aggrTemplate ) {
360 infomsg ("NOW IS FILE AGGREGATION\n=======================\n\n");
361 $filecounter=1;
362 foreach $file ( sort ( keys %filenameshash ) ) {
363 $file .= ".jpg";
364 $info = $exifTool->ImageInfo($file);
365 $newfilename = template2name($aggrTemplate);
366 if ( not -d $newfilename ) {
367 unless ( mkdir $newfilename ) { errmsg ("$newfilename wasn't created!\n"); }
368 }
369 infomsg ( "$file has been aggregated to the directory $newfilename\n" );
370 $newfilename .= "/" . $file;
371 rename ( $file, $newfilename ) || ( fatalmsg ("$file -> $newfilename\n"), die );
372 $filecounter++;
373 }
374}
375
345exit 0; 376exit 0;
346 377
347######################################################################################## 378########################################################################################
@@ -404,7 +435,7 @@ sub getTimestamp {
404 $timestamp = timeNow(); 435 $timestamp = timeNow();
405 warnmsg ("EXIF timestamp isn't correct, using timeNow()!\n"); 436 warnmsg ("EXIF timestamp isn't correct, using timeNow()!\n");
406 } 437 }
407 438
408 return $timestamp; 439 return $timestamp;
409} 440}
410 441
@@ -553,6 +584,7 @@ infomsg (
553 it's for the files which were rotated, but thumbnail wasn't 584 it's for the files which were rotated, but thumbnail wasn't
554 --no-rename no rename needed, default is to rename to the YYYYmmddHHMMSS.jpg 585 --no-rename no rename needed, default is to rename to the YYYYmmddHHMMSS.jpg
555 --name-template <TPL> filename template (see manual for details) 586 --name-template <TPL> filename template (see manual for details)
587 --aggr-template <TPL> aggregation template (see manual for details)
556 --mtime to set file mtime according DateTimeOriginal tag value 588 --mtime to set file mtime according DateTimeOriginal tag value
557 --comment-file <FILE> file with commentary 589 --comment-file <FILE> file with commentary
558 --version the version of this script 590 --version the version of this script
@@ -637,12 +669,6 @@ sub template2name {
637 else { $thename .= $substrchar; } 669 else { $thename .= $substrchar; }
638 } 670 }
639 671
640 if ( $filenameshash{$thename} ) {
641 $thename = sprintf("%s.%s",$thename,$templatehash{"c"});
642 }
643
644 $filenameshash{$thename} = 1;
645
646 return $thename; 672 return $thename;
647} 673}
648 674
@@ -659,7 +685,7 @@ renrot [OPTIONS]
659=head1 DESCRIPTION 685=head1 DESCRIPTION
660 686
661B<RenRot> is intended to work ONLY in current directory. You can change the 687B<RenRot> is intended to work ONLY in current directory. You can change the
662behaviour by specify B<--work-directory> option. 688behaviour by specifying B<--work-directory> option.
663 689
664Renrot renames files according the DateTimeOriginal and FileModifyDate EXIF 690Renrot renames files according the DateTimeOriginal and FileModifyDate EXIF
665tags, if they exist. Otherwise, the name will be set according to the current 691tags, if they exist. Otherwise, the name will be set according to the current
@@ -684,6 +710,9 @@ The script can also put commentary into:
684Personal details can be specified via XMP tags defined in a configuration 710Personal details can be specified via XMP tags defined in a configuration
685file, look L<CONFIG> section. 711file, look L<CONFIG> section.
686 712
713In addition renrot can aggregate all files in directories according the given
714date/time pattern template, set with B<--aggr-template>.
715
687=head1 OPTIONS 716=head1 OPTIONS
688 717
689=over 718=over
@@ -780,6 +809,28 @@ B<%y> last two digits of year (00..99)
780 809
781=back 810=back
782 811
812=item B<--aggr-template> I<Aggregation TEMPLATE>
813
814template, which is used for file aggregation. Aggragation fulfils according date/time patterns.
815
816=over
817
818B<%d> day of the month (01-31)
819
820B<%H> hour (00-23)
821
822B<%M> minute (00-59)
823
824B<%m> month (01-12)
825
826B<%S> second (00-59)
827
828B<%Y> year (1900, 1901, and so on)
829
830B<%y> last two digits of year (00..99)
831
832=back
833