Exemple #1
0
def main():
    if len(sys.argv) > 1:
        try:
            socket = int(sys.argv[1])
        except:
            socket = sys.argv[1]
    else:
        socket = "/tmp/mahjong.sock"

    if hasattr(settings, 'EMAILSERVER'):
        qm = QueMail.get_instance()
        qm.init(settings.EMAILSERVER, settings.EMAILUSER, settings.EMAILPASSWORD, settings.EMAILPORT, True)
        qm.start()

    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(Application(), max_buffer_size=24*1024**3)
    if isinstance(socket, int):
        http_server.add_sockets(tornado.netutil.bind_sockets(socket))
    else:
        http_server.add_socket(tornado.netutil.bind_unix_socket(socket))

    signal.signal(signal.SIGINT, sigint_handler)

    tornado.ioloop.PeriodicCallback(periodicCleanup, 60 * 60 * 1000).start() # run periodicCleanup once an hour
    # start it up
    tornado.ioloop.IOLoop.instance().start()

    if qm is not None:
        qm.end()
Exemple #2
0
def sendEmail(toaddr, subject, body):
    fromaddr = settings.EMAILFROM

    qm = QueMail.get_instance()
    qm.send(
        Email(subject=subject,
              text=body,
              adr_to=toaddr,
              adr_from=fromaddr,
              mime_type='html'))
Exemple #3
0
def init():
    qm = QueMail.get_instance()
    qm.init(settings.EMAILSERVER, settings.EMAILUSER, settings.EMAILPASSWORD,
            settings.EMAILPORT, settings.EMAILUSETLS)
    qm.start()
    return qm
Exemple #4
0
def sendEmail(toaddr, subject, body):
	fromaddr = settings.EMAILFROM

	qm = QueMail.get_instance()
	qm.send(Email(subject=subject, text=body, adr_to=toaddr, adr_from=fromaddr, mime_type='html'))
Exemple #5
0
def main():
    default_socket = "/tmp/mahjong.sock"
    socket = None
    force = False
    i = 1
    errors = []
    usage = [
        "usage: {0} [-f|--force] [tornado-options] [Port|Socket]",
        "positional arguments:",
        "  Port|Socket   Port number or unix socket to listen on",
        "                (default: {0})".format(default_socket),
        "",
        "optional arguments:",
        "  -f|--force    Force database schema updates without prompting",
        "                (default: {0})".format(force),
        "  -h|--help     show help information and exit",
        "",
        "tornado options:",
    ]
    usage = __doc__ + "\n" + "\n".join(usage)
    while i < len(sys.argv):
        if sys.argv[i].isdigit():
            if socket is None:
                socket = int(sys.argv[i])
            else:
                errors.append('Multiple port or socket arguments specified '
                              '"{0}"'.format(sys.argv[i]))
        elif sys.argv[i].startswith('-'):
            if sys.argv[i] in ['-f', '--force']:
                force = True
                del sys.argv[i]
                continue
            elif sys.argv[i] in ['-h', '--help']:
                print(usage)  # and don't exit so tornado help will print
                if sys.argv[i] == '-h':
                    sys.argv[i] = '--help'  # tornado doesn't accept -h option
            else:
                pass  # Leave tornado options in place for later parsing
        else:
            if socket is None:
                socket = sys.argv[i]
            else:
                errors.append('Multiple port or socket arguments specified '
                              '"{0}"'.format(sys.argv[i]))
        i += 1

    if socket is None:
        socket = default_socket

    tornado.options.parse_command_line()
    if errors:
        print("\n  ".join(["Errors:"] + errors))
        sys.exit(-1)

    if hasattr(settings, 'EMAILSERVER'):
        qm = QueMail.get_instance()
        qm.init(settings.EMAILSERVER, settings.EMAILUSER,
                settings.EMAILPASSWORD, settings.EMAILPORT,
                settings.EMAILUSETLS)
        qm.start()

    http_server = tornado.httpserver.HTTPServer(Application(force=force),
                                                max_buffer_size=24 * 1024**3)
    if isinstance(socket, int):
        http_server.add_sockets(tornado.netutil.bind_sockets(socket))
    else:
        http_server.add_socket(
            tornado.netutil.bind_unix_socket(socket,
                                             mode=stat.S_IRUSR | stat.S_IWUSR
                                             | stat.S_IRGRP | stat.S_IWGRP
                                             | stat.S_IROTH | stat.S_IWOTH))

    signal.signal(signal.SIGINT, sigint_handler)

    tornado.ioloop.PeriodicCallback(
        periodicCleanup,
        60 * 60 * 1000).start()  # run periodicCleanup once an hour
    # start up web server
    tornado.ioloop.IOLoop.instance().start()

    if qm is not None:
        qm.end()