aboutsummaryrefslogtreecommitdiffstats
path: root/mkpeople
diff options
context:
space:
mode:
authorNicolas Vigier <boklm@mageia.org>2013-04-12 13:54:48 +0000
committerNicolas Vigier <boklm@mageia.org>2013-04-12 13:54:48 +0000
commit48c18b7e133b126c77bc6fb8c2880cb8ff7e0925 (patch)
tree106a8bccb6b06835c91a54f232da3a9838d9af07 /mkpeople
parent08efbb990d14e4cc8e59ede5e361024e44cdc964 (diff)
downloadmgapeople-48c18b7e133b126c77bc6fb8c2880cb8ff7e0925.tar
mgapeople-48c18b7e133b126c77bc6fb8c2880cb8ff7e0925.tar.gz
mgapeople-48c18b7e133b126c77bc6fb8c2880cb8ff7e0925.tar.bz2
mgapeople-48c18b7e133b126c77bc6fb8c2880cb8ff7e0925.tar.xz
mgapeople-48c18b7e133b126c77bc6fb8c2880cb8ff7e0925.zip
Add support for multiple output formats
Diffstat (limited to 'mkpeople')
-rwxr-xr-xmkpeople27
1 files changed, 16 insertions, 11 deletions
diff --git a/mkpeople b/mkpeople
index 1cc4c7f..d7021e3 100755
--- a/mkpeople
+++ b/mkpeople
@@ -14,6 +14,14 @@ my %maintdb;
my %groups;
my %users;
+sub process_template {
+ my ($template, $src, $vars, $dest) = @_;
+ for my $extension (@{$config->{output_format}}) {
+ next unless -f "$config->{tmpl_dir}/$src.$extension";
+ $template->process("$src.$extension", $vars, "$dest.$extension");
+ }
+}
+
sub loadmaintdb {
return unless $config->{maintdburl};
my $ua = LWP::UserAgent->new;
@@ -62,7 +70,6 @@ sub loadgroups {
}
sub output_users {
- my ($extension) = @_;
my $template = Template->new({
INCLUDE_PATH => $config->{tmpl_dir},
OUTPUT_PATH => "$config->{output_dir}/u",
@@ -76,7 +83,7 @@ sub output_users {
maintdb => \%maintdb,
};
my $uid = $users{$user}->{uid}->[0];
- $template->process("user.$extension", $vars, "$uid.$extension");
+ process_template($template, 'user', $vars, $uid);
}
my $vars = {
@@ -85,11 +92,10 @@ sub output_users {
groups => \%groups,
maintdb => \%maintdb,
};
- $template->process("userindex.$extension", $vars, "index.$extension");
+ process_template($template, 'userindex', $vars, 'index');
}
sub output_groups {
- my ($extension) = @_;
my $template = Template->new({
INCLUDE_PATH => $config->{tmpl_dir},
OUTPUT_PATH => "$config->{output_dir}/g",
@@ -103,7 +109,7 @@ sub output_groups {
maintdb => \%maintdb,
};
my $cn = $groups{$group}->{cn}->[0];
- $template->process("group.$extension", $vars, "$cn.$extension");
+ process_template($template, 'group', $vars, $cn);
}
my $vars = {
@@ -112,11 +118,10 @@ sub output_groups {
groups => \%groups,
maintdb => \%maintdb,
};
- $template->process("groupindex.$extension", $vars, "index.$extension");
+ process_template($template, 'groupindex', $vars, 'index');
}
sub output_index {
- my ($extension) = @_;
my $template = Template->new({
INCLUDE_PATH => $config->{tmpl_dir},
OUTPUT_PATH => "$config->{output_dir}",
@@ -127,7 +132,7 @@ sub output_index {
groups => \%groups,
maintdb => \%maintdb,
};
- $template->process("index.$extension", $vars, "index.$extension");
+ process_template($template, 'index', $vars, 'index');
}
my $bindpw = read_file($config->{bindpwfile});
@@ -140,6 +145,6 @@ $m = $ldap->bind($config->{binddn}, password => $bindpw);
die $m->error if $m->is_error;
loadmaintdb;
loadgroups($ldap);
-output_users('html');
-output_groups('html');
-output_index('html');
+output_users();
+output_groups();
+output_index();