]>
jfr.im git - z_archive/Ophion.git/blob - util.py
1 from traceback
import print_exc
9 def noaccess(bot
, nick
, chcmd
=False):
11 bot
.msg(nick
, "You don't have enough access to do that.")
13 bot
.msg(nick
, "No such command or not enough access.")
15 # except Exception as e:
16 # print_exc(None, cache.excfile)
17 # bot.msg(fromnick, "An error occurred, sorry! Try again later.")
18 # cache.mainBot.cmsg('warn', "EXCEPTION! %r Caused by <%s> %s" % (e, fromnick, line))
19 def loadmod(modf
, cache
, reloading
=False):
20 # return: 0=success, 1=import error, 2=already loaded, 3=reload() failed
21 if modf
in cache
.modules
:
23 elif modf
in cache
.unmodules
:
24 mod
= cache
.unmodules
[modf
]
27 except Exception as e
:
29 print_exc(None, cache
.excfile
)
33 print "not mod.init(cache)"
34 cache
.excfile
.write("%s refused init - returned True\n" % (modf
))
36 except Exception as e
:
38 print_exc(None, cache
.excfile
)
40 del cache
.unmodules
[modf
]
43 mod
= __import__(modf
)
44 except Exception as e
:
46 print_exc(None, cache
.excfile
)
50 cache
.excfile
.write("%s refused init - returned True\n" % (modf
))
51 except Exception as e
:
53 print_exc(None, cache
.excfile
)
55 cache
.modules
[modf
] = mod
57 def unloadmod(modf
, cache
, reloading
=False):
58 # return: 0=success, 1=refused unload, 2=not loaded
59 if modf
not in cache
.modules
:
63 ret
= cache
.modules
[modf
].deinit(cache
, reloading
)
64 except Exception as e
:
65 print_exc(None, cache
.excfile
)
70 cache
.unmodules
[modf
] = cache
.modules
[modf
]
71 del cache
.modules
[modf
]
73 def reloadmod(modf
, cache
):
74 # return: 0 = success; 1,2=unload error; 3,4,5=load error
75 unloadret
= unloadmod(modf
, cache
, True)
76 if unloadret
!= 0: return unloadret
77 loadret
= loadmod(modf
, cache
, True)
78 if loadret
!= 0: return loadret
+2