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