wrap bot.py in a main() function to be import-safe

This commit is contained in:
Ryan Hitchman 2015-01-21 23:16:27 -08:00
parent 62fbe6e237
commit 921b986683
1 changed files with 35 additions and 31 deletions

12
bot.py
View File

@ -6,10 +6,6 @@ import sys
import traceback
import time
sys.path += ['plugins'] # so 'import hook' works without duplication
sys.path += ['lib']
os.chdir(sys.path[0] or '.') # do stuff relative to the install directory
class Bot(object):
def __init__(self):
@ -18,6 +14,11 @@ class Bot(object):
if not os.path.exists(self.persist_dir):
os.mkdir(self.persist_dir)
def main():
sys.path += ['plugins'] # so 'import hook' works without duplication
sys.path += ['lib']
os.chdir(sys.path[0] or '.') # do stuff relative to the install directory
bot = Bot()
print 'Loading plugins'
@ -52,3 +53,6 @@ while True:
pass
while all(conn.out.empty() for conn in bot.conns.itervalues()):
time.sleep(.1)
if __name__ == '__main__':
main()