So I decided to build an exclude list thinking it would be easyer than making an include list.... Long story short I ended up writing this script...
Code: Select all
#!/usr/bin/python
#
# prlock.py (Portage Rsync Lockdown)
# This script creates a exclude list for portage's rsync. The exclude list
# excludes all but the installed packages (found with qpkg).
# Specify 'branch-name/package-name' arguments to unlock additional packages
# that are not yet installed.
# Remember to edit make.conf and make the dir /etc/portage
#
# *WARNING*
# If you use this script and find yourself wanting to add a new package...
# You MUST either add it to the exclude list (By passing it as an arg to
# prlock) or comment out the exclude list entirly in make.conf.
# Then do a sync
# THEN add the package
# If you don't you will add a package that may be out of date!
#
# Eg.....
# > prlock.py dev-python/wxPython
# This will restrict the rsync to only the installed packages AND wxPython
# All other packages will not be updated.
#
# Nick Fisher prlock@nickdafish.com
#
import os, re, sys
# Quit if an arg that doens't look like a package is encountered.
for arg in sys.argv[1:]:
if not re.match('[\w|-]+/[\w|-]+',arg):
print 'Line doens\'t look like it is a package....\n',arg,'\n','...aborting.'
sys.exit(1)
# Check that the make.conf is ready for the exclude
for line in open('/etc/make.conf','r').readlines():
if re.match('RSYNC_EXCLUDEFROM=/etc/portage/rsync_excludes', line): break
else:
print 'WARNING! RSYNC_EXCLUDEFROM=/etc/portage/rsync_excludes was not found in /etc/make.conf'
print 'Make sure that it isn\'t commented out. Portage will not exclude without it!'
# Check that we will be able to write the file
if not os.path.isdir('/etc/portage'):
print "/etc/portage/ does not exist!\nPlease make the dir and try again."
sys.exit(1)
# Run qpkg to find all the installed packages
pkgl = os.popen('/bin/bash /usr/bin/qpkg -nc -I','r').readlines()
# Add the args
for arg in sys.argv[1:]:
pkgl.append(arg)
print 'Adding package from cmd line ',arg
# Add the branches to list and format
fmt = re.compile(r'[\w|-]*/')
list=[]
for line in pkgl:
m = fmt.search(line)
if not('+ '+m.group()+'\n' in list): list.append('+ '+m.group()+'\n')
if not('+ metadata/cache/'+m.group()+'\n' in list): list.append('+ metadata/cache/'+m.group()+'\n')
# Add the package dir and all subdirs/files to list
for x in range(len(pkgl)):
list.append('+ '+pkgl[x].strip()+'/\n')
list.append('+ '+pkgl[x].strip()+'/**\n')
list.append('+ metadata/cache/'+pkgl[x].strip()+'*\n')
# Append the directives to allow access to the metadata
list.append('+ metadata/\n')
list.append('+ metadata/*\n')
list.append('+ metadata/cache/\n')
list.append('+ metadata/cache/*\n')
# Allow sync for eclasses
# I don't know how I could exclude them well
list.append('+ eclass/\n')
list.append('+ eclass/**\n')
# Allow sync for files
# These shouldn't be excluded
list.append('+ files/\n')
list.append('+ files/**\n')
# Allow sync for libsidplay
# I havn't a clue what this branch is about
list.append('+ libsidplay/\n')
list.append('+ libsidplay/**\n')
# Allow sync for licenses
# Should be updated that often
list.append('+ licenses/\n')
list.append('+ licenses/**\n')
# Allow sync for packages
# Dunno what this branch is about
# Include for safteys sake
list.append('+ packages/\n')
list.append('+ packages/**\n')
# Allow sync for profiles
# Should smarten this up at some point
list.append('+ profiles/\n')
list.append('+ profiles/**\n')
# Allow sync for scripts
list.append('+ scripts/\n')
list.append('+ scripts/**\n')
# Sort the list for readability
list.sort()
# Add the include all files and exclude everything else
list.append('+ /*\n- *')
# Write the pkg list out to the exclude file
open('/etc/portage/rsync_excludes','w').writelines(''.join(list))
Things to note:
Remember to make the /etc/portage dir
Remember to uncomment the 'RSYNC_EXCLUDEFROM' in the make.conf
Remember to localise rsync as layed out in the GWN
Also Please note that I'm not and do not profess to be a Portage guru or a Python guru. Infact this is the first python script I have used in production. If you have any notes, bugs or comments about the script please message me and I will do an edit.... lets keep this thread clean.
I'm not really sure that this script is 100% safe. I've been using it for a while, I've have had no trouble and I see no reason why I should. If anyone does spot a problem please let me know!
Happy light weight rsyncing
Nick
EDIT: Added includes for portage dirs that should always be rsynced.






