~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to gozerbot/reboot.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# gozerbot/utils/reboot.py
 
2
#
 
3
#
 
4
 
 
5
"""
 
6
     reboot code. 
 
7
 
 
8
"""
 
9
 
 
10
## IMPORT SECTION
 
11
 
 
12
from gozerbot.fleet import fleet
 
13
from gozerbot.config import config
 
14
 
 
15
from simplejson import dump
 
16
 
 
17
import os, sys, pickle, tempfile
 
18
 
 
19
## END IMPORT 
 
20
 
 
21
## LOCK SECTION
 
22
 
 
23
# no locks
 
24
 
 
25
## END LOCK
 
26
 
 
27
def reboot():
 
28
 
 
29
    """
 
30
        reboot the bot.
 
31
 
 
32
        .. literalinclude:: ../../gozerbot/reboot.py
 
33
            :pyobject: reboot
 
34
 
 
35
    """
 
36
 
 
37
    fleet.exit()
 
38
    os.execl(sys.argv[0], *sys.argv)
 
39
 
 
40
def reboot_stateful(bot, ievent, fleet, partyline):
 
41
    """
 
42
        reboot the bot, but keep the connections.
 
43
 
 
44
        :param bot: bot on which the reboot command is given
 
45
        :type bot: gozerbot.botbase.BotBase     
 
46
        :param ievent: event that triggered the reboot
 
47
        :type ievent: gozerbot.eventbase. EventBase
 
48
        :param fleet: the fleet of the bot
 
49
        :type fleet: gozerbot.fleet.Fleet
 
50
        :param partyline: partyline of the bot
 
51
        :type partyline: gozerbot.partyline.PartyLine
 
52
 
 
53
        .. literalinclude:: ../../gozerbot/reboot.py
 
54
            :pyobject: reboot_stateful
 
55
 
 
56
    """
 
57
    config.reload()
 
58
    session = {'bots': {}, 'name': bot.name, 'channel': ievent.channel, 'partyline': []}
 
59
 
 
60
    for i in fleet.bots:
 
61
        session['bots'].update(i._resumedata())
 
62
 
 
63
    session['partyline'] = partyline._resumedata()
 
64
    sessionfile = tempfile.mkstemp('-session', 'gozerbot-')[1]
 
65
    dump(session, open(sessionfile, 'w'))
 
66
    fleet.save()
 
67
    fleet.exit(jabber=True)
 
68
    os.execl(sys.argv[0], sys.argv[0], '-r', sessionfile)
 
69
 
 
70
## INIT SECTION
 
71
 
 
72
# no vars
 
73
 
 
74
## END INIT