def main(): db.generate_mapping() tornado.options.parse_command_line() tornado.httpserver.HTTPServer(Application(), xheaders=True).listen(options.port) print("App started. Listenning on %d" % options.port) tornado.ioloop.IOLoop.instance().start()
def initialize(self): conf = ConfigParser.RawConfigParser(allow_no_value=True) conf.read('db.conf') db_usr = conf.get('mysql', 'user') db_pwd = conf.get('mysql', 'passwd') db.bind('mysql', host='localhost', user=db_usr, passwd=db_pwd, db='DOB') db.generate_mapping(check_tables=True, create_tables=True)
def main(argv): try: opts, args = getopt.getopt(argv, "", ["install", "init", "iwanttodropdatabase"]) except getopt.GetoptError: print("参数错误") sys.exit(2) for opt, val in opts: if opt == "--init": try: c.execute("create database %s" % config.db_name) c.execute("grant all privileges on %s.* to '%s'@'localhost' identified by '%s'" % (config.db_name, config.db_user, config.db_pass)) c.execute("flush privileges") c.close() m.commit() m.close() except: pass db.generate_mapping(create_tables=True) if not Node.get(id=1): Node(name=u'根节点', urlname='root', description=u'一切的根源').save() print("数据库表初始化成功") if opt == '--iwanttodropdatabase': key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": try: c.execute("drop database %s" % config.db_name) except Exception as e: print(e) finally: pass c.close() m.commit() m.close() print("已清空数据库!") else: print("已取消操作!") if opt == "--install": base_path = sys.path[0] try: print(requirements_path) os.system('sudo python %s/libs/pony/setup.py install' % base_path) os.system('sudo pip install -r %s/requirements.txt' % base_path) except e: print(e) finally: print("依赖安装成功")
def main(argv): try: opts, args = getopt.getopt(argv, "", ["install", "init", "iwanttodropdatabase"]) except getopt.GetoptError: print("参数错误") sys.exit(2) for opt, val in opts: if opt == "--init": # create database try: c.execute("create database %s" % config.db_name) c.execute( "grant all privileges on %s.* to '%s'@'localhost' identified by '%s'" % (config.db_name, config.db_user, config.db_pass)) c.execute("flush privileges") c.close() m.commit() m.close() except Exception: pass # create tables try: merge() except Exception: pass from models import db db.generate_mapping(create_tables=True) init_node() print("数据库表初始化成功") if opt == '--iwanttodropdatabase': key = raw_input( "你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": key = raw_input( "你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": key = raw_input( "你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": try: c.execute("drop database %s" % config.db_name) except Exception as e: print(e) finally: pass c.close() m.commit() m.close() print("已清空数据库!") else: print("已取消操作!")
def global_setup(): print("Global SetUp: Bind database and generate mapping") db_name = "test_db.db" db.bind(provider="sqlite", filename=db_name, create_db=True) db.generate_mapping(create_tables=True) yield print("Global TearDown: drop tables") db.drop_all_tables(with_all_data=True) db.disconnect()
def main(argv): try: opts, args = getopt.getopt(argv, "", ["install", "init", "iwanttodropdatabase"]) except getopt.GetoptError: print("参数错误") sys.exit(2) for opt, val in opts: if opt == "--init": try: c.execute("create database %s" % config.db_name) c.execute("grant all privileges on %s.* to '%s'@'localhost' identified by '%s'" % (config.db_name, config.db_user, config.db_pass)) c.execute("flush privileges") c.close() m.commit() m.close() except: pass try: merge() except: pass from models import db db.generate_mapping(create_tables=True) init_node() print("数据库表初始化成功") if opt == '--iwanttodropdatabase': key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n") if key == "yes i do": try: c.execute("drop database %s" % config.db_name) except Exception as e: print(e) finally: pass c.close() m.commit() m.close() print("已清空数据库!") else: print("已取消操作!")
from models import db from views import app if __name__ == '__main__': db.generate_mapping(create_tables=True) app.config.update(DEBUG=True) app.run()
# Script to read from database and output recipient of participant into .txt file from models import db, Participant from pony.orm import * db.bind('sqlite', 'participants.db', create_db=False) db.generate_mapping(create_tables=True) @db_session def recipient_to_txt(): query = Participant.get(name=input('Who do you need the recipient for? ex: Justin: ')) with open(query.name + '.txt', 'w') as file: file.write(query.name + ', you are giving to ' + query.giving_to + "!") recipient_to_txt()
# Setting up the option parser parser = OptionParser() parser.add_option("-l", "--level", dest="level", type="str") parser.add_option("-p", "--part", dest="part", type="str") parser.add_option("-t", "--type", dest="type", type="str") (options, args) = parser.parse_args() DBDIR = "data" INPUT_DB_NAME = "{}-{}-{}-complete.sqlite".format(options.level, options.part, options.type) OUTPUT_DB_NAME = "{}-{}-{}-clean.sqlite".format(options.level, options.part, options.type) INVALID_RECORD_MESSAGE = "Record Not Found Check Roll Number" db.bind('sqlite', os.path.join(DBDIR, INPUT_DB_NAME)) db.generate_mapping() cleandb.bind('sqlite', os.path.join(DBDIR, OUTPUT_DB_NAME), create_db=True) cleandb.generate_mapping(create_tables=True) with orm.db_session: pool = orm.select(c for c in Record if c.error == 0)[:] test = random.sample(pool, 90) + pool[-10:] def split_tables(soup): info, results = soup.find_all('table')[-2:] return info, results def parse_info(info_soup):
from flask import Flask from flask_graphql import GraphQLView from pony.flask import Pony from models import db from schema import schema app = Flask(__name__) Pony(app) app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) if __name__ == '__main__': db.bind(provider='postgres', user='******', port=5432, password='******', host='postgres', database='postgres') db.generate_mapping(create_tables=False) app.run(host="0.0.0.0", port=5000, debug=True)
all_identical = est_num[1:] == est_num[:-1] ranked = Counter(est_num).most_common(1) if ranked: result = str(ranked[0][0]) if not all_identical: result += " (!)" else: result = '-' return result if __name__ == '__main__': db.bind(provider=app.config['PONY']['provider'], user=app.config['PONY']['user'], password=app.config['PONY']['password'], host=os.environ.get('DATABASE_URL') or app.config['PONY']['host'], database=app.config['PONY']['database'], port=app.config['PONY']['port']) db.generate_mapping(create_tables=app.config['PONY']['create_tables']) app.run(host='0.0.0.0') if __name__ == 'app': db.bind(provider=app.config['PONY']['provider'], user=app.config['PONY']['user'], password=app.config['PONY']['password'], host=app.config['PONY']['host'], database=app.config['PONY']['database'], port=app.config['PONY']['port']) db.generate_mapping(create_tables=app.config['PONY']['create_tables']) app.run(host='0.0.0.0')
from flaskr import create_app from models import db as mysql_db from models import populate_db from rabbitmq import rabbitmq import env app = create_app() mysql_db.bind(**env.mysql_db_settings) mysql_db.generate_mapping(create_tables=True) if __name__ == "__main__": rabbitmq.connect() populate_db() app.run(debug=True, host='0.0.0.0', use_reloader=False)
def __init__(self, filename="example-addressbook.db"): db.generate_mapping(create_tables=True)
def run(*args, **kwargs): if not os.path.exists(DEPLOY_DIR): os.makedirs(DEPLOY_DIR) db.bind(DB_PROVIDER, **DB_CONFIG) db.generate_mapping(create_tables=True) return app.run(*args, **kwargs)