public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] Two scripts to automate the daily 'emerge rsync' with unmasked packages
@ 2002-06-08 21:21 José Fonseca
  0 siblings, 0 replies; only message in thread
From: José Fonseca @ 2002-06-08 21:21 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1270 bytes --]

Here two scripts to automate the daily 'emerge rsync' with unmasked 
packages.

To use them gust have your unmasked packages in 
/usr/portage/profiles/package.mask by double commenting them out, i.e., 
inserting '##' before them, e.g., changing

   # spider@gentoo.org ; 21 May 2002;   # =x11-libs/gtk+-1.2* doesn't work
   # this is now the gnome2 big bloated mask!
   # (gnome-2 that is ;)
   >=x11-libs/gtk-engines-1.9.0
   >=gnome-base/libglade-1.99.10-r1
   >=app-text/scrollkeeper-0.3.0

   ...

into

   # spider@gentoo.org ; 21 May 2002;   # =x11-libs/gtk+-1.2* doesn't work
   # this is now the gnome2 big bloated mask!
   # (gnome-2 that is ;)
   ##>=x11-libs/gtk-engines-1.9.0
   ##>=gnome-base/libglade-1.99.10-r1
   ##>=app-text/scrollkeeper-0.3.0

   ...

and run (as root) the 'emerge_rsync.sh' script as many times you want! ;-)

It will also present you with what has been changed in package.mask and in 
"world".

Also give a look into the scripts to know a little more - I've minimally 
commented them and they are fairly simple.

I hope that you find this useful. If yes, please tell, and I'll make sure 
that any fixes and improvements that I (or others) make get back to you 
(e.g., by hosting these scripts in my webpage).

Regards,

José Fonseca

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: emerge_rsync.sh --]
[-- Type: text/x-sh; charset=unknown-8bit, Size: 1555 bytes --]

#!/bin/sh

# emerge_rsync.sh
#
# Alternative shell script to 'emerge rsync' that tries to keep the unmasked packages'
#
# Just have your unmasked packages by double commenting them out, i.e., inserting '##' before them, and run this script
#
# 	José Fonseca <j_r_fonseca@yahoo.co.uk>

PACKAGE_MASK=/usr/portage/profiles/package.mask
PACKAGE_MASK_OLD=`mktemp` || exit 1
PACKAGE_MASK_NEW=`mktemp` || exit 1

# Copy the old package.mask
cp $PACKAGE_MASK $PACKAGE_MASK_OLD || exit 1

emerge rsync || exit 1

# Mimic the packages unmasked by '#' in the old package.mask
python package.py $PACKAGE_MASK_OLD $PACKAGE_MASK > $PACKAGE_MASK_NEW || exit 1

# One can choose between two diffs:
#
#   diff -u $PACKAGE_MASK $PACKAGE_MASK_NEW
# 
# shows what has been unmasked again, while
#
#   diff -u $PACKAGE_MASK_OLD $PACKAGE_MASK_NEW
#
# shows what changed between your previous and suggested package mask. 
# The later shows also what has been added so I find it a little more interesting, and if there is no change then it's obvious too, and one doesn't need too take much attention to it. ;-)
#
# It would be nice if less allowed to quit with non-zero return value, but unfortunately if you want to avoid the changes you'll have to hit Ctrl-Z and kill it...
if diff -u $PACKAGE_MASK_OLD $PACKAGE_MASK_NEW | less
then
	mv -f $PACKAGE_MASK_NEW $PACKAGE_MASK
else
	rm -f $PACKAGE_MASK_NEW
fi
rm -f $PACKAGE_MASK_OLD

# Leave this here if you also want to know what new stuff is available
emerge --update --pretend world

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: package.py --]
[-- Type: text/x-python; charset=unknown-8bit, Size: 2106 bytes --]

#!/usr/bin/env python

# package.py
#
# Python program to mimic the packages unmasked by '##' in package.mask across an 'emerge rsync'
#
# 	José Fonseca <j_r_fonseca@yahoo.co.uk>

def make_key(operator,category,package,version,release):
	key = package
	if operator:
		key = operator + key
		if operator == '=':
			key = key + '-' + version
	return key
	


if __name__ == "__main__":
	import sys, os, time, glob, re, string

	old = sys.argv[1]
	new = sys.argv[2]
	
	# Regular expressions to match the packages masks
	OPERATOR_RE = r"([*<>=~]+)"
	CATEGORY_RE = r"([0-9a-zA-Z]+-[0-9a-zA-Z]+)"
	PACKAGE_RE = r"([a-zA-Z+][-+_0-9a-zA-Z]*?)"
	NUMBER_RE = r"(?:[a-zA-Z]*[0-9]+|[0-9]+[a-zA-Z]*)"
	VERSION_RE = r"(" + NUMBER_RE + r"(?:[._]" + NUMBER_RE + r")*)"
	RELEASE_RE = r"(r[0-9]+)"
	EXTENSION_RE = r"[0-9a-zA-Z]+"
	MASK_RE = OPERATOR_RE + r"?(?:" + CATEGORY_RE + r"/)?" + PACKAGE_RE + r"(?:-" + VERSION_RE + r"\*?(?:-" + RELEASE_RE + r")?)?(?:\." + EXTENSION_RE + r")?"
	UNMASK_RE = r"##" + MASK_RE

	BEGIN_RE = r"^"
	END_RE = r"(?:[ 	].*)?\n$"
			
	mask_re = re.compile(BEGIN_RE + MASK_RE + END_RE)
	unmask_re = re.compile(BEGIN_RE + UNMASK_RE + END_RE)
	
	# Dictinary to old the unmasked packages keys. The key consists of the operator and package name to cope with multiple ocurrences of the same package
	unmasked = {};
	
	# Search for unmasked packages in the old package.mask
	f = open(old)
	l = f.readline()
	while l != "":	
		if unmask_re.match(l):
			begin,operator,category,package,version,release,end = unmask_re.split(l)
			key = make_key(operator,category,package,version,release)

			unmasked[key] = 1;
		
		l = f.readline()
	f.close()

	# Unmask them again on the new package.mask
	f = open(new)
	l = f.readline()
	while l != "":	
		if mask_re.match(l):
			begin,operator,category,package,version,release,end = mask_re.split(l)
			key = make_key(operator,category,package,version,release)
			
			if unmasked.has_key(key):
				print "##" + l,
			else:
				print l,
		else:
			print l,
		
		l = f.readline()
	f.close()
	

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-06-08 21:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-08 21:21 [gentoo-dev] Two scripts to automate the daily 'emerge rsync' with unmasked packages José Fonseca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox