init III
This commit is contained in:
148
Perl OTRS/Kernel/System/Console/Command/Dev/Package/Build.pm
Normal file
148
Perl OTRS/Kernel/System/Console/Command/Dev/Package/Build.pm
Normal file
@@ -0,0 +1,148 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Console::Command::Dev::Package::Build;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Create an OTRS package (opm) file from an OTRS package source (sopm) file.');
|
||||
$Self->AddOption(
|
||||
Name => 'version',
|
||||
Description => "Specify the version to be used (overrides version from sopm file).",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/^\d{1,4}[.]\d{1,4}[.]\d{1,4}$/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'module-directory',
|
||||
Description =>
|
||||
"Specify the directory containing the module sources (otherwise the OTRS home directory will be used).",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'source-path',
|
||||
Description => "Specify the path to an OTRS package source (sopm) file that should be built.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'target-directory',
|
||||
Description => "Specify the directory where the generated package should be placed.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SourcePath = $Self->GetArgument('source-path');
|
||||
if ( !-r $SourcePath ) {
|
||||
die "File $SourcePath does not exist / cannot be read.\n";
|
||||
}
|
||||
|
||||
my $TargetDirectory = $Self->GetArgument('target-directory');
|
||||
if ( !-d $TargetDirectory ) {
|
||||
die "Directory $TargetDirectory does not exist.\n";
|
||||
}
|
||||
|
||||
my $ModuleDirectory = $Self->GetOption('module-directory');
|
||||
if ( $ModuleDirectory && !-d $ModuleDirectory ) {
|
||||
die "Directory $ModuleDirectory does not exist.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Building package...</yellow>\n");
|
||||
|
||||
my $FileString;
|
||||
my $SourcePath = $Self->GetArgument('source-path');
|
||||
my $ContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $SourcePath,
|
||||
Mode => 'utf8', # optional - binmode|utf8
|
||||
Result => 'SCALAR', # optional - SCALAR|ARRAY
|
||||
);
|
||||
if ( !$ContentRef || ref $ContentRef ne 'SCALAR' ) {
|
||||
$Self->PrintError("File $SourcePath is empty / could not be read.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
$FileString = ${$ContentRef};
|
||||
|
||||
my %Structure = $Kernel::OM->Get('Kernel::System::Package')->PackageParse(
|
||||
String => $FileString,
|
||||
);
|
||||
|
||||
# just build it if PackageIsDownloadable flag is enable
|
||||
if (
|
||||
defined $Structure{PackageIsDownloadable}
|
||||
&& !$Structure{PackageIsDownloadable}->{Content}
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Package cannot be built.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
if ( $Self->GetOption('version') ) {
|
||||
$Structure{Version}->{Content} = $Self->GetOption('version');
|
||||
}
|
||||
|
||||
# build from given package directory, if any (otherwise default to OTRS home)
|
||||
if ( $Self->GetOption('module-directory') ) {
|
||||
$Structure{Home} = $Self->GetOption('module-directory');
|
||||
}
|
||||
|
||||
my $Filename = $Structure{Name}->{Content} . '-' . $Structure{Version}->{Content} . '.opm';
|
||||
my $Content = $Kernel::OM->Get('Kernel::System::Package')->PackageBuild(%Structure);
|
||||
if ( !$Content ) {
|
||||
$Self->PrintError("Package build failed.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
my $File = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
|
||||
Location => $Self->GetArgument('target-directory') . '/' . $Filename,
|
||||
Content => \$Content,
|
||||
Mode => 'utf8', # binmode|utf8
|
||||
Type => 'Local', # optional - Local|Attachment|MD5
|
||||
Permission => '644', # unix file permissions
|
||||
);
|
||||
if ( !$File ) {
|
||||
$Self->PrintError("File $File could not be written.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
# sub PostRun {
|
||||
# my ( $Self, %Param ) = @_;
|
||||
#
|
||||
# # This will be called after Run() (even in case of exceptions). Perform any cleanups here.
|
||||
#
|
||||
# return;
|
||||
# }
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,88 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Console::Command::Dev::Package::RepositoryIndex;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::Package',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Generate an index file (otrs.xml) for an OTRS package repository.');
|
||||
$Self->AddArgument(
|
||||
Name => 'source-directory',
|
||||
Description => "Specify the directory containing the OTRS packages.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub PreRun {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $SourceDirectory = $Self->GetArgument('source-directory');
|
||||
if ( $SourceDirectory && !-d $SourceDirectory ) {
|
||||
die "Directory $SourceDirectory does not exist.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $Result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
|
||||
$Result .= "<otrs_package_list version=\"1.0\">\n";
|
||||
my $SourceDirectory = $Self->GetArgument('source-directory');
|
||||
my @List = $Kernel::OM->Get('Kernel::System::Main')->DirectoryRead(
|
||||
Directory => $SourceDirectory,
|
||||
Filter => '*.opm',
|
||||
Recursive => 1,
|
||||
);
|
||||
for my $File (@List) {
|
||||
my $Content = '';
|
||||
my $ContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
|
||||
Location => $File,
|
||||
Mode => 'utf8', # optional - binmode|utf8
|
||||
Result => 'SCALAR', # optional - SCALAR|ARRAY
|
||||
);
|
||||
if ( !$ContentRef ) {
|
||||
$Self->PrintError("Can't open $File: $!\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
my %Structure = $Kernel::OM->Get('Kernel::System::Package')->PackageParse( String => ${$ContentRef} );
|
||||
my $XML = $Kernel::OM->Get('Kernel::System::Package')->PackageBuild( %Structure, Type => 'Index' );
|
||||
if ( !$XML ) {
|
||||
$Self->PrintError("Cannot generate index entry for $File.\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
$Result .= "<Package>\n";
|
||||
$Result .= $XML;
|
||||
my $RelativeFile = $File;
|
||||
$RelativeFile =~ s{^\Q$SourceDirectory\E}{}smx;
|
||||
$RelativeFile =~ s{^/}{}smx;
|
||||
$Result .= " <File>$RelativeFile</File>\n";
|
||||
$Result .= "</Package>\n";
|
||||
}
|
||||
$Result .= "</otrs_package_list>\n";
|
||||
$Self->Print($Result);
|
||||
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user