public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "José Fonseca" <j_r_fonseca@yahoo.co.uk>
To: gentoo-dev@gentoo.org
Subject: [gentoo-dev] Two scripts to automate the daily 'emerge rsync' with unmasked packages
Date: Sat, 8 Jun 2002 22:21:41 +0100	[thread overview]
Message-ID: <20020608212141.GA22808@localhost> (raw)

[-- 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()
	

                 reply	other threads:[~2002-06-08 21:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020608212141.GA22808@localhost \
    --to=j_r_fonseca@yahoo.co.uk \
    --cc=gentoo-dev@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox