[opencms-dev] manifest.xml generation
Dan Moore
Dan.Moore at xor.com
Tue Apr 30 00:50:38 CEST 2002
Hi folks,
Browsing throught the opencms archive, I came upon this message:
http://www.opencms.org/majordomo/opencms-dev/0101/msg00050.html
which has a perl script which generates a manifest.xml for modules to
easily import things from the filesystem. Thanks to Jeroen for putting
this together.
Since I like versioning things on the filesystem (I understand CVS, I don't
yet understand how to successfully version things in a database) I really
liked this script. It seemed a bit outdated, so I cleaned it up, made it
work with 4.6.0, parameterized some options, etc.
It's still very much a work in progress, but I've attached it in the
hopes that it will be useful to someone.
The usage is much the same:
manifestgen -m modulename -d dir1,dir2 [-u user] [-g group] [-a access] [-o outfile]
you can specify the directory where your module starts and it tries to
delete that prefix.
For example, if you are in
.../foo/bar
and your module starts in
.../foo/bar/baz/module1
you'd use this command line:
manifestgen -m module1 -d .../foo/bar/baz/module1
Dan
-------------- next part --------------
#!/usr/local/bin/perl
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
require "find.pl";
use Getopt::Long;
my ($user, $group, $access, $modname, $headerfile,$outfile, @dirs);
GetOptions('user=s' => \$user, 'group=s' => \$group,'access=i' =>
\$access,'module=s' => \$modname, 'outfile=s'=>\$outfile, 'dirs=s'
=>\@dirs);
@dirs = split(/,/,join(',', at dirs));
# XXX add in header file reading in, for totally customized headers
# XXX add in project switch
# XXX add author switch
# XXX have dates be correct
&usage unless ($modname && @dirs);
# sane defaults
$user = $user || "Admin";
$group= $group || "Administrators";
$access=$access || 383;
$outfile=$outfile || "STDOUT";
$valueweirdness = "${modname}_1";
open (OUT, ">$outfile") or die "could not open $outfile: $!";
print OUT <<"ENDOFXML";
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<!-- Creator: $0 @dirs -->
<!-- Createdate: $^T -->
<export>
<info>
<creator>$user</creator>
<opencms_version>4.6.0 Tleilax</opencms_version>
<createdate>25.04.2002 08:17</createdate>
<project>online</project>
<export_version>1</export_version>
</info>
<module>
<name>$modname</name>
<nicename>Test module</nicename>
<version>1</version>
<description>
test
</description>
<author>Dan</author>
<email>dan.moore\@seurat.com</email>
<creationdate>11.12.2002</creationdate>
<view/>
<documentation>/system/modules/$modname/doc/index.html</documentation>
<dependencies/>
<parameters/>
<repository/>
</module>
<files>
ENDOFXML
# Traverse desired filesystems
while ($dirname = shift @dirs) {
&find($dirname);
}
print OUT "\t</files>\n";
print OUT "</export>\n";
exit;
sub properties {
my $type = shift;
my $properties = "\t\t\t<properties>
\t\t\t\t<property>
\t\t\t\t\t<name>module</name>
\t\t\t\t\t<type>$type</type>
\t\t\t\t\t<value><![CDATA[$valueweirdness]]></value>
\t\t\t\t</property>
\t\t\t</properties>\n";
return $properties;
}
sub wanted {
if ( $name ne "." ) {
$name =~ s/$dirname//;
$tempdir = $dirname;
$tempdir =~ s!/$!!;
if ($name eq $tempdir) {return;}
$name =~ s/^\.//;
$name =~ s/^\///g;
next unless ($name);
if (-d $_ ) {
$typenum=0;
print OUT "\t\t<file>\n";
print OUT "\t\t\t<destination>$name</destination>\n";
print OUT "\t\t\t<type>folder</type>\n";
print OUT "\t\t\t<user>$user</user>\n";
print OUT "\t\t\t<group>$group</group>\n";
print OUT "\t\t\t<access>$access</access>\n";
print OUT &properties($typenum);
print OUT "\t\t</file>\n";
} elsif (-f $_ ) {
$typenum=0;
$filetype = `file $_`;
if ($filetype =~ /XML/) {
$type="XMLTemplate";
$typenum =4;
} elsif ($filetype =~ /Java class/) {
$type="binary";
$typenum =5;
} elsif (/\.(gif|jpg|png)$/i) {
$type="image";
$typenum =6;
} else {
$type="plain";
$typenum = 3;
}
print OUT "\t\t<file>\n";
print OUT "\t\t\t<source>$name</source>\n";
print OUT "\t\t\t<destination>$name</destination>\n";
print OUT "\t\t\t<type>$type</type>\n";
print OUT "\t\t\t<user>$user</user>\n";
print OUT "\t\t\t<group>$group</group>\n";
print OUT "\t\t\t<access>$access</access>\n";
print OUT &properties($typenum);
print OUT "\t\t</file>\n";
}
}
}
sub usage{
print STDERR <<"EOF";
Usage: $0 -m modulename -d dir1,dir2 [-u user] [-g group] [-a access] [-o outfile]
EOF
exit(1);
}
More information about the opencms-dev
mailing list