|
1 #!/usr/bin/env python2.7 |
|
2 from twisted.python import log |
|
3 |
|
4 from sqlalchemy import create_engine, pool |
|
5 from sqlalchemy.exc import ArgumentError |
|
6 import sys |
|
7 |
|
8 import logging |
|
9 |
|
10 from iro.controller.pool import dbPool |
|
11 from iro import config, __version__, install |
|
12 |
|
13 observer = log.PythonLoggingObserver() |
|
14 observer.start() |
|
15 |
|
16 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s(%(processName)s)-%(levelname)s: %(message)s') |
|
17 |
|
18 import argparse |
|
19 |
|
20 parser = argparse.ArgumentParser(description='Iro main routine.', version=__version__) |
|
21 parser.add_argument('--install', action='store_true', |
|
22 help='will create the right database layout.') |
|
23 parser.add_argument('--update', action='store_true', |
|
24 help='will install all routes and providers.') |
|
25 args = parser.parse_args() |
|
26 |
|
27 if not install.checkConfig(): |
|
28 install.createSampleConfig() |
|
29 logging.info("Please edit iro.conf") |
|
30 sys.exit(1) |
|
31 |
|
32 config.init() |
|
33 |
|
34 try: |
|
35 engine = create_engine(config.main.dburl, |
|
36 poolclass = pool.SingletonThreadPool, pool_size=dbPool.maxthreads, ) |
|
37 except ArgumentError: |
|
38 logging.error("Can't connect to database") |
|
39 logging.info("Please edit iro.conf") |
|
40 sys.exit(1) |
|
41 |
|
42 |
|
43 if not install.checkDatabaseConnection(): |
|
44 logging.error("Can't connect to database") |
|
45 logging.info("Please edit iro.conf") |
|
46 sys.exit(1) |
|
47 |
|
48 if not install.checkDatabase(): |
|
49 logging.error("Database not in right format.") |
|
50 if args.install: |
|
51 install.createDatabase() |
|
52 logging.info("Database layout created.") |
|
53 logging.info("Now you can run "+sys.argv[0]) |
|
54 else: |
|
55 logging.info("Please edit iro.conf and run %s --install"%sys.argv[0]) |
|
56 sys.exit(1) |
|
57 |
|
58 routes = [ s for s in config.configParser.sections() if not s in ["main",]] |
|
59 ao = install.getAllRoutes(routes, False) |
|
60 for o in ao["orphand"]: |
|
61 logging.info("Offer(%s) is orphand (no route using this offer)."%o) |
|
62 if ao["added"]: |
|
63 if args.install or args.update: |
|
64 ao = install.getAllRoutes(routes,True) |
|
65 for a in ao["added"]: |
|
66 logging.info("Added Offer(%s)"%a) |
|
67 logging.info('Updated offerlist.') |
|
68 logging.info("Now you can run "+sys.argv[0]) |
|
69 else: |
|
70 logging.warning('offerlist is not up-to-date.') |
|
71 logging.info("Please run %s --update"%sys.argv[0]) |
|
72 sys.exit(1) |
|
73 |
|
74 if args.install or args.update: |
|
75 logging.info('Nothing todo for me.') |
|
76 logging.info("Now you can run "+sys.argv[0]) |
|
77 sys.exit(1) |
|
78 |
|
79 logging.info("You can just start your iro server.") |
|
80 |
|
81 #start via cmdline |
|
82 #root = resource.Resource() |
|
83 #root = xmlrpc.appendResource(root) |
|
84 |
|
85 #v2 = resource.Resource() |
|
86 #v2 = xmlrpc.appendResource(root) |
|
87 #root.putChild('2.0', v2) |
|
88 |
|
89 #reactor.callLater(0.2, config.readConfig) |
|
90 #main.runReactor(reactor, engine, config.main.port, root) |