本文整理汇总了Python中server.main函数的典型用法代码示例。如果您正苦于以下问题:Python main函数的具体用法?Python main怎么用?Python main使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了main函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
for a in sys.argv:
if a == '-v':
print_version_and_exit()
if len(sys.argv) < 2 or sys.argv[1] == '-h':
print_usage_and_exit(0)
load_settings()
command = sys.argv[1]
arg_parser = make_arg_parser(command)
import relayevent
import sendmail
import server
import webhook
if command in ('startserver', 'stopserver'):
server.main(arg_parser, sys.argv[2:], command[:-6])
elif command == 'sendmail':
sendmail.main(arg_parser, sys.argv[2:])
elif command == 'relayevent':
relayevent.main(arg_parser, sys.argv[2:])
elif command == 'webhook':
webhook.main(arg_parser, sys.argv[2:])
else:
sys.stderr.write('unknown command "%s"\n\n' % command)
print_usage_and_exit(-1)
示例2: update
def update(self, clickPos, page, serverAddr=""):
"""
option 1: 1p vs 1p
option 2: connect
option 3: server
option 4: client
option 5: server address correct or not
"""
if self.rect.collidepoint(clickPos):
if self.option == 1:
pygame.quit()
mainScreen.main()
elif self.option == 2:
page[0] = 2
elif self.option == 3:
pygame.quit()
server.main()
elif self.option == 4:
page[0] = 3
elif self.option == 5:
ifCorrect = checkAddressFormat(serverAddr)
if ifCorrect:
pygame.quit()
client.main(serverAddr)
else:
page[0] = -1
示例3: main
def main():
print "Launched."
if not os.path.exists("dataSaved.csv"):
try:
f = open("dataSaved.csv", "w")
except IOError:
print "Unable to create CSV file. Exiting."
return
else:
f.close()
v = Verarbeitung()
v.loadData()
v.saveDataCSV()
t = Thread(target=application.realmain)
t.start()
print "Web server launched!"
try:
print "About to launch local server..."
server.main(v)
except KeyboardInterrupt:
pass
finally:
print "Exiting. Saving data."
v.saveData()
t._Thread__stop()
示例4: test_main
def test_main():
fakemodule = FakeSocketModule()
success = False
try:
server.main(fakemodule)
except AcceptCalledMultipleTimes:
success = True
assert success, "something went wrong"
示例5: start
def start():
for d in DIRS:
if not os.path.exists(os.getcwd() + '/' + d):
print 'This is not a drax project, directory "{}"'\
' is missing'.format(d)
return
parser = argparse.ArgumentParser()
parser.add_argument('--port', default=8888)
parser.add_argument('--auth_token', default=None)
args = parser.parse_args(sys.argv[2:])
server.main(os.getcwd(), auth_token=args.auth_token, port=args.port)
示例6: main
def main(argv=None):
program_name = os.path.basename(sys.argv[0])
program_version = __version__
program_build_date = "%s" % __updated__
program_version_string = '%%prog %s (%s)' % (program_version, program_build_date)
program_longdesc = '''''' # optional - give further explanation about what the program does
program_license = u"Copyright 2016 Magosányi Árpád \
Licensed under GNU GPL v3"
if argv is None:
argv = sys.argv[1:]
try:
parser = OptionParser(version=program_version_string, epilog=program_longdesc, description=program_license)
parser.add_option("-d", "--id", dest="keyid", type="string",
help="key id (mandatory!)")
parser.add_option("-m", "--module", dest="module", type="string",
help="pkcs11 module path")
parser.add_option("-p", "--pin", dest="pin", type="string",
help="pin [default: %default]")
parser.add_option("-M", "--mechanism", dest="mechanism",
help="HNAC/sign mechanism to use [default: %default]", type="string")
parser.add_option("-H", "--host", dest="host", type="string",
help="host [default: %default]")
parser.add_option("-P", "--port", dest="port", type="int",
help="port [default: %default]")
parser.add_option("-v", "--verbose", dest="verbose", action="count",
help="verbose to syslog. WARNING: logs PIN! [default: %default]")
parser.add_option("-e", "--environment", dest="environment", type="string",
help="append var=value to environment [default: %default]")
parser.set_defaults(module="/usr/lib/opensc-pkcs11.so", pin=u"0000", mechanism="SHA512-RSA-PKCS", host=u"localhost", port=9999, environment=None)
# process options
(opts, args) = parser.parse_args(argv)
if not opts.keyid:
print parser.format_help()
sys.exit(1)
if opts.environment:
(name,value) = opts.environment.split("=",2)
print (name,value)
os.environ[name]=value
syslog.openlog("cryptoserver", logoption=syslog.LOG_PID)
syslog.syslog("cryptoserver started at {0} {1}".format(opts.host,opts.port))
server.main(opts)
except:
excString = traceback.format_exc()
syslog.syslog(excString)
print excString
syslog.syslog("cryptoserver stopped at {0} {1}".format(opts.host,opts.port))
示例7: main
def main():
if len(sys.argv) != 2:
usage()
sys.exit(1)
if sys.argv[1] == 'serve':
server.main()
elif sys.argv[1] == 'crawl':
crawler.main()
else:
usage()
sys.exit(1)
示例8: test_main
def test_main():
fakemodule = FakeSocketModule()
sys.argv[1] = '-A'
sys.argv.append('myapp')
success = False
try:
server.main(fakemodule)
except AcceptCalledMultipleTimes:
success = True
pass
assert success, "Something went wrong"
示例9: startDaemon
def startDaemon():
curPath = os.path.dirname(os.path.realpath(__file__))
# Fork and die
pid = os.fork()
if pid == 0: #The first child
#os.chdir("/")
os.setsid()
os.umask(0)
pid2 = os.fork()
if pid2 == 0:
server.main()
#subprocess.call(["python",curPath + '/server.py'])
sys.exit()
示例10: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--host", default="0.0.0.0")
parser.add_argument("--port", type=int, default=1155)
parser.add_argument("--mongo_host", default="localhost")
parser.add_argument("--mongo_port", type=int, default=27017)
args = parser.parse_args()
try:
c = Connection()
c.disconnect()
except:
print "mongo connection not found"
exit(1)
server.main(args)
message = '''
示例11: main
def main():
desc = "A chat app built over TCP"
parser = argparse.ArgumentParser(description=desc)
group = parser.add_mutually_exclusive_group()
group.add_argument('-s', '--server', action='store_true', help='starts the server')
group.add_argument('-c', '--client', action='store_true', help='starts the client')
parser.add_argument('interface')
parser.add_argument('password')
args = parser.parse_args()
argv = [args.interface, args.password]
if args.server:
server.main(argv)
elif args.client:
client.main(argv)
else:
parser.print_help()
示例12: test_create_server_input
def test_create_server_input(self):
"""
Verify the input when creating servers is always correct.
"""
# This case should cast 8080 to an int
sys.argv = ['server.py']
sys.argv.append('-l 127.0.0.1')
sys.argv.append('-p 8080')
self.assertRaises(SystemExit, server.main)
# This case can't cast tasty tacos to integers.
# Make sure we get a parser error and invalid int warning
sys.argv[1] = '-l 127.0.0.1'
sys.argv[2] = '-p taco'
out_buff = StringIO()
sys.stderr = out_buff
try:
server.main()
except SystemExit, ex:
assert ex.message == 2
out_buff.seek(0)
assert 'invalid integer' in out_buff.read()
示例13: main
def main():
fileName = sys.argv[1]
mrm = master.main(fileName)
server.main(mrm, fileName)
client.main(mrm, fileName)
示例14:
#!/usr/bin/env python
# _______ _______ _______ _______ __ __ ___ _______ _______
# | || _ || || || | | || | | || |
# | || |_| ||_ _|| ___|| | | || | | || ___|
# | || | | | | | __ | |_| || | | || |___
# | _|| | | | | || || || | | _|| ___|
# | |_ | _ | | | | |_| || || | | |_ | |___
# |_______||__| |__| |___| |_______||_______||___| |_______||_______|
# --------- A Website For the Purchase of Excellent Things ------------
#
# Coded by Josh Thomas <[email protected]>
# Currated & Owned by Catherine Kern <[email protected]>
#
import server as server
import os, sys
__author__ = "Josh Thomas"
__credits__ = ["Josh Thomas", "Catherine Kern"]
__license__ = "GPL"
__version__ = "0.1"
__maintainer__ = "Josh Thomas"
__contact__ = "http://github.com/lambdanaut"
__email__ = "[email protected]"
__status__ = "Development"
if __name__ == "__main__": server.main()
示例15: len
#!/usr/bin/env python
import os
import sys
if len(sys.argv) != (1 + 1):
raise RuntimeError(
'init.py should be ran with one arg DGRAM or SOCK_STREAM'
)
#host = ''
settings = {
'host' : '127.0.0.1',
'port' : 3444,
'mode' : sys.argv[1]
}
if os.fork():
import server
server.main(settings)
else:
import client
client.main(settings)