#!/usr/bin/env python
#
# Copyright (C) 2000, 2001 Mark Cornick
# <mcornick@users.sourceforge.net> and contributors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# $Id: convertconf.py,v 1.6 2001/01/14 15:38:47 mcornick Exp $
# WARNING: The Surgeon General has determined that taking IRC too
# seriously is dangerous to your health.
# This script converts old Accutron 2000 configuration files to the
# new format used as of version 2.0beta5.
# This script is full of extremely ugly hacks. Do not emulate this.
import re,os,sys
def transform(line):
"Convert 1.0 format to 2.0 format."
line=re.sub('^HOST','host',line)
line=re.sub('^PORT','port',line)
line=re.sub('^NICK','nick',line)
line=re.sub('^NAME','name',line)
line=re.sub('^CHANNEL','channel',line)
line=re.sub('^CHANMODES','chanmodes',line)
line=re.sub('^BOTSNACKS','botsnacks',line)
line=re.sub('^REMOTEPW','password',line)
line=re.sub('^BOOKMARKS','urllist',line)
line=re.sub('^DEBUG.*$','',line)
line=re.sub('^OPDELAY.*$','',line)
line=re.sub('^OP','op',line)
return line
# Check for a new-style file
try:
import a2kconf
os.remove("a2kconf.pyc")
if a2kconf.server:
oldconf=open("a2kconf.py","r")
newconf=open("newconf.py","w")
for x in oldconf.readlines():
newconf.write(x)
newconf.close()
oldconf.close()
os.rename("a2kconf.py","a2kconf.py.orig")
except (ImportError,AttributeError):
# first try the 2.0beta1 style single file
try:
oldconf=open("a2kconf.py","r")
newconf=open("newconf.py","w")
conf=oldconf.readlines()
oldconf.close()
for x in conf:
newconf.write(transform(x))
newconf.close()
os.rename("a2kconf.py","a2kconf.py.orig")
# failing that, try the 1.0 style twin files
except:
try:
oldconf=open("accutronconf.py","r")
newconf=open("newconf.py","w")
conf=oldconf.readlines()
oldconf.close()
for x in conf:
newconf.write(transform(x))
newconf.close()
oldconf=open("accutronops.py","r")
newconf=open("newconf.py","a")
conf=oldconf.readlines()
oldconf.close()
for x in conf:
newconf.write(transform(x))
newconf.close()
except:
print "I dunno what to do."
sys.exit(1)
# And now, the sneaky part
import newconf
# Add the new opdelay option if needed
try:
newconf.opdelay
except AttributeError:
newconf.opdelay = 5
writeconf = open("a2kconf.py","w")
writeconf.write("""# Accutron 2000 2.x configuration module
# This file created by convertconf.py
# WARNING: The Surgeon General has determined that taking IRC too
# seriously is dangerous to your health.
# The IRC server(s) (host and port) to connect to. This is a list,
# and can contain one or more sets of hosts or ports, e.g.
# server = [('irc.foo.com', 6667),('irc.bar.com', 6667)]
""")
try:
writeconf.write("server = %s\n" % newconf.server)
except AttributeError:
writeconf.write("server = [('%s', %s)]\n" % (newconf.host, newconf.port))
writeconf.write("""# The nickname to use:
nick = '%s'
# The name to use:
name = '%s'
# The channel to join:
channel = '%s'
# What modes to set there:
chanmodes = '%s'
# Want to eat botsnacks? 1 = yes, 0 = no:
botsnacks = %s
# A password for remote commands via /msg:
password = '%s'
# The name of a file to save posted URLs in:
urllist = '%s'
# Number of seconds to wait after someone joins before giving them ops:
opdelay = %s
# Op list. Do not remove the following two lines:
import re
op = {}
# Add new entries below this line.
""" % (newconf.nick,newconf.name,newconf.channel,newconf.chanmodes,newconf.botsnacks,newconf.password,newconf.urllist,newconf.opdelay))
for ii in newconf.op.keys():
writeconf.write("op['"+ii+"'] = re.compile('"+newconf.op[ii].pattern+"')\n")
writeconf.close()
os.remove('newconf.py')
os.remove('newconf.pyc')
print "Your configuration has been converted."
sys.exit(0)
|