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