
Hi everybody
this is a small script taht may be useful for everybody who develops
add-ons for OTRS (aka. OPM packages). This script checks the "manifest"
(file list) in the .sopm file.
It gets the filelist from the XML and gets a list of files in the
subdirectories of the OPM package. Then it checks if all the files
mentioned in the manifest can be found on disk and if all files that
were found on disk were listed in the sopm file.
This is a sample output if anything goes wrong:
C:\>check_manifest.pl path\to\your.sopm
1..1
not ok 1
# Failed test at C:\check_manifest.pl line 66.
# Structures begin differing at:
# $got->{Kernel/System/AnyFile.pm} = Does not exist
# $expected->{Kernel/System/AnyFile.pm} = '1'
# Looks like you failed 1 test of 1.
And when you have added AnyFile.pm everything is ok:
C:\>check_manifest.pl path\to\your.sopm
1..1
ok 1
Everything that "does not exist" in the "$got" hashref must be added in
the .sopm file and any files that does not exist in the "$expected"
hashref are files that are mentioned in the manifest and no according
file could be found.
This test can be helpful before you create the OPM package to check if
your manifest is up to date.
I hope this is helpful to anybody out there.
Cheers,
Renee
--
Perl-Magazin: http://perl-magazin.de
Perl-Nachrichten: http://perl-nachrichten.de
#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple ();
use File::Spec;
use File::Basename ();
use File::Find::Rule;
use Test::More tests => 1;
my $path = $ARGV[0];
print_usage() unless $path and -e $path and substr( $path, -5 ) eq '.sopm';
my @listed_files = get_listed_files( $path );
my @real_files = get_real_files( $path );
check_filelist( \@listed_files, \@real_files );
sub print_usage {
plan tests => 0;
print <<"USAGE";
Usage: $0

This is another helper script.
Sometimes you define tables that should be created on OPM package
installation. And it happens during development that you have already
installed a version of your OPM package but another table should be
created. Then you may not deinstall the package just to get the new
table created as you will lose all data of your package on deinstallation.
There exists a script called xml2sql.pl in OTRS_HOME/bin, but that
creates all SQL statements even those that were written for
deinstallation process.
My script extracts only the DatabaseInstall part and you can specify a
single table. And it calls xml2sql to generate the SQL statements for
that specific part.
Example:
<DatabaseInstall Type="post">
<TableCreate Name="table1">
<!-- Column Definition -->
</TableCreate>
<TableCreate Name="table2">
<!-- Column Definition -->
</TableCreate>
</DatabaseInstall>
<DatabaseUninstall Type="pre">
<TableDrop Name="table1"/>
<TableDrop Name="table2"/>
</DatabaseUninstall>
C:\>sopm2xml.pl -file .\yourfile.sopm -table table2 -sql
# ----------------------------------------------------------
# driver: mysql, generated: 2009-03-20 09:46:07
# ----------------------------------------------------------
# ----------------------------------------------------------
# create table table2
# ----------------------------------------------------------
CREATE TABLE table2 (
id BIGINT NOT NULL AUTO_INCREMENT,
name BIGINT NOT NULL,
test VARCHAR (255) NOT NULL,
PRIMARY KEY(id)
);
With -t option you can specify the db type (like the -t option for
xml2sql.pl).
You have to configure the path to xml2sql.pl in the script.
Cheers,
Renée
--
Perl-Magazin: http://perl-magazin.de
Perl-Nachrichten: http://perl-nachrichten.de
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use File::Basename;
use File::Spec;
use File::Temp qw(tempfile);
GetOptions(
'file=s' => \my $file,
'out=s' => \my $outputdir,
'table=s' => \my $table,
'type=s' => \my $type,
'sql' => \my $sql_required,
);
die 'specify .sopm file with -file option' unless $file;
my $filename = basename( $file, '.sopm' );
my $part = "";
my $xml2sql = 'D:\OTRS\bin\xml2sql.pl';
open my $fh, '<', $file or die $!;
while( my $line = <$fh> ){
if( $line =~ /
participants (1)
-
Renee Bäcker