pf-tools/pf-tools: 3 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Dec 10 12:11:12 UTC 2014
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/cadcaa2e6e96
changeset: 1368:cadcaa2e6e96
user: shad
date: Wed Dec 10 11:38:45 2014 +0100
description:
translate new path
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/377e7f526110
changeset: 1369:377e7f526110
user: shad
date: Wed Dec 10 13:00:05 2014 +0100
description:
shortcut doc
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/8be01e585a19
changeset: 1370:8be01e585a19
user: shad
date: Wed Dec 10 13:11:04 2014 +0100
description:
merge Melkor's change + swap HOSTNAME and HOST in AUTO order
diffstat:
doc/updatefile-syntax | 42 ++++++++-----
lib/PFTools/Compat/Translation.pm | 14 ++++-
lib/PFTools/Update/ADDFILE.pm | 117 +++++++++++++++++++++++--------------
tools/Translate_old_config | 10 +-
4 files changed, 116 insertions(+), 67 deletions(-)
diffs (259 lines):
diff -r ef99d1555fe7 -r 8be01e585a19 doc/updatefile-syntax
--- a/doc/updatefile-syntax Wed Dec 10 08:48:19 2014 +0100
+++ b/doc/updatefile-syntax Wed Dec 10 13:11:04 2014 +0100
@@ -177,19 +177,29 @@
! action ::= include
there are some shortcut defined that resolve to path relatively to VCS root
and 'module' defined in pf-tool.conf file
- - CONFIG: resolve to /module/CONFIG/
- - CONFIGSITE: resolve to /module/SITE/pop/CONFIG/ (if the hosttype of machine is pop-bar)
- - CONFIGSITE_foo: resolve to /module/SITE/foo/CONFIG/
- - COMMON: resolve to /module/COMMON/
- - HOST: resolve to /module/CONFIG/bar/ (if the hosttype of machine is pop-bar)
- - HOSTSITE: resolve to /module/SITE/pop/CONFIG/pop-bar/ (if the hosttype of machine is pop-bar)
- - HOSTSITE_foo: resolve to /module/SITE/foo/CONFIG/pop-bar/ (if the hosttype of machine is pop-bar)
- - MODEL: resolve to /module/MODEL/
- - MODELSITE: resolve to /module/SITE/pop/MODEL/ (if the hosttype of machine is pop-bar)
- - MODELSITE_foo: resolve to /module/SITE/foo/MODEL/
- - SITE: resolve to /module/SITE/
- - SITE_foo: resolve to /module/SITE/foo/
- - SHORTHOST: resolve to /module/CONFIG/bar/ (if the hosttype of machine is pop-bar)
- - SHORTHOSTHOSTSITE: resolve to /module/SITE/pop/CONFIG/bar (if the hosttype of machine is pop-bar)
- - SHORTHOSTHOSTSITE_foo: resolve to /module/SITE/SITE/foo/CONFIG/bar (if the hosttype of machine is pop-bar)
- - ROOT: resolve to /module/
+ - AUTO: try to resolve in order to:
+ - CONFIG: resolve to /module/CONFIG/
+ - CONFIGSITE: resolve to /module/SITE/pop/CONFIG/ (if the hosttype of machine is pop-bar)
+ - CONFIGSITE_foo: resolve to /module/SITE/foo/CONFIG/
+ - COMMON: resolve to /module/COMMON/
+ - FILE: resolve to /module/FILE/
+ - FILESITE: resolve to /module/SITE/pop/FILE/ (if the hosttype of machine is pop-bar)
+ - FILESITE_foo: resolve to /module/SITE/foo/FILE/
+ - HOST: resolve to /module/CONFIG/pop-bar/ (if the hosttype of machine is pop-bar)
+ - HOSTSITE: resolve to /module/SITE/pop/CONFIG/pop-bar/ (if the hosttype of machine is pop-bar)
+ - HOSTSITE_foo: resolve to /module/SITE/foo/CONFIG/pop-bar/ (if the hosttype of machine is pop-bar)
+ - HOSTNAME: resolve to /module/CONFIG/pop-bar00/ (if the hostname of machine is pop-bar00)
+ - HOSTNAMESITE: resolve to /module/SITE/pop/CONFIG/pop-bar00/ (if the hostname of machine is pop-bar00)
+ - HOSTNAMESITE_foo: resolve to /module/SITE/foo/CONFIG/pop-bar00/ (if the hostname of machine is pop-bar00)
+ - MODEL: resolve to /module/MODEL/
+ - MODELSITE: resolve to /module/SITE/pop/MODEL/ (if the hosttype of machine is pop-bar)
+ - MODELSITE_foo: resolve to /module/SITE/foo/MODEL/
+ - SITE: resolve to /module/SITE/
+ - SITE_foo: resolve to /module/SITE/foo/
+ - SHORTHOST: resolve to /module/CONFIG/bar/ (if the hosttype of machine is pop-bar)
+ - SHORTHOSTSITE: resolve to /module/SITE/pop/CONFIG/bar/ (if the hosttype of machine is pop-bar)
+ - SHORTHOSTSITE_foo: resolve to /module/SITE/SITE/foo/CONFIG/bar/ (if the hosttype of machine is pop-bar)
+ - SHORTHOSTNAME: resolve to /module/CONFIG/bar00/ (if the hostname of machine is pop-bar00)
+ - SHORTHOSTNAMESITE: resolve to /module/SITE/pop/CONFIG/bar00/ (if the hostname of machine is pop-bar00)
+ - SHORTHOSTNAMESITE_foo: resolve to /module/SITE/SITE/foo/CONFIG/bar00/ (if the hostname of machine is pop-bar00)
+ - ROOT: resolve to /module/
diff -r ef99d1555fe7 -r 8be01e585a19 lib/PFTools/Compat/Translation.pm
--- a/lib/PFTools/Compat/Translation.pm Wed Dec 10 08:48:19 2014 +0100
+++ b/lib/PFTools/Compat/Translation.pm Wed Dec 10 13:11:04 2014 +0100
@@ -41,7 +41,7 @@
my $new_conf = $conf_parsed;
foreach my $section ( keys %{$new_conf} ) {
if ( $section =~ /^@(.*)$/ ) {
- $new_conf->{qq{COMMON:/$1}} = { 'action' => 'include' };
+ $new_conf->{qq{COMMON:$1}} = { 'action' => 'include' };
delete $new_conf->{$section};
next;
}
@@ -110,6 +110,18 @@
$new_conf->{$section}->{$key}
=~ s/fix_hosts -d (\S+) --host (\S+)/fix_hosts -h $2 -o $1/;
}
+ elsif ( $new_conf->{$section}->{$key} =~ /GLOBAL:/ ) {
+ $new_conf->{$section}->{$key}
+ =~ s/GLOBAL:/COMMON:/;
+ }
+ elsif ( $new_conf->{$section}->{$key} =~ /CONFIG:GLOBAL/ ) {
+ $new_conf->{$section}->{$key}
+ =~ s/CONFIG:GLOBAL/COMMON:/;
+ }
+ elsif ( $new_conf->{$section}->{$key} =~ /CONFIG:/ ) {
+ $new_conf->{$section}->{$key}
+ =~ s/CONFIG:/FILE:/;
+ }
}
}
return $new_conf;
diff -r ef99d1555fe7 -r 8be01e585a19 lib/PFTools/Update/ADDFILE.pm
--- a/lib/PFTools/Update/ADDFILE.pm Wed Dec 10 08:48:19 2014 +0100
+++ b/lib/PFTools/Update/ADDFILE.pm Wed Dec 10 13:11:04 2014 +0100
@@ -53,6 +53,45 @@
return;
}
+sub __find_source {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ # search in order into:
+ # /SITE/pro1/FILE/pro1-ncdn-cache00/
+ # /SITE/pro1/FILE/pro1-ncdn-cache/
+ # /FILE/pro1-ncdn-cache00/
+ # /FILE/pro1-ncdn-cache/
+ # /SITE/pro1/FILE/ncdn-cache00/
+ # /SITE/pro1/FILE/ncdn-cache/
+ # /FILE/ncdn-cache00/
+ # /FILE/ncdn-cache/
+ # /FILE/common/
+
+ my @search_dirs = (
+ 'HOSTNAMESITE', 'HOSTSITE', 'HOSTNAME', 'HOST',
+ 'SHORTHOSTSITE', 'SHORTHOST', 'FILE:common/'
+ );
+
+ my $source;
+SEARCH_DIR:
+ foreach my $search_dir (@search_dirs) {
+ my @search_files = (
+ qq{$search_dir:%SECTIONNAME%.%HOSTDIGITS%},
+ qq{$search_dir:%SECTIONNAME%},
+ );
+ foreach my $search_file (@search_files) {
+ $source
+ = get_source( $search_file, $options->{'host'}, $hash_subst );
+ if ( -e $source ) {
+ $ref_section->{source} = $search_file;
+ last SEARCH_DIR;
+ }
+ }
+ }
+
+ return $source;
+}
+
sub action_exec {
my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
my ( $source, $tmp );
@@ -61,61 +100,49 @@
$hash_subst->{'SECTIONNAME'} = $dest;
$tmp = get_tmp_dest($dest);
- # Removing trailing space from source
if ( !$ref_section->{'source'} ) {
-
- # search in order into:
- # /SITE/pro1/FILE/pro1-ncdn-cache00/
- # /SITE/pro1/FILE/pro1-ncdn-cache/
- # /FILE/pro1-ncdn-cache00/
- # /FILE/pro1-ncdn-cache/
- # /SITE/pro1/FILE/ncdn-cache00/
- # /SITE/pro1/FILE/ncdn-cache/
- # /FILE/ncdn-cache00/
- # /FILE/ncdn-cache/
- my @search_dirs = (
- 'HOSTNAMESITE', 'HOSTSITE', 'HOST',
- 'HOSTNAME', 'SHORTHOSTSITE', 'SHORTHOST',
- );
- SEARCH_DIR:
- foreach my $search_dir (@search_dirs) {
- my @search_files = (
- qq{$search_dir:%SECTIONNAME%.%HOSTDIGITS%},
- qq{$search_dir:%SECTIONNAME%},
- );
- foreach my $search_file (@search_files) {
- $source = get_source( $search_file,
- $options->{'host'}, $hash_subst );
- if ( -e $source ) {
- $ref_section->{source} = $search_file;
- last SEARCH_DIR;
- }
- }
- }
+ $source = __find_source( $ref_section, $options, $hash_subst );
}
else {
+ # Removing trailing space from source
$ref_section->{'source'} =~ s{\A\s*}{}xms;
$ref_section->{'source'} =~ s{\s*\z}{}xms;
+
if ( $ref_section->{'source'} =~ m{\s}xms ) {
$source = get_tmp_dest($dest) . q{.merged};
unlink $source;
+
+ SPLITSOURCE:
foreach my $splitsource ( split q{ }, $ref_section->{'source'} ) {
- $splitsource
- = get_source( $splitsource, $options->{'host'},
- $hash_subst );
- if ( !-f $splitsource ) {
- carp colored(
- qq{ERROR: $splitsource no such file or directory},
- q{bold red on_white} );
- return;
+
+ if ( $splitsource =~ m{\AAUTO:(.*)\z}xms ) {
+ $splitsource = __find_source( $1, $options, $hash_subst );
+
+ if ( !-f $splitsource ) {
+ next SPLITSOURCE;
+ }
+
}
- if (deferredlogsystem(
- q{cat '} . $splitsource . q{' >> } . $source
- )
- )
- {
- carp qq{ERROR: Unable to append $splitsource to $source};
- return;
+ else {
+ $splitsource
+ = get_source( $splitsource, $options->{'host'},
+ $hash_subst );
+ if ( !-f $splitsource ) {
+ carp colored(
+ qq{ERROR: $splitsource no such file or directory},
+ q{bold red on_white}
+ );
+ return;
+ }
+ if (deferredlogsystem(
+ q{cat '} . $splitsource . q{' >> } . $source
+ )
+ )
+ {
+ carp
+ qq{ERROR: Unable to append $splitsource to $source};
+ return;
+ }
}
}
}
diff -r ef99d1555fe7 -r 8be01e585a19 tools/Translate_old_config
--- a/tools/Translate_old_config Wed Dec 10 08:48:19 2014 +0100
+++ b/tools/Translate_old_config Wed Dec 10 13:11:04 2014 +0100
@@ -123,15 +123,15 @@
}
elsif ( $_ =~ m{\A \@include \s* (.*) \z}msx ) {
if ( $options->{'type'} eq 'config' ) {
- $current_section = qq{COMMON:/include-$1};
+ $current_section = qq{COMMON:include-$1};
}
else {
if ( $options->{'site'} eq q{UNDEFINED} ) {
- $current_section = qq{COMMON:/include-$1};
+ $current_section = qq{COMMON:include-$1};
}
else {
$current_section
- = qq{CONFIGSITE_$options->{'site'}:/include-$1};
+ = qq{CONFIGSITE_$options->{'site'}:include-$1};
}
}
push @included_list, qq{include-$1};
@@ -174,10 +174,10 @@
if ( $section =~ m{\A @ (.*) \z}msx ) {
my $current_section;
if ( $options->{'site'} eq q{UNDEFINED} ) {
- $current_section = qq{COMMON:/$1};
+ $current_section = qq{COMMON:$1};
}
else {
- $current_section = qq{CONFIGSITE_$options->{'site'}:/$1};
+ $current_section = qq{CONFIGSITE_$options->{'site'}:$1};
}
$trans->{$current_section} = { 'type' => 'include' };
More information about the pf-tools-commits
mailing list