~ubuntu-branches/ubuntu/precise/gozerbot/precise

« back to all changes in this revision

Viewing changes to runbot

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2008-06-02 19:26:39 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080602192639-3rn65nx4q1sgd6sy
Tags: 0.8.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
sys.path.insert(0, os.getcwd())
28
28
sys.path.insert(1, os.path.abspath(os.path.join(os.getcwd(), 'myplugs', 'addons')))
29
29
 
30
 
import getopt
31
 
 
32
 
doascii = False
33
 
dobackup = True
34
 
doumode = True
35
 
doresume = False
36
 
 
37
 
try:
38
 
    (options, rest) = getopt.getopt(sys.argv[1:], 'abur:')
39
 
    for i, j in options:
40
 
        if i == '-a':
41
 
            doascii = True
42
 
        if i == '-b':
43
 
            dobackup = True
44
 
        if i == '-u':
45
 
            doumode = False
46
 
        if i == '-r':
47
 
            doresume = j
48
 
except getopt.GetoptError, ex:
49
 
    print str(ex)
50
 
 
51
 
if not doascii:
 
30
from optparse import OptionParser
 
31
 
 
32
parser = OptionParser(usage='usage: %prog [options]', version='%prog 0.8.1')
 
33
 
 
34
parser.add_option('', '-a', action='store_true', default=False, dest='doascii',
 
35
                  help="Use ASCII as the default encoding instead of UTF-8")
 
36
parser.add_option('', '-b', action='store_true', default=False, dest='dobackup',
 
37
                  help="Do Backup")
 
38
parser.add_option('', '-u', action='store_false', default=True, dest='doumode',
 
39
                  help="Check permissions on the gozerdata folder")
 
40
parser.add_option('', '-r', type='string', default=False, dest='doresume', 
 
41
                  metavar='PATH', 
 
42
                  help="Resume the bot from the folder specified")
 
43
 
 
44
opts, args = parser.parse_args()
 
45
opts.args = args
 
46
 
 
47
if not opts.doascii:
52
48
    reload(sys)
53
49
    sys.setdefaultencoding('utf-8')
54
50
 
55
51
sys.setcheckinterval(50)
56
52
socket.setdefaulttimeout(30)
57
53
 
58
 
try:
59
 
    from gozerbot.generic import rlog, handle_exception, enable_logging, \
60
 
checkpermissions
61
 
    from gozerbot.config import config, writeconfig
 
54
from gozerbot.generic import handle_exception
 
55
 
 
56
try:
 
57
    from gozerbot.config import config, writeconfig, writeloadlist
 
58
    from gozerbot.datadir import makedirs
 
59
    from gozerbot.generic import enable_logging
 
60
    makedirs()
 
61
    writeconfig()
 
62
    writeloadlist()
 
63
    config.load()
 
64
    enable_logging()
 
65
except Exception, ex:
 
66
    handle_exception()
 
67
    os._exit(1)
 
68
 
 
69
try:
 
70
    from gozerbot.generic import rlog, handle_exception, checkpermissions
62
71
    from gozerbot.bot import Bot
63
72
    from gozerbot.fleet import fleet
64
73
    from gozerbot.plugins import plugins
65
74
    from gozerbot.eventhandler import mainhandler
66
75
    from gozerbot.users import users
67
76
    from gozerbot.thr import start_new_thread
68
 
    from gozerbot.datadir import makedirs
69
77
    from gozerbot.partyline import partyline
70
78
    from gozerbot.exit import globalshutdown
71
79
except Exception, ex:
72
 
    print ex
73
 
    os._exit(0)
74
 
 
 
80
    handle_exception()
 
81
    os._exit(1)
75
82
 
76
83
import time, signal, gc, types
77
84
 
85
92
 
86
93
signal.signal(signal.SIGTERM, dostop)
87
94
 
88
 
makedirs()
89
 
writeconfig()
90
 
config.load()
91
 
enable_logging()
 
95
 
92
96
rlog(10, 'GOZERBOT', 'starting %s' % config['version'])
93
 
rlog(10, 'gozerbot', 'default encoding is %s' % sys.getdefaultencoding())
 
97
rlog(5, 'gozerbot', 'default encoding is %s' % sys.getdefaultencoding())
94
98
 
95
 
if doumode:
 
99
if opts.doumode:
96
100
    umask = config['umask']
97
101
    if not umask:
98
102
        checkpermissions('gozerdata', 0700)
118
122
else:
119
123
    owner += config['owneruserhost']
120
124
 
121
 
for i in owner:
122
 
    username = users.getname(i)
123
 
    if not username:
124
 
        if not users.merge('owner', i):
125
 
            users.add('owner', [i, ], perms = ['USER', 'OPER'])
 
125
try:
 
126
    for i in owner:
 
127
        username = users.getname(i)
 
128
        if not username:
 
129
            if not users.merge('owner', i):
 
130
                users.add('owner', [i, ], perms = ['USER', 'OPER'])
 
131
except Exception, ex:
 
132
    print str(ex)
 
133
    os._exit(1)
126
134
 
127
135
# register plugins
128
136
start_new_thread(plugins.regplugins, ())
132
140
    try:
133
141
        from gozerbot.jabberbot import Jabberbot
134
142
    except ImportError:
135
 
        print "no xmpppy installed"
136
 
        os._exit(0)
137
 
    bot = Jabberbot('jabbermain')
 
143
        handle_exception()
 
144
        os._exit(1)
 
145
    bot = Jabberbot('jabbermain', config['jabberowner'])
138
146
    bot.host = config['jabberhost']
139
147
    bot.user = config['jabberuser']
140
148
    bot.password = config['jabberpass']
141
149
    bot.port = 5222
142
 
else:
143
 
    bot = Bot(config['owneruserhost'])
 
150
    # add to fleet
 
151
    fleet.addbot(bot)
 
152
 
 
153
if not config['ircdisable']:
 
154
    bot = Bot('main', config['owneruserhost'])
144
155
    bot.nick = config['nick'] or 'gb1'
145
156
    bot.server = config['server'] or 'localhost'
146
157
    bot.port = config['port'] or 6667
147
 
    bot.password = config['password']
148
 
    bot.ipv6 = config['ipv6']
 
158
    bot.password = config['password'] or ""
 
159
    bot.ipv6 = config['ipv6'] or 0
 
160
    bot.ssl = config['ssl'] or 0
 
161
    # add to fleet
 
162
    fleet.addbot(bot)
149
163
 
150
 
# add to fleet
151
 
fleet.addbot(bot)
152
 
if doresume and os.path.isfile(doresume):
153
 
    fleet.resume(doresume)
 
164
if opts.doresume and os.path.isfile(opts.doresume):
 
165
    fleet.resume(opts.doresume)
154
166
    fleet.startok.wait()
155
 
    partyline.resume(doresume)
156
 
    os.unlink(doresume) # bye
 
167
    partyline.resume(opts.doresume)
 
168
    os.unlink(opts.doresume) # bye
157
169
else:
158
170
    fleet.start()
159
171
 
167
179
    except Exception, ex:
168
180
        handle_exception()
169
181
        globalshutdown()
170
 
        os._exit(0)
 
182
        os._exit(1)