tags 551310 patch
thanks

Here are patches to provide an sbuild-clean script.

On Saturday 17 October 2009 01:37:29 Andres Mejia wrote:
> Package: sbuild
> Version: 0.59.1~rc1
> Severity: wishlist
> 
> 
> It would be nice if there was a corresponding sbuild-clean script to
>  perform various cleaning commands with apt-get, such as "clean" and
>  "autoremove".
> 
> I currently had to use sbuild-apt to perform a cleaning. It does help bring
>  down the size of a newly created chroot tarball from 140MB to roughly
>  70MB.
> 
> -- System Information:
> Debian Release: squeeze/sid
>   APT prefers unstable
>   APT policy: (500, 'unstable'), (1, 'experimental')
> Architecture: i386 (i686)
> 
> Kernel: Linux 2.6.30-2-686 (SMP w/2 CPU cores)
> Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
> Shell: /bin/sh linked to /bin/dash
> 
> Versions of packages sbuild depends on:
> ii  adduser                       3.111      add and remove users and
>  groups ii  libsbuild-perl                0.59.1~rc1 Tool for building
>  Debian binary pa ii  perl                          5.10.1-5   Larry Wall's
>  Practical Extraction ii  perl-modules                  5.10.1-5   Core
>  Perl modules
> 
> Versions of packages sbuild recommends:
> ii  debootstrap                   1.0.20     Bootstrap a basic Debian
>  system ii  fakeroot                      1.14       Gives a fake root
>  environment
> 
> Versions of packages sbuild suggests:
> pn  deborphan                     <none>     (no description available)
> ii  wget                          1.12-1     retrieves files from the web
> 
> -- no debconf information
> 
> 
> 
> _______________________________________________
> Buildd-tools-devel mailing list
> [email protected]
> http://lists.alioth.debian.org/mailman/listinfo/buildd-tools-devel
> 

-- 
Regards,
Andres
From 5480dbdef2b1987792e39915510c19665eb3a1b9 Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
Date: Sat, 17 Oct 2009 17:38:10 -0400
Subject: [PATCH 1/4] Supply subroutines to perform apt-get cleaning commands.

---
 lib/Sbuild/ChrootSetup.pm |   43 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/lib/Sbuild/ChrootSetup.pm b/lib/Sbuild/ChrootSetup.pm
index fa01b85..8afba06 100644
--- a/lib/Sbuild/ChrootSetup.pm
+++ b/lib/Sbuild/ChrootSetup.pm
@@ -31,13 +31,16 @@ BEGIN {
 
     @ISA = qw(Exporter);
 
-    @EXPORT = qw(update upgrade distupgrade basesetup shell
-                 list_packages set_package_status);
+    @EXPORT = qw(update upgrade distupgrade clean autoclean autoremove basesetup
+                 shell list_packages set_package_status);
 }
 
 sub update ($$);
 sub upgrade ($$);
 sub distupgrade($$);
+sub clean ($$);
+sub autoclean ($$);
+sub autoremove ($$);
 sub basesetup ($$);
 sub shell ($$);
 sub list_packages ($$@);
@@ -79,6 +82,42 @@ sub distupgrade ($$) {
     return $?;
 }
 
+sub clean ($$) {
+    my $session = shift;
+    my $conf = shift;
+
+    $session->run_apt_command(
+	{ COMMAND => [$conf->get('APT_GET'), '-y', 'clean'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
+sub autoclean ($$) {
+    my $session = shift;
+    my $conf = shift;
+
+    $session->run_apt_command(
+	{ COMMAND => [$conf->get('APT_GET'), '-y', 'autoclean'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
+sub autoremove ($$) {
+    my $session = shift;
+    my $conf = shift;
+
+    $session->run_apt_command(
+	{ COMMAND => [$conf->get('APT_GET'), '-y', 'autoremove'],
+	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
+	  USER => 'root',
+	  DIR => '/' });
+    return $?;
+}
+
 sub basesetup ($$) {
     my $session = shift;
     my $conf = shift;
-- 
1.6.5

From dad74ff42566eb4fb603238278a87491806dbd44 Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
Date: Sat, 17 Oct 2009 17:38:58 -0400
Subject: [PATCH 2/4] Supply sbuild-clean script that can perform various apt-get cleaning commands for chroots.

---
 bin/sbuild-clean |  143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 143 insertions(+), 0 deletions(-)
 create mode 100755 bin/sbuild-clean

diff --git a/bin/sbuild-clean b/bin/sbuild-clean
new file mode 100755
index 0000000..b7e65ab
--- /dev/null
+++ b/bin/sbuild-clean
@@ -0,0 +1,143 @@
+#!/usr/bin/perl -w
+#
+# Copyright © 2005-2009  Roger Leigh <[email protected]>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+#######################################################################
+
+use strict;
+use warnings;
+
+use Sbuild::ChrootSetup qw(clean autoclean autoremove);
+
+package Conf;
+
+use Sbuild::Conf;
+
+BEGIN {
+    use Exporter ();
+    our (@ISA, @EXPORT);
+
+    @ISA = qw(Exporter Sbuild::Conf);
+
+    @EXPORT = qw();
+}
+
+sub init_allowed_keys {
+    my $self = shift;
+
+    $self->SUPER::init_allowed_keys();
+
+    my %update_keys = (
+	'CLEAN'				=> {
+	    DEFAULT => 0
+	},
+	'AUTOCLEAN'			=> {
+	    DEFAULT => 0
+	},
+	'AUTOREMOVE'			=> {
+	    DEFAULT => 0
+	},
+    );
+
+    $self->set_allowed_keys(\%update_keys);
+}
+
+package Options;
+
+use Sbuild::OptionsBase;
+use Sbuild::Conf;
+
+BEGIN {
+    use Exporter ();
+    our (@ISA, @EXPORT);
+
+    @ISA = qw(Exporter Sbuild::OptionsBase);
+
+    @EXPORT = qw();
+}
+
+sub set_options {
+    my $self = shift;
+
+    $self->add_options(
+	"clean|c" => sub {
+	    $self->set_conf('CLEAN', 1);
+	},
+	"autoclean|a" => sub {
+	    $self->set_conf('AUTOCLEAN', 1);
+	},
+	"autoremove|r" => sub {
+	    $self->set_conf('AUTOREMOVE', 1);
+	});
+}
+
+package main;
+
+use Getopt::Long;
+use Sbuild qw(help_text version_text usage_error);
+use Sbuild::Utility qw(setup cleanup);
+
+my $conf = Conf->new();
+exit 1 if !defined($conf);
+my $options = Options->new($conf, "sbuild-clean", "1");
+exit 1 if !defined($options);
+$conf->check_group_membership();
+
+if ( ! $conf->get('CLEAN') && ! $conf->get('AUTOCLEAN') &&
+    ! $conf->get('AUTOREMOVE') ) {
+    $conf->set('CLEAN', 1);
+}
+
+usage_error("sbuild-clean", "Incorrect number of options") if (@ARGV < 1);
+
+foreach (@ARGV) {
+
+    my $chroot = Sbuild::Utility::get_dist($_);
+
+    my $session = setup($ARGV[0], $conf) or die "Chroot setup failed";
+
+    if ($conf->get('CLEAN')) {
+	print "Performing clean.\n";
+	my $status = clean($session, $conf);
+	$status >>= 8;
+	if ($status) {
+	    die "Exiting from update with status $status.\n";
+	}
+    }
+
+    if ($conf->get('AUTOCLEAN')) {
+	print "Performing autoclean.\n";
+	my $status = autoclean($session, $conf);
+	$status >>= 8;
+	if ($status) {
+	    die "Exiting from upgrade with status $status.\n";
+	}
+    }
+
+    if ($conf->get('AUTOREMOVE')) {
+	print "Performing autoremove.\n";
+	my $status = autoremove($session, $conf);
+	$status >>= 8;
+	if ($status) {
+	    die "Exiting from distupgrade with status $status.\n";
+	}
+    }
+
+    cleanup($conf);
+}
+
+exit 0;
-- 
1.6.5

From 99a3981fee31fcd29fea356971bbf048f44cc3ed Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
Date: Sat, 17 Oct 2009 17:39:55 -0400
Subject: [PATCH 3/4] Provide man page for new sbuild-clean script.

---
 man/sbuild-clean.1.in |   83 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 man/sbuild-clean.1.in

diff --git a/man/sbuild-clean.1.in b/man/sbuild-clean.1.in
new file mode 100644
index 0000000..342e6d0
--- /dev/null
+++ b/man/sbuild-clean.1.in
@@ -0,0 +1,83 @@
+.\" Copyright © 2005-2009  Roger Leigh <[email protected]>
+.\"
+.\" This program is free software: you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation, either version 2 of the License, or
+.\" (at your option) any later version.
+.\"
+.\" This program is distributed in the hope that it will be useful, but
+.\" WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+.\" General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" along with this program.  If not, see
+.\" <http://www.gnu.org/licenses/>.
+.TH SBUILD\-CLEAN 1 "@RELEASE_DATE@" "Version @VERSION@" "Debian sbuild"
+.SH NAME
+sbuild\-clean \- clean an sbuild chroot with apt-get
+.SH SYNOPSIS
+.BR sbuild\-clean
+.BR [ \-h \[or] \-\-help ] " " [ \-V \[or] \-\-version ]
+.BR [ \-c \[or] \-\-clean ] " " [ \-a \[or] \-\-autoclean ] " "
+.BR [ \-r \[or] \-\-autoremove ]
+.BR CHROOT1 " [" CHROOT2 " [" CHROOT\f[BI]n\fP... ]]
+.SH DESCRIPTION
+\fBsbuild\-clean\fR runs \f[CB]apt\-get\fP inside the specified chroot
+performing \f[CB]clean\fP, \f[CB]autoclean\fP, and/or \f[CB]autoremove\fP
+depending on the options specified on the command line.
+.SH OPTIONS
+.SS Actions
+.TP
+.BR \-h ", " \-\-help
+Display this manual.
+.TP
+.BR \-V ", " \-\-version
+Print version information.
+.TP
+.BR \-c ", " \-\-clean
+Perform an \f[CB]apt\-get clean\fP. This is the default if no options are
+specified.
+.TP
+.BR \-a ", " \-\-autoclean
+Perform an \f[CB]apt\-get autoclean\fP.
+.TP
+.BR \-r ", " \-\-autoremove
+Perform an \f[CB]apt\-get autoremove\fP.
+.SS Chroot selection
+.TP
+.B CHROOT
+The chroot to use.  Note that \[oq]o\[cq], \[oq]s\[cq],
+\[oq]t\[cq], \[oq]u\[cq] and \[oq]e\[cq] may be used as abbreviations for
+\[oq]oldstable\[cq], \[oq]stable\[cq], \[oq]testing\[cq], \[oq]unstable\[cq]
+and \[oq]experimental\[cq], respectively.
+.SH EXAMPLES
+To clean the \fIunstable\fP chroot:
+.PP
+\f[CR]% \f[CB]sbuild\-clean \-\-clean unstable\fP\fP
+.PP
+To perform an autoremove on the \fIunstable\fP chroot:
+.PP
+\f[CR]% \f[CB]sbuild\-clean \-\-autoremove unstable\fP\fP
+.PP
+To perform both n clean and an autoremove for the
+\fIunstable\fP chroot:
+.PP
+\f[CR]% \f[CB]sbuild\-clean \-cr unstable\fP\fP
+.SH AUTHORS
+.nf
+Roger Leigh.
+.fi
+.SH COPYRIGHT
+.nf
+Copyright \[co] 2006\[en]2009 Roger Leigh <[email protected]>.
+.fi
+.SH "SEE ALSO"
+.BR sbuild (1),
+.BR sbuild\-apt (1),
+.\"#
+.\"# The following sets edit modes for GNU EMACS
+.\"# Local Variables:
+.\"# mode:nroff
+.\"# fill-column:79
+.\"# End:
-- 
1.6.5

From 81236bfc2460c30eb04b0f0e141fd3203033b8b3 Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
Date: Sat, 17 Oct 2009 17:40:23 -0400
Subject: [PATCH 4/4] Update build system to install sbuild-clean script and man page.

---
 bin/Makefile.am |    1 +
 configure.ac    |    1 +
 man/Makefile.am |    1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/bin/Makefile.am b/bin/Makefile.am
index 53c5aaa..9a90a11 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -32,6 +32,7 @@ bin_SCRIPTS = 				\
 	sbuild-update			\
 	sbuild-upgrade			\
 	sbuild-distupgrade		\
+	sbuild-clean			\
 	sbuild-shell			\
 	sbuild-stats			\
 	sbuild-hold			\
diff --git a/configure.ac b/configure.ac
index c878b13..f65c9cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -313,6 +313,7 @@ AC_CONFIG_FILES([man/sbuild-setup.7])
 AC_CONFIG_FILES([man/sbuild-shell.1])
 AC_CONFIG_FILES([man/sbuild-stats.1])
 AC_CONFIG_FILES([man/sbuild-update.1])
+AC_CONFIG_FILES([man/sbuild-clean.1])
 AC_CONFIG_FILES([man/wanna-build.1])
 AC_CONFIG_FILES([man/wanna-build-catdb.1])
 AC_CONFIG_FILES([man/wanna-build-mail.1])
diff --git a/man/Makefile.am b/man/Makefile.am
index 94ac8d6..ef9cd4e 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -38,6 +38,7 @@ man_MANS =				\
 	sbuild-shell.1			\
 	sbuild-stats.1			\
 	sbuild-update.1			\
+	sbuild-clean.1			\
 	wanna-build.1			\
 	wanna-build-catdb.1		\
 	wanna-build-mail.1		\
-- 
1.6.5

Reply via email to