Skip to content
Newer
Older
100644 139 lines (101 sloc) 4.09 KB
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 # Copyright Bernardo Heynemann <heynemann@gmail.com>
5
6 # Licensed under the Open Software License ("OSL") v. 3.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9
10 # http://www.opensource.org/licenses/osl-3.0.php
11
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 import sys
19 import os
20 from os.path import abspath, dirname, join
21 import optparse
22 import urllib
23
24 import Queue
25
26 import skink.lib
27 from ion import Server, Settings
28 from simple_db_migrate.cli import CLI
29 from simple_db_migrate.core import InPlaceConfig
30 from simple_db_migrate.main import Main
31
32 import cherrypy
33
34 from skink.src.services.plugins.builder import *
35 from skink.src.services.plugins.monitor import *
19b4c5e @heynemann New coverage plugin and on_failed event for plugins
authored Oct 4, 2010
36 from skink.src.plugins.base import *
e79fc6a @heynemann Plugin infrastructure
authored Jun 16, 2010
37 from skink.src.plugins import *
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
38
02d9d3b @heynemann Patch for allowing sending sighup and specifying log files
authored Mar 4, 2011
39 import signal
40
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
41 def main():
42 """ Main function - parses args and runs action """
43 parser = optparse.OptionParser(usage="%prog run or type %prog -h (--help) for help", description=__doc__, version="%prog")
44
45 (options, args) = parser.parse_args()
19b4c5e @heynemann New coverage plugin and on_failed event for plugins
authored Oct 4, 2010
46
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
47 if not args:
48 print "Invalid action. for help type skink_console.py -h (--help) for help"
49 sys.exit(0)
19b4c5e @heynemann New coverage plugin and on_failed event for plugins
authored Oct 4, 2010
50
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
51 action = args[0]
19b4c5e @heynemann New coverage plugin and on_failed event for plugins
authored Oct 4, 2010
52
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
53 if action.lower() == "run":
54 run_skink_server()
55
56 if action.lower() == "createdb":
57 run_migrations(drop_db=True)
58
59 if action.lower() == "upgradedb":
60 run_migrations(drop_db=False)
61
62 sys.exit(0)
63
02d9d3b @heynemann Patch for allowing sending sighup and specifying log files
authored Mar 4, 2011
64 def SigHUPHandler(signum, frame):
65 cherrypy.log('signal SIGHUP received','SIGNAL')
66 cherrypy.log.reopen_files()
67 return
68
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
69 def on_user_authentication_failed_handler(data):
70 raise cherrypy.HTTPRedirect("/authentication/%s" % urllib.quote(cherrypy.url(cherrypy.request.path_info)).replace("/", "@@"))
71
72 def run_skink_server():
02d9d3b @heynemann Patch for allowing sending sighup and specifying log files
authored Mar 4, 2011
73 signal.signal( signal.SIGHUP, SigHUPHandler )
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
74 root_dir = abspath(dirname(__file__))
75 server = Server(root_dir=root_dir)
76 server.build_dir = join(root_dir, "ci_tmp")
77
78 server.subscribe('on_user_authentication_failed', on_user_authentication_failed_handler)
79
80 server.context.current_project = None
81 server.context.current_command = None
82 server.context.current_log = ""
83 server.context.build_queue = Queue.deque()
84 server.context.projects_being_built = Queue.deque()
19b4c5e @heynemann New coverage plugin and on_failed event for plugins
authored Oct 4, 2010
85
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
86 builder = BuilderPlugin(cherrypy.engine, server)
87 builder.subscribe()
88
89 monitor = MonitorPlugin(cherrypy.engine, server)
90 monitor.subscribe()
91
3cffb6e @bardusco made possible to configure PID file on config.ini
bardusco authored Mar 4, 2011
92 settings = Settings(root_dir)
93 settings.load("config.ini")
94
95 pid_file = settings.Ion.pid_file
96 pid = cherrypy.process.plugins.PIDFile(cherrypy.engine, pid_file)
62e2d8f @bardusco Added PID file to /var/run/skink.pid
bardusco authored Mar 4, 2011
97 pid.subscribe()
98
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
99 try:
e79fc6a @heynemann Plugin infrastructure
authored Jun 16, 2010
100 server.start("config.ini", non_block=True)
101 for plugin in SkinkPlugin.all():
102 config = server.context.settings.config
103 if config.has_section(plugin.__name__) and \
104 config.get(plugin.__name__, "enabled") == "True":
105 cherrypy.log('Plugin %s enabled!' % plugin.__name__,
106 'PLUGINS')
107 instance = plugin(server)
19b4c5e @heynemann New coverage plugin and on_failed event for plugins
authored Oct 4, 2010
108
e79fc6a @heynemann Plugin infrastructure
authored Jun 16, 2010
109 cherrypy.engine.block()
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
110 except KeyboardInterrupt:
111 server.stop()
112
113 def run_migrations(drop_db=False):
114 root_dir = abspath(dirname(__file__))
19b4c5e @heynemann New coverage plugin and on_failed event for plugins
authored Oct 4, 2010
115
526525f SKINK Release 2.0
Bernardo Heynemann authored Apr 14, 2010
116 settings = Settings(root_dir)
117 settings.load("config.ini")
118
119 protocol = settings.Db.protocol
120 username = settings.Db.user
121 password = settings.Db.password
122 host = settings.Db.host
123 port = int(settings.Db.port)
124 database = settings.Db.database
125
126 config = InPlaceConfig(db_host=host, db_user=username, db_password=password, db_name=database, migrations_dir=join(root_dir, "db"))
127
128 config.put("schema_version", None)
129 config.put("show_sql", False)
130 config.put("show_sql_only", False)
131 config.put("new_migration", None)
132
133 config.put("drop_db_first", drop_db)
134
135 Main(config).execute()
136
137 if __name__ == "__main__":
138 main()
Something went wrong with that request. Please try again.