예제 #1
0
def main():
    '''Separate main for unittesting and calling from other modules'''   
    def getstage():
        '''Determine whether prod or dev'''
        stage = 'dev'
        if len(sys.argv) > 1: 
            if sys.argv[1] == 'prod':
                stage = 'prod'
        return stage
    stage = getstage()    
    
    try:
        tornado.options.parse_command_line()
        config = ConfigObj('imeveryone.conf')
        # Set up logging
        logging.basicConfig(level=logging.DEBUG, filename=config['application'][stage]['logfile'])
        # Start MongoDB server and client.
        database = Database(config,stage)
        database.start()
        database.dbclient()
        # Create our avatar list
        def getavatars(config):
            '''Return names of avatars to use'''
            avatars = []
            files = os.listdir(config['posting']['avatardir'])
            for avoidavatar in config['posting']['avatarignore']:
                if avoidavatar in files:
                    files.remove(avoidavatar)
            for file in files:
                avatars.append(file.replace('.png',''))
            return avatars
        config['posting']['avatars'] = getavatars(config)
        # Start web app
        application = Application(config,database=database,stage=stage)
        http_server = tornado.httpserver.HTTPServer(application)
        port, ip = config['application'][stage].as_int('port'),config['application'][stage]['ip']
        http_server.listen(port,address=ip)
        print('_'*80) 
        print('Web server running on http://'+str(ip)+':'+str(port)+' .') 
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        print 'Server cancelled'
        sys.exit(1)
예제 #2
0
'''Quickly drop DB - eg, ./quickdb.py dev'''
from database import Database
from configobj import ConfigObj
import usermessages
import time
import sys
import pickle
import os

config = ConfigObj('imeveryone.conf')
stage = 'dev'#sys.argv[1]
db = Database(config,stage=stage)


#db.start()
db.dbclient()
db.connection.messages.find_one()
db.connection.messages.find_one({'_id':1})

print('_')*80
print('_')*80
print('_')*80
print('_')*80
print('Ready')
#print('''db.connection.messages.drop()''')

def getmessage(id):
    '''Get a dict from DB and return a message object'''
    dbdict = db.connection.messages.find_one({'_id':id})
    return usermessages.Message(dehydrated=dbdict)