import os from paste.script import command from paste.deploy import appconfig def get_config(self, config_spec): section = self.options.section_name if section is None: if '#' in config_spec: config_spec, section = config_spec.split('#', 1) else: section = 'main' if not ':' in section: plain_section = section section = 'app:'+section else: plain_section = section.split(':', 1)[0] if not config_spec.startswith('config:'): config_spec = 'config:' + config_spec if plain_section != 'main': config_spec += '#' + plain_section config_file = config_spec[len('config:'):].split('#', 1)[0] config_file = os.path.join(os.getcwd(), config_file) self.logging_file_config(config_file) conf = appconfig(config_spec, relative_to=os.getcwd()) return conf class OpenIDCommand(command.Command): max_args = 1 min_args = 1 usage = "CONFIG_FILE" summary = "Setup Quoins OpenID tables" group_name = "Quoins" parser = command.Command.standard_parser(verbose=True) parser.add_option('--name', action='store', dest='section_name', default=None, help='The name of the section to set up (default: app:main)') def command(self): config_file = self.args[0] if self.verbose: print "Using config file: %s" % config_file conf = get_config(self, config_file) from quoins.controllers import get_oid_connection from openid.store.sqlstore import MySQLStore import MySQLdb conn = get_oid_connection(conf) store = MySQLStore(conn) try: store.createTables() except MySQLdb.OperationalError, message: errorcode = message[0] if errorcode == 1050: print 'ok' else: raise class BlogCommand(command.Command): max_args = 1 min_args = 1 usage = "CONFIG_FILE" summary = "Create a new Quoins Blog" group_name = "Quoins" parser = command.Command.standard_parser(verbose=True) parser.add_option('--name', action='store', dest='section_name', default=None, help='The name of the section to set up (default: app:main)') def command(self): config_file = self.args[0] if self.verbose: print "Using config file: %s" % config_file conf = get_config(self, config_file) from model import Blog, DBSession, init_model from sqlalchemy import create_engine init_model(create_engine(conf.get('sqlalchemy.url'))) title = raw_input("Blog title: ") subtitle = raw_input("Blog subtitle: ") comments = raw_input("Allow comments by default? (y/n) ") if comments.strip().lower()=='y': comments = True else: comments = False b = Blog() b.title = title.strip() if subtitle: b.subtitle = subtitle.strip() b.allow_comments = comments DBSession.add(b) DBSession.flush()