|
1 #!/usr/bin/env python2.7 |
|
2 |
|
3 # Copyright (c) 2012 netzguerilla.net <iro@netzguerilla.net> |
|
4 # |
|
5 # This file is part of Iro. |
|
6 # |
|
7 # Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
8 # this software and associated documentation files (the "Software"), to deal in |
|
9 # the Software without restriction, including without limitation the rights to use, |
|
10 # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
|
11 # #Software, and to permit persons to whom the Software is furnished to do so, |
|
12 # subject to the following conditions: |
|
13 # |
|
14 # The above copyright notice and this permission notice shall be included in |
|
15 # all copies or substantial portions of the Software. |
|
16 # |
|
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
|
18 # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
|
19 # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
23 |
|
24 from twisted.python import log |
|
25 |
|
26 from sqlalchemy import create_engine, pool |
|
27 from sqlalchemy.exc import ArgumentError |
|
28 import sys,os |
|
29 |
|
30 import logging |
|
31 |
|
32 from iro.controller.pool import dbPool |
|
33 from iro import config, __version__, install |
|
34 |
|
35 observer = log.PythonLoggingObserver() |
|
36 observer.start() |
|
37 |
|
38 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s(%(processName)s)-%(levelname)s: %(message)s') |
|
39 |
|
40 import argparse |
|
41 |
|
42 parser = argparse.ArgumentParser(description='Iro installer.') |
|
43 parser.add_argument('-v', '--version', action='version', version="%s %s"%(os.path.basename(sys.argv[0]),__version__)) |
|
44 parser.add_argument('--install', action='store_true', |
|
45 help='will create the right database layout.') |
|
46 parser.add_argument('--update', action='store_true', |
|
47 help='will install all routes and providers.') |
|
48 args = parser.parse_args() |
|
49 |
|
50 if not install.checkConfig(): |
|
51 install.createSampleConfig() |
|
52 logging.info("Please edit iro.conf") |
|
53 sys.exit(1) |
|
54 |
|
55 config.init() |
|
56 |
|
57 try: |
|
58 engine = create_engine(config.main.dburl, |
|
59 poolclass = pool.SingletonThreadPool, pool_size=dbPool.maxthreads, ) |
|
60 except ArgumentError: |
|
61 logging.error("Can't connect to database") |
|
62 logging.info("Please edit iro.conf") |
|
63 sys.exit(1) |
|
64 |
|
65 |
|
66 if not install.checkDatabaseConnection(): |
|
67 logging.error("Can't connect to database") |
|
68 logging.info("Please edit iro.conf") |
|
69 sys.exit(1) |
|
70 |
|
71 if not install.checkDatabase(): |
|
72 logging.error("Database not in right format.") |
|
73 if args.install: |
|
74 install.createDatabase() |
|
75 logging.info("Database layout created.") |
|
76 else: |
|
77 logging.info("Please edit iro.conf and run %s --install"%os.path.basename(sys.argv[0])) |
|
78 sys.exit(1) |
|
79 |
|
80 routes = [ s for s in config.configParser.sections() if not s in ["main",]] |
|
81 ao = install.getAllRoutes(routes, False) |
|
82 for o in ao["orphand"]: |
|
83 logging.info("Offer(%s) is orphand (no route using this offer)."%o) |
|
84 if ao["added"]: |
|
85 if args.install or args.update: |
|
86 ao = install.getAllRoutes(routes,True) |
|
87 for a in ao["added"]: |
|
88 logging.info("Added Offer(%s)"%a) |
|
89 logging.info('Updated offerlist.') |
|
90 else: |
|
91 logging.warning('offerlist is not up-to-date.') |
|
92 logging.info("Please run %s --update"%os.path.basename(sys.argv[0])) |
|
93 sys.exit(1) |
|
94 |
|
95 logging.info("You can just start your iro server.") |
|
96 |
|
97 |