aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shevchenko <andy@smile.org.ua>2006-08-22 07:18:22 +0000
committerAndy Shevchenko <andy@smile.org.ua>2006-08-22 07:18:22 +0000
commit165a725a6cf238b9bf25e858a1c2af566e7c9655 (patch)
tree5b8b813b7c8b273b83862eb472d8f9248e65d458
parentf494599aecd21266e9852085b3b73cea48e760bd (diff)
downloadrenrot-165a725a6cf238b9bf25e858a1c2af566e7c9655.tar.gz
renrot-165a725a6cf238b9bf25e858a1c2af566e7c9655.tar.bz2
The colorization for output has been implemented, the options --use-color and
--color were added. git-svn-id: file:///svnroot/renrot/branches/RENROT_STABLE@249 fe2816f4-e837-0410-b10a-f608c9d244a1
-rw-r--r--ChangeLog5
-rw-r--r--NEWS12
-rw-r--r--etc/colors.conf13
-rw-r--r--etc/renrot.conf3
-rwxr-xr-xrenrot129
-rw-r--r--renrot.spec5
6 files changed, 153 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e53605..97b215c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
$Log$
+Revision 1.148.2.4 2006/08/22 07:18:22 andy
+The colorization for output has been implemented, the options --use-color and
+--color were added.
+
Revision 1.148.2.3 2006/08/19 10:59:19 andy
Release as 0.23.
@@ -605,3 +609,4 @@ Id keyword is added to renrot file.
Revision 1.1 2005/10/17 13:39:38 zeus
ChangeLog file is added. Its the very begining.
+
diff --git a/NEWS b/NEWS
index b34b557..7b11f78 100644
--- a/NEWS
+++ b/NEWS
@@ -1,12 +1,12 @@
* 0.23 *
-The additional template sequences %C, %O, and %o had been added. They are
-represented the original filename counter, base part and full copy of the
-original filename respectively. A new tag RenRotFileNameOriginal is writing
-after first pass by renrot. On a Win32 platform the home path is taken from
-the environment variable USERPROFILE instead of HOME. The IPC support for
+The additional template sequences %C, %O, and %o had been added. They
+represent the original filename counter, base part, and full copy of the
+original filename respectively. A new tag, RenRotFileNameOriginal, is written
+after the first pass by renrot. On the Win32 platform, the home path is taken
+from the environment variable USERPROFILE instead of HOME. The IPC support for
rotating thumbnails has been added. The output messages of the usage function
-had been reformatted.
+have been reformatted.
* 0.22 *
diff --git a/etc/colors.conf b/etc/colors.conf
new file mode 100644
index 0000000..73297ce
--- /dev/null
+++ b/etc/colors.conf
@@ -0,0 +1,13 @@
+#
+## This is configuration file for RenRot. See commented variables for defaults.
+#
+# Note: These variables can be overriden by command line options.
+
+# Setup colors for different facilities
+
+#Color = debug: 'green'
+#Color = error: 'magenta'
+#Color = fatal: 'red'
+#Color = info: 'bold'
+#Color = process: 'white'
+#Color = warning: 'cyan'
diff --git a/etc/renrot.conf b/etc/renrot.conf
index 6c62ba4..3b564e7 100644
--- a/etc/renrot.conf
+++ b/etc/renrot.conf
@@ -3,6 +3,9 @@
#
# Note: These variables can be overriden by command line options.
+# Include color scheme
+#include = '/etc/renrot/colors.conf'
+
# Whether to keywordize the files (see option --keywordize description for details)
#keywordize = No
diff --git a/renrot b/renrot
index f489fcb..7307d3d 100755
--- a/renrot
+++ b/renrot
@@ -12,6 +12,11 @@ use Time::Local;
use Image::ExifTool;
use Getopt::Long;
+use Term::ANSIColor;
+
+$Term::ANSIColor::AUTORESET = 1;
+$Term::ANSIColor::EACHLINE = "\n";
+
our $VERSION = "0.23"; # the version of this script
my $maxVerbosity = 4; # our max verbosity level (internal)
@@ -79,6 +84,7 @@ my $aggrTemplate; # template for the files aggregation taken from CLI
my $aggrVirtual; # flag to do links instead real file moving while aggregation
my $aggrVirtDir; # directory name for virtual aggregation
my $backup = 1; # make or not a backup of the original files
+my %colorsFromCli; # colors are got from CLI
my $comfile; # file with commentary
my $configFile; # configuration file
my $countFF = 1; # use fixed field for counter
@@ -101,6 +107,7 @@ my $rotateAngle; # define the angle to rotate on 90, 180 or 270
my $rotateThumbnail; # define the angle to rotate on 90, 180 or 270
my %tagsFromCli; # tags are got from CLI
my $trim; # jpegtran -trim
+my $useColor; # colorized output
my $useIPC; # rotate thumbnail via pipe
my $userComment; # text to put into UserComment tag
my $verbose = 0; # verbosity of output
@@ -173,41 +180,78 @@ my %rotorientrev = reverse %rotorient;
my %incFiles; # hash of included files while parsing configuration file
my @multOpts = (
+ 'color',
+ 'include',
'tag',
'tagfile',
- 'include',
);
+########################################################################################
+#
+# Colors hash
+#
+my %colors = (
+ debug => 'green',
+ error => 'magenta',
+ fatal => 'red',
+ info => 'bold',
+ process => 'white',
+ warning => 'cyan',
+);
+
+# Prints colored message to STDERR
+sub printColored {
+ my $facility = shift;
+
+ if (defined $useColor and $useColor != 0) {
+ if (defined $facility and defined $colors{$facility}) {
+ print STDERR colored [$colors{$facility}], @_;
+ return;
+ }
+ }
+
+ print STDERR @_; # fallback to normal print
+}
+
# processing message
sub procmsg {
- print @_ if ($quiet == 0);
+ return if ($quiet != 0);
+
+ if (defined $useColor and $useColor != 0) {
+ if (defined $colors{'process'}) {
+ print colored [$colors{'process'}], @_;
+ return;
+ }
+ }
+
+ print @_; # fallback to normal print
}
# information message
sub infomsg {
- print STDERR @_;
+ printColored('info', @_);
}
# warning message
sub warnmsg {
- print STDERR "Warning: ", @_;
+ printColored('warning', "Warning: ", @_);
}
# error message
sub errmsg {
- print STDERR "ERROR: ", @_;
+ printColored('error', "ERROR: ", @_);
}
# fatal message
sub fatalmsg {
- print STDERR "FATAL: ", @_;
+ printColored('fatal', "FATAL: ", @_);
}
# debug message
sub dbgmsg {
my $level = shift;
if ($verbose >= $level) {
- print STDERR "DEBUG[$level]: ", @_;
+ printColored('debug', "DEBUG[$level]: ", @_);
}
}
@@ -245,6 +289,7 @@ sub boolConverter {
sub getOptions {
my $showVersion = 0; # need version
my $showHelp = 0; # need help
+ my @tmpColors;
my @tmpTags;
my $getOptions = GetOptions (
"aggr-delta=i" => \$aggrDelta,
@@ -254,6 +299,7 @@ sub getOptions {
"aggr-virtual!" => \$aggrVirtual,
"aggr-virtual-directory=s" => \$aggrVirtDir,
"backup!" => \$backup,
+ "color=s" => \@tmpColors,
"comment-file=s" => \$comfile,
"config-file|c=s" => \$configFile,
"counter-fixed-field!" => \$countFF,
@@ -277,6 +323,7 @@ sub getOptions {
"rotate-thumb=i" => \$rotateThumbnail,
"tag|t=s" => \@tmpTags,
"trim!" => \$trim,
+ "use-color!" => \$useColor,
"use-ipc!" => \$useIPC,
"user-comment=s" => \$userComment,
"v+" => \$verbose,
@@ -293,6 +340,7 @@ sub getOptions {
dbgmsg (3, " --aggr-virtual: ", boolConv($aggrVirtual), "\n") if (defined $aggrVirtual);
dbgmsg (3, " --aggr-virtual-directory: $aggrVirtDir\n") if (defined $aggrVirtDir);
dbgmsg (3, " --backup: ", boolConv($backup), "\n");
+ dbgmsg (3, " --color:\n", join("\n", @tmpColors), "\n") if (scalar(@tmpColors) > 0);
dbgmsg (3, " --comment-file: $comfile\n") if (defined $comfile);
dbgmsg (3, " --config-file: $configFile\n") if (defined $configFile);
dbgmsg (3, " --counter-start: $countStart",
@@ -314,6 +362,7 @@ sub getOptions {
dbgmsg (3, " --rotate-thumb: $rotateThumbnail\n") if (defined $rotateThumbnail);
dbgmsg (3, " --tag:\n", join("\n", @tmpTags), "\n") if (scalar(@tmpTags) > 0);
dbgmsg (3, " --trim: ", boolConv($trim), "\n") if (defined $trim);
+ dbgmsg (3, " --use-color: ", boolConv($useColor), "\n") if (defined $useColor);
dbgmsg (3, " --use-ipc: ", boolConv($useIPC), "\n") if (defined $useIPC);
dbgmsg (3, " --work-directory: $workDir\n");
dbgmsg (3, " ARGV:\n", join("\n", @ARGV), "\n") if ($fileCount > 0);
@@ -346,6 +395,14 @@ sub getOptions {
$extToProcess =~ s/^\*?\.?/\./ if ($fileCount == 0);
dbgmsg (1, "getOptions(): Process with '$extToProcess' extension.\n");
+ # Convert multiple color parameters to colors hash
+ foreach my $colorStr (@tmpColors) {
+ my %color = colorParser($colorStr);
+ foreach my $key (keys %color) {
+ $colorsFromCli{$key} = $color{$key};
+ }
+ }
+
# Convert multiple tag parameters to tags hash
foreach my $tagStr (@tmpTags) {
my %tag = tagParser($tagStr);
@@ -408,6 +465,26 @@ sub tagParser {
########################################################################################
#
+# colorParser() parses given string to a color hash
+#
+sub colorParser {
+ my $colorStr = shift;
+ my %color;
+ $colorStr =~ s/:/=/; # change first ':' to '='
+ my ($key, $value) = parsePair($colorStr);
+ if (defined $key) {
+ $color{$key} = $value;
+ # Print debug message
+ $value = 'reset' if (not defined $value);
+ dbgmsg (4, "colorParser(): Parsed: $key = '$value'\n");
+ } else {
+ warnmsg ("Invalid color format: $colorStr\n");
+ }
+ return %color;
+}
+
+########################################################################################
+#
# getConfig() parses configuration file
#
sub getConfig {
@@ -531,6 +608,28 @@ sub dirValidator {
########################################################################################
#
+# switchColor() switches to user defined color scheme
+#
+sub switchColor {
+ dbgmsg (1, "Switch to user defined color scheme.\n");
+
+ # Parse configuration file color set
+ foreach my $cKey (keys %configOptions) {
+ next if ($cKey !~ m/^color#\d+#\d+$/); # skip not a color
+ my %color = colorParser($configOptions{$cKey});
+ foreach my $key (keys %color) {
+ $colors{$key} = $color{$key};
+ }
+ }
+
+ # Merge colors from configuration file with command line arguments
+ foreach my $key (keys %colorsFromCli) {
+ $colors{$key} = $colorsFromCli{$key};
+ }
+}
+
+########################################################################################
+#
# MAIN() renames and rotates given files
#
@@ -539,6 +638,8 @@ getOptions();
parseConfig($configFile);
+switchColor();
+
# redefining options set in configuration file with set via CLI ones
$configOptions{'aggregation delta'} = $aggrDelta if (defined $aggrDelta);
$configOptions{'aggregation directory'} = $aggrDir if (defined $aggrDir);
@@ -1323,11 +1424,15 @@ Tag writing options:
-t, --tag <TAG> ... existent EXIF tag to set in renamed files
--no-tags no tags writing, default is to write tags
+Colorizing options:
+ --use-color (*) colorized output
+ --color <COLOR> ... setup color(s)
+
Misc options:
--dry-run show what would have been happened
--use-ipc (*) thumbnail rotation via pipe, rather than via file
-v number of these options defines debug level
- -?, --help display this help and exit
+ -h, --help display this help and exit
--version output version and exit
(*) The option does not take an argument and may be negated, i.e. prefixed by 'no'. E.g. 'mtime' will allow '--mtime' (positive value will be assigned) and '--nomtime' or '--no-mtime' (negative value will be assigned).
@@ -1697,6 +1802,14 @@ look L</TAGS> section for the detailed description
no tags will be written. Default is to write tags.
+=item B<--use-color>, B<--no-use-color>
+
+colorized output. This NOT works under Win32.
+
+=item B<--color> I<COLOR>
+
+setup color for choosen facility
+
=item B<--dry-run>
show what would have been happened (no real actions)
diff --git a/renrot.spec b/renrot.spec
index 21bd704..15fd04e 100644
--- a/renrot.spec
+++ b/renrot.spec
@@ -41,6 +41,7 @@ chmod 755 $RPM_BUILD_ROOT%{_bindir}/renrot
# install sample confuration files
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}
+install -m644 etc/colors.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}
install -m644 etc/copyright.tag $RPM_BUILD_ROOT%{_sysconfdir}/%{name}
install -m644 etc/renrot.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}
install -m644 etc/tags.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}
@@ -65,11 +66,15 @@ fi
%{_bindir}/renrot
%{_mandir}/man1/*.1*
%dir %{_sysconfdir}/%{name}
+%config(noreplace) %{_sysconfdir}/%{name}/colors.conf
%config(noreplace) %{_sysconfdir}/%{name}/copyright.tag
%config(noreplace) %{_sysconfdir}/%{name}/renrot.conf
%config(noreplace) %{_sysconfdir}/%{name}/tags.conf
%changelog
+* Tue Aug 22 2006 Andy Shevchenko <andy@smile.org.ua>
+- add colors.conf
+
* Wed Jun 07 2006 Andy Shevchenko <andriy@asplinux.com.ua>
- relocate configuration to %_sysconfdir/%name

Return to:

Send suggestions and report system problems to the System administrator.