diff --git a/Demo/scripts/newslist.py b/Demo/scripts/newslist.py index 1dc8af20415..7e0fade228f 100755 --- a/Demo/scripts/newslist.py +++ b/Demo/scripts/newslist.py @@ -32,22 +32,22 @@ # fraser@europarc.xerox.com qs101@cl.cam.ac.uk # # ####################################################################### -import sys,nntplib, string, marshal, time, os, posix, string +import sys, nntplib, marshal, time, os ####################################################################### # Check these variables before running! # # Top directory. # Filenames which don't start with / are taken as being relative to this. -topdir='/anfs/qsbigdisc/web/html/newspage' +topdir = os.path.expanduser('~/newspage') # The name of your NNTP host # eg. # newshost = 'nntp-serv.cl.cam.ac.uk' # or use following to get the name from the NNTPSERVER environment # variable: -# newshost = posix.environ['NNTPSERVER'] -newshost = 'nntp-serv.cl.cam.ac.uk' +# newshost = os.environ['NNTPSERVER'] +newshost = 'news.example.com' # The filename for a local cache of the newsgroup list treefile = 'grouptree' @@ -81,7 +81,7 @@ skipempty = 1 # pagelinkicon can contain html to put an icon after links to # further pages. This helps to make important links stand out. # Set to '' if not wanted, or '...' is quite a good one. -pagelinkicon='... ' +pagelinkicon = '... ' # --------------------------------------------------------------------- # Less important personal preferences: @@ -106,7 +106,7 @@ from nntplib import NNTP from stat import * rcsrev = '$Revision$' -rcsrev = string.join(filter(lambda s: '$' not in s, string.split(rcsrev))) +rcsrev = ' '.join(filter(lambda s: '$' not in s, rcsrev.split())) desc = {} # Make (possibly) relative filenames into absolute ones @@ -120,7 +120,7 @@ page = os.path.join(topdir,pagedir) def addtotree(tree, groups): print 'Updating tree...' for i in groups: - parts = string.splitfields(i,'.') + parts = i.split('.') makeleaf(tree, parts) # Makeleaf makes a leaf and the branch leading to it if necessary @@ -141,34 +141,38 @@ def makeleaf(tree,path): # to those groups beginning with . def createpage(root, tree, p): - filename = os.path.join(pagedir,root+'.html') + filename = os.path.join(pagedir, root+'.html') if root == rootpage: detail = '' else: detail = ' under ' + root - f = open(filename,'w') - # f.write('Content-Type: text/html\n') - f.write('Newsgroups available' + detail + '\n') - f.write('

Newsgroups available' + detail +'

\n') - f.write('Back to top level

\n') - printtree(f,tree,0,p) - f.write('This page automatically created by \'newslist\' v. '+rcsrev+'.') - f.write(time.ctime(time.time()) + '

') - f.close() + with open(filename, 'w') as f: + # f.write('Content-Type: text/html\n') + f.write('\n\n') + f.write('Newsgroups available%s\n' % detail) + f.write('\n\n') + f.write('

Newsgroups available%s

\n' % detail) + f.write('Back to top level

\n' % + (httppref, rootpage)) + printtree(f, tree, 0, p) + f.write('\n

') + f.write("This page automatically created by 'newslist' v. %s." % + rcsrev) + f.write(time.ctime(time.time()) + '\n') + f.write('\n\n') # Printtree prints the groups as a bulleted list. Groups with # more than subgroups will be put on a separate page. # Other sets of subgroups are just indented. def printtree(f, tree, indent, p): - global desc l = len(tree) - if l > sublistsize and indent>0: + if l > sublistsize and indent > 0: # Create a new page and a link to it - f.write('

  • ') - f.write(p[1:]+'.*') - f.write(''+pagelinkicon+'\n') + f.write('
  • ' % (httppref, p[1:])) + f.write(p[1:] + '.*') + f.write('%s\n' % pagelinkicon) createpage(p[1:], tree, p) return @@ -178,67 +182,64 @@ def printtree(f, tree, indent, p): kl.sort() if indent > 0: # Create a sub-list - f.write('
  • '+p[1:]+'\n