head	1.6;
access;
symbols
	RELEASE-1_4:1.5.0.2
	GENTOO_1_4_SNAP_2003010800:1.4;
locks; strict;
comment	@# @;


1.6
date	2003.08.15.12.50.15;	author lanius;	state dead;
branches;
next	1.5;

1.5
date	2003.02.14.22.06.26;	author vapier;	state Exp;
branches;
next	1.4;

1.4
date	2002.07.15.12.17.02;	author karltk;	state Exp;
branches;
next	1.3;

1.3
date	2002.03.17.14.33.45;	author karltk;	state Exp;
branches;
next	1.2;

1.2
date	2002.03.17.02.04.51;	author karltk;	state Exp;
branches;
next	1.1;

1.1
date	2002.01.24.20.45.57;	author karltk;	state Exp;
branches;
next	;


desc
@@


1.6
log
@moved to app-portage
@
text
@#!/usr/bin/python
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-x86/app-admin/gentoolkit/files/scripts/pkg-clean,v 1.5 2003/02/14 22:06:26 vapier Exp $
# Author: Leo Lipelis <aeoo@@gentoo.org>
# Author: Karl Trygve Kalleberg <karltk@@gentoo.org>

import commands
import re
import sys
import string
import time
import os

# constants for package tuples that are stored in pkg_hash
PKG_TIME = 0 # number of seconds for ctime function
PKG = 1 # package full path as accepted by ebuild
PKG_NAME = 2 # package name as accepted by emerge

(status, pkg_files) = commands.getstatusoutput(
		"find /var/db/pkg -iname '*.ebuild' -printf '%T@@ %p\n' | sort -n")

pkg_file_list = pkg_files.splitlines()

pkg_hash = {}
for time_pkg_pair in pkg_file_list:
	(pkg_time, pkg) = time_pkg_pair.split()
	pkg_time = string.atoi(pkg_time)
	# This covers developer trees with not-accepted categories
	tmp_name = re.match(r'/var/db/pkg/(.*/.*)/.*', pkg)
	if not tmp_name: continue
	pkg_name = tmp_name.group(1)
	tmp_core = re.match(r'(.*)-\d.*', pkg_name)
	if not tmp_core: continue
	pkg_core = tmp_core.group(1)
	if pkg_hash.has_key(pkg_core):
		pkg_hash[pkg_core].append((pkg_time, pkg, pkg_name))
	else:
		pkg_hash[pkg_core] = [(pkg_time, pkg, pkg_name)]

total_len = len(pkg_hash.keys())
curpkg = 0
tmpname = os.tmpnam()
assume_yes = 0

if len(sys.argv) > 1:
	if sys.argv[1] in ["-y", "--yes"]:
		assume_yes = 1
	elif sys.argv[1] in ["-h", "--help"]:
		print """pkg-clean [options]

-y, --yes       Don't ask for individual confirmation before unmerging; assume yes.
"""
		sys.exit(0)

for pkg_core in pkg_hash.keys():
	print "Examining %s:" % (pkg_core)
	if len(pkg_hash[pkg_core]) < 2:
		continue
	unmerged_indexes = []
	
	curpkg += 1
	choices = ""
	idx = 1
	for pkg_tuple in pkg_hash[pkg_core]:
		choices += " %d \"%s %s\" 0" % \
			   (idx, time.ctime(pkg_tuple[PKG_TIME]),
			    pkg_tuple[PKG_NAME])
		idx += 1

	params = "dialog --separate-output --backtitle \"pkg-clean processing package %d of %d\" " % ( curpkg, total_len)
	params += "--checklist \"Select which package(s) to unmerge\" 20 70 12" + choices
	res = os.system(params + " 2> " + tmpname)
	if res:
		sys.exit(0)
	
	ins = open(tmpname)
	for j in ins.readlines():
		idx = string.atoi(j)
		if idx == 0:
			break

		full_path = pkg_hash[pkg_core][idx-1][PKG]
		ebuild = string.replace(full_path, "/var/db/pkg/", "")

		if not assume_yes: 
			params = "dialog --backtitle \"" + ebuild + "\" " + \
				 "--yesno \"Are you sure you want to unmerge " + ebuild + " ?\" 20 70"
			res = os.system(params)
		else:
			res = 0

		if res == 0:
			(status, unmerge_out) = commands.getstatusoutput(
				"ebuild %s unmerge" % (full_path))
			print unmerge_out
			time.sleep(2)
			if status != 0:
				sys.exit(status)
	ins.close()
@


1.5
log
@update copyright info
@
text
@d4 1
a4 1
# $Header: $
@


1.4
log
@Fixed missing -y support
@
text
@d2 3
a4 3
# vim: set ts=4 sw=4:
# Copyright 2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
@


1.3
log
@Fixed major path bug in pkg-clean
@
text
@d86 7
a92 3
		params = "dialog --backtitle \"" + ebuild + "\" " + \
			 "--yesno \"Are you sure you want to unmerge " + ebuild + " ?\" 20 70"
		res = os.system(params)
@


1.2
log
@Added dialog-based menu to pkg-clean
@
text
@d8 1
a8 1
import commands as c
d20 1
a20 1
(status, pkg_files) = c.getstatusoutput(
d83 2
a84 1
		ebuild = string.replace(pkg_hash[pkg_core][idx-1][PKG], "/var/db/pkg/", "")
d90 2
a91 2
			(status, unmerge_out) = c.getstatusoutput(
				"ebuild %s unmerge" % (ebuild))
d93 1
@


1.1
log
@Initial import of Gentoolkit
@
text
@d5 2
a6 1
# Author: Leo Lipelis
d13 1
d29 7
a35 2
	pkg_name = re.match(r'/var/db/pkg/(.*/.*)/.*', pkg).group(1)
	pkg_core = re.match(r'(.*)-\d.*', pkg_name).group(1)
d41 15
d61 20
a80 13
	while 1:
		i = 0
		print "0) Continue"
		for pkg_tuple in pkg_hash[pkg_core]:
			if i not in unmerged_indexes:
				print "%d) %s %s" % (
						i+1,
						time.ctime(pkg_tuple[PKG_TIME]),
						pkg_tuple[PKG_NAME])
			i = i + 1
		print "Unmerge: ",
		index = string.atoi(sys.stdin.readline())
		if index == 0:
d82 7
a88 6
		else:
			index = index - 1
		ebuild = pkg_hash[pkg_core][index][PKG]
		print "Unmerge %s? " % (ebuild),
		confirmed = sys.stdin.readline()
		if confirmed == "y\n":
d90 1
a90 1
					"ebuild %s unmerge" % (ebuild))
d94 1
a94 3
			unmerged_indexes.append(index)
		else:
			print "continuing without unmerging..."
@

