[Slim-Checkins] r11012 - in /trunk/tools/PluginBuilder: ./ MANIFEST
Makefile.PL README bin/ bin/create-slimserver-plugin
dsully at svn.slimdevices.com
dsully at svn.slimdevices.com
Wed Dec 20 13:23:40 PST 2006
Author: dsully
Date: Wed Dec 20 13:23:40 2006
New Revision: 11012
URL: http://svn.slimdevices.com?rev=11012&view=rev
Log:
Bug: N/A
Description: Initial version of the plugin packager / builder.
Added:
trunk/tools/PluginBuilder/
trunk/tools/PluginBuilder/MANIFEST
trunk/tools/PluginBuilder/Makefile.PL
trunk/tools/PluginBuilder/README
trunk/tools/PluginBuilder/bin/
trunk/tools/PluginBuilder/bin/create-slimserver-plugin (with props)
Added: trunk/tools/PluginBuilder/MANIFEST
URL: http://svn.slimdevices.com/trunk/tools/PluginBuilder/MANIFEST?rev=11012&view=auto
==============================================================================
--- trunk/tools/PluginBuilder/MANIFEST (added)
+++ trunk/tools/PluginBuilder/MANIFEST Wed Dec 20 13:23:40 2006
@@ -1,0 +1,4 @@
+Makefile.PL
+MANIFEST
+README
+bin/create-slimserver-plugin
Added: trunk/tools/PluginBuilder/Makefile.PL
URL: http://svn.slimdevices.com/trunk/tools/PluginBuilder/Makefile.PL?rev=11012&view=auto
==============================================================================
--- trunk/tools/PluginBuilder/Makefile.PL (added)
+++ trunk/tools/PluginBuilder/Makefile.PL Wed Dec 20 13:23:40 2006
@@ -1,0 +1,22 @@
+use inc::Module::Install;
+
+# Define metadata
+name ('Slim-PluginBuilder');
+#all_from ('lib/Slim/PluginBuilder.pm');
+license ('perl');
+version ('1.0');
+
+# Specific dependencies
+requires ('Archive::Zip' => 0);
+requires ('Data::UUID' => 0);
+requires ('Getopt::Long' => 0);
+requires ('PAR' => 0);
+requires ('PAR::Dist' => 0);
+requires ('PAR::Packer' => 0);
+requires ('Module::CoreList' => 0);
+requires ('XML::Simple' => 0);
+
+install_script ('bin/create-slimserver-plugin');
+
+auto_install();
+WriteAll();
Added: trunk/tools/PluginBuilder/README
URL: http://svn.slimdevices.com/trunk/tools/PluginBuilder/README?rev=11012&view=auto
==============================================================================
--- trunk/tools/PluginBuilder/README (added)
+++ trunk/tools/PluginBuilder/README Wed Dec 20 13:23:40 2006
@@ -1,0 +1,52 @@
+
+* SlimServer Plugin Builder
+======================================================================
+
+This tool allows you to build a SlimServer 7.0+ compatible plugin package.
+
+The basic layout of a plugin is as follows:
+
+topdir/
+ install.xml
+ strings.txt
+ lib/
+ lib/Path/To/Modules.pm
+
+All files listed above are mandatory.
+
+Additionally, one may have the following files,
+which are referred to by install.xml:
+
+ bin/
+ HTML/
+ convert.conf
+
+All files in the topdir/ will be bundled into a .zip file, which is then
+installable via the SlimServer Web Interface. A '.par' file will be created
+from the perl modules in your lib/ path, which will pull in the appropriate
+dependencies.
+
+======================================================================
+
+* Please run 'perl Makefile.PL' to install the necessary dependencies.
+
+* If you wish to install these tools system-wide, run 'make install'
+
+Usage: ./bin/create-slimserver-plugin
+
+ --plugindir <dir>
+ This must point to the top level directory where your plugin is.
+
+ --slimserverdir <dir>
+
+ This must point to the top level of your SlimServer directory.
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2006 by Slim Devices, Inc.
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.8.6 or,
+at your option, any later version of Perl 5 you may have available.
+
+
Added: trunk/tools/PluginBuilder/bin/create-slimserver-plugin
URL: http://svn.slimdevices.com/trunk/tools/PluginBuilder/bin/create-slimserver-plugin?rev=11012&view=auto
==============================================================================
--- trunk/tools/PluginBuilder/bin/create-slimserver-plugin (added)
+++ trunk/tools/PluginBuilder/bin/create-slimserver-plugin Wed Dec 20 13:23:40 2006
@@ -1,0 +1,227 @@
+#!/usr/bin/perl
+
+# $Id$
+#
+# Create a packaged slimserver plugin.
+
+use strict;
+use warnings;
+
+use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
+use Data::UUID;
+use Getopt::Long;
+use File::Spec::Functions qw(:ALL);
+use File::Find ();
+use File::Temp qw(tempfile tempdir);
+use Module::CoreList;
+use XML::Simple;
+
+sub main {
+
+ my ($pluginDir, $slimserverDir);
+
+ GetOptions(
+ 'plugindir=s' => \$pluginDir,
+ 'slimserverdir=s' => \$slimserverDir,
+ );
+
+ if (!defined $slimserverDir || !-d $slimserverDir || !-f catdir($slimserverDir, 'strings.txt')) {
+
+ die "$0: Need --slimserverdir!\n";
+ }
+
+ if (!defined $pluginDir || !-d $pluginDir || !-f catdir($pluginDir, 'install.xml')) {
+
+ die "$0: Need --plugindir!\n";
+ }
+
+ my $tempDir = tempdir(CLEANUP => 1);
+ my ($excludeFH, $excludeFile) = tempfile(DIR => $tempDir);
+
+ print "* Starting module packaging process..\n\n";
+ print "- Created temp file [$excludeFile] for module exclude list\n\n";
+
+ generateExcludeList($slimserverDir, $excludeFH);
+
+ close($excludeFH);
+
+ my $metaData = readPluginMetaData($pluginDir);
+
+ generatePARFile($pluginDir, $metaData, $excludeFile);
+
+ my $zipFile = generateZipFile($pluginDir, $metaData);
+
+ if (-f $zipFile) {
+
+ print "* Packaged plugin ok! File: [$zipFile] is ready for posting\n";
+ }
+}
+
+sub generateExcludeList {
+ my $baseDir = shift;
+ my $outFile = shift;
+
+ print "- Generating module exclude list from the SlimServer root directory\n\n";
+
+ my @coreModules = keys %{$Module::CoreList::version{$]}};
+ my @slimModules = ();
+ my @slimDirs = map { catdir($baseDir, $_) } qw(Slim Plugins lib CPAN);
+
+ for my $incDir (@slimDirs) {
+
+ File::Find::find({
+ wanted => sub {
+
+ my $file = $File::Find::name;
+
+ return unless -f $file and $file =~ /\.pm/i;
+
+ $file =~ s/^\Q$incDir\E(?:\\|\/)?//;
+ $file =~ s/(?:\\|\/)/::/g;
+ $file =~ s/\.[^.]+$//;
+
+ push @slimModules, $file;
+ },
+
+ no_chdir => 1,
+
+ }, $incDir);
+ }
+
+ my %modules = (map { $_ => undef } @slimModules, @coreModules);
+
+ for my $key (keys %modules) {
+
+ if ($^O !~ /win32/i && $key =~ /win32/i) {
+
+ delete $modules{$key};
+ }
+ }
+
+ print $outFile map {"-X $_\n"} sort keys %modules;
+}
+
+sub readPluginMetaData {
+ my $baseDir = shift;
+
+ my $installXML = catdir($baseDir, 'install.xml');
+
+ if (!-f $installXML) {
+
+ die "No install.xml file in the plugin root directory!\n";
+ }
+
+ print "- Fetching plugin metadata from $installXML\n\n";
+
+ my $metadata = eval { XMLin($installXML) };
+
+ if ($@) {
+ die "There was an error in your $installXML file: [$@]\n";
+ }
+
+ for my $key (qw(name module version description creator email)) {
+
+ if (!defined $metadata->{$key}) {
+
+ die "Error: Missing <$key>...</$key> in $installXML\n";
+ }
+ }
+
+ if (!$metadata->{'id'}) {
+
+ my $uuid = Data::UUID->new;
+
+ $metadata->{'id'} = $uuid->create_str;
+
+ open(OUT, ">$installXML") or die $!;
+
+ print OUT XMLout($metadata,
+ RootName => 'extension',
+ NoAttr => 1,
+ XMLDecl => 1,
+ );
+
+ close(OUT);
+ }
+
+ return $metadata;
+}
+
+sub generatePARFile {
+ my $baseDir = shift;
+ my $plugin = shift;
+ my $exclude = shift;
+
+ print "- Generating .par file from $plugin->{'module'} in $baseDir\n\n";
+
+ my $libDir = catdir($baseDir, 'lib');
+ my $name = $plugin->{'module'};
+ my $parFile = catdir($libDir, "$name.par");
+
+ $parFile =~ s/::/-/g;
+
+ if (!-d $libDir) {
+
+ die "No lib/ in $baseDir!\n";
+ }
+
+ if (-f $parFile) {
+
+ print "- Removing old $parFile\n\n";
+
+ unlink($parFile) or die "Couldn't remove [$parFile] - $!\n";
+ }
+
+ my $command = "pp \@$exclude -p -o $parFile -I $libDir -M $name -e 1";
+
+ print "- Running: '$command'\n\n";
+
+ system($command);
+
+ if (-f $parFile) {
+
+ print "- PAR file: [$parFile] created ok!\n\n";
+ }
+}
+
+sub generateZipFile {
+ my $baseDir = shift;
+ my $plugin = shift;
+
+ my $zipFile = join('.', $plugin->{'module'}, 'zip');
+ $zipFile =~ s/::/-/g;
+
+ if (-f $zipFile) {
+
+ print "- Removing old $zipFile\n\n";
+
+ unlink($zipFile) or die "Couldn't remove [$zipFile] - $!\n";
+ }
+
+ print "- About to write out zipFile: [$zipFile] from $baseDir\n\n";
+
+ my $zip = Archive::Zip->new;
+
+ $zip->addTreeMatching($baseDir, undef, '\.par$');
+ $zip->addTreeMatching($baseDir, undef, '\.xml$');
+ $zip->addTreeMatching($baseDir, undef, '\.js$');
+ $zip->addTreeMatching($baseDir, undef, '\.html?$');
+ $zip->addTreeMatching($baseDir, undef, '\.jpe?g$');
+ $zip->addTreeMatching($baseDir, undef, '\.gif$');
+ $zip->addTreeMatching($baseDir, undef, '\.png$');
+ $zip->addTreeMatching($baseDir, undef, '\.txt$');
+ $zip->addTreeMatching($baseDir, undef, '\.conf$');
+ $zip->addTreeMatching($baseDir, undef, '\bbin\b');
+
+ my $status = $zip->writeToFileNamed($zipFile);
+
+ if ($status != AZ_OK) {
+
+ print "An error occurred while writing out: [$zipFile] exiting!\n";
+ die;
+ }
+
+ return $zipFile;
+}
+
+main();
Propchange: trunk/tools/PluginBuilder/bin/create-slimserver-plugin
------------------------------------------------------------------------------
svn:executable = *
More information about the checkins
mailing list