Python program to create groups for Cnews

Lance Ellinghouse (lance@markv.com)
Thu, 11 Feb 93 18:35:17 PST

I was tired of creating groups for Cnews by hand..
I whipped up a little program to do it for me..
All you have to do is change to vars at the beginning and
away it goes.. if you find any problems or want to make it better,
let me know..
Thanks!
Lance Ellinghouse
lance@markv.com
--- Cut Here:
#! /usr2/local/bin/python

# This file takes and scans for files in the "junk" directory
# of Cnews. It then creates groups based on the Newsgroups: line
# in these files. It then exits.

import sys, os, string

junkdir='/usr/spool/cnews/junk/'
bindir='/usr2/lib/newsbin/maint/'

def get_groups(file_name):
try:
fd=open(file_name,'r')
except:
print 'cannot open ' + file_name
return []
while 1:
try:
line=fd.readline()
except EOFError:
return []
line=string.strip(line)
if line[:11] == 'Newsgroups:':
groups = string.splitfields(line[12:],',')
return groups
if len(line) == 0:
return []

def make_groups(groups):
for group in groups:
os.system(bindir + 'addgroup ' + group + ' y')

def main():
os.chdir(junkdir)
for file_name in os.listdir('.'):
if file_name not in ['.','..']:
print 'processing ' + file_name
rtn = make_groups(get_groups(file_name))

main()