For what it's worth, here's a little Python script I use to keep my
local package repository up to date. Martin posted something similar
recently, but it was in Perl, to which I have a slight allergy.
Run it in the same directory that your *.pkg.tar.gz files live.
There are a few configuration variables at the very top that you
can change. Hopefully it's pretty self-explanatory.
#!/usr/local/bin/python
# user-configurable variables
FTP_SERVER="ftp.xemacs.org"
PACKAGE_DIR="/pub/xemacs/beta/xemacs-21.0/packages/binary-packages"
fetch_all = 0
# if fetch_all is nonzero, we get all packages on the server.
# Otherwise we only update the packages which are already present in the
# current directory.
verbose = 1
# end of user-configurable variables
import os, string
from ftplib import FTP
def newer(a,b):
# args are 2-tuples containing (major, minor) version number
if a[0]>b[0]:
return 1
elif a[1]>b[1]:
return 1
else:
return 0
## parselist takes an "ls"-type listing of XEmacs packages and returns
## a dictionary, where the key is basename of the package, and the
## value is a 3-tuple of the form
## (version-major, version-minor,filename)
def parselist(listing):
dict={}
for f in listing:
words = string.split(f,'-')
if words[-1] != 'pkg.tar.gz':
if verbose: print "skipping", f
continue
version = string.split(words[-2],'.')
name = string.join(words[:-2],'-')
if name in dict.keys():
if not newer(version, dict[name]):
if verbose: print f, 'is not newer than', dict[name][2]
continue
dict[name] = (version[0],version[1],f)
if verbose: print name, version[0],version[1]
return dict
if verbose: print "Local packages"
local = parselist(os.listdir("."))
ftp = FTP(FTP_SERVER)
ftp.login()
ftp.cwd(PACKAGE_DIR)
if verbose: print "Remote packages:"
remote=parselist(ftp.nlst())
##callback function for ftp.retrbinary
openfile = None
def storeit(data):
if openfile:
openfile.write(data)
if fetch_all:
packages = remote.keys()
else:
packages = local.keys()
for key in packages:
if newer(remote[key],local[key]):
name = remote[key][2]
if verbose: print "fetching", name
openfile = open(name,"w")
ftp.retrbinary('RETR '+name, storeit, 1024)
openfile.close()
os.unlink(local[key][2])
Show replies by date