def main(): with app.app_context(): if daconfig.get('use alembic', True): packagedir = pkg_resources.resource_filename( pkg_resources.Requirement.parse('docassemble.webapp'), 'docassemble/webapp') if not os.path.isdir(packagedir): sys.exit("path for running alembic could not be found") from alembic.config import Config from alembic import command alembic_cfg = Config(os.path.join(packagedir, 'alembic.ini')) alembic_cfg.set_main_option("sqlalchemy.url", alchemy_connection_string()) alembic_cfg.set_main_option("script_location", os.path.join(packagedir, 'alembic')) if not db.engine.has_table(dbtableprefix + 'alembic_version'): command.stamp(alembic_cfg, "head") if db.engine.has_table(dbtableprefix + 'user'): command.upgrade(alembic_cfg, "head") #db.drop_all() try: sys.stderr.write("Trying to create tables\n") db.create_all() except: sys.stderr.write( "Error trying to create tables; trying a second time.\n") try: db.create_all() except: sys.stderr.write( "Error trying to create tables; trying a third time.\n") db.create_all() populate_tables() db.engine.dispose()
def main(): #import docassemble.webapp.database start_time = time.time() from docassemble.webapp.app_object import app with app.app_context(): from docassemble.webapp.db_object import db from docassemble.webapp.packages.models import Package from sqlalchemy import select #app.config['SQLALCHEMY_DATABASE_URI'] = docassemble.webapp.database.alchemy_connection_string() if mode == 'initialize': sys.stderr.write("update: updating with mode initialize after " + str(time.time() - start_time) + " seconds\n") update_versions(start_time=start_time) any_package = db.session.execute( select(Package).filter_by(active=True)).first() if any_package is None: add_dependencies(1, start_time=start_time) update_versions(start_time=start_time) check_for_updates(start_time=start_time, invalidate_cache=False) remove_inactive_hosts(start_time=start_time) else: sys.stderr.write( "update: updating with mode check_for_updates after " + str(time.time() - start_time) + " seconds\n") check_for_updates(start_time=start_time) if USING_SUPERVISOR: SUPERVISORCTL = daconfig.get('supervisorctl', 'supervisorctl') container_role = ':' + os.environ.get('CONTAINERROLE', '') + ':' if re.search(r':(web|celery|all):', container_role): sys.stderr.write("update: sending reset signal after " + str(time.time() - start_time) + " seconds\n") args = [ SUPERVISORCTL, '-s', 'http://localhost:9001', 'start', 'reset' ] subprocess.run(args, check=False) else: sys.stderr.write( "update: not sending reset signal because not web or celery after " + str(time.time() - start_time) + " seconds\n") else: sys.stderr.write("update: touched wsgi file after " + str(time.time() - start_time) + " seconds\n") wsgi_file = daconfig.get( 'webapp', '/usr/share/docassemble/webapp/docassemble.wsgi') if os.path.isfile(wsgi_file): with open(wsgi_file, 'a', encoding='utf-8'): os.utime(wsgi_file, None) db.engine.dispose() sys.exit(0)
def main(): with app.app_context(): if daconfig.get('use alembic', True): packagedir = pkg_resources.resource_filename(pkg_resources.Requirement.parse('docassemble.webapp'), 'docassemble/webapp') if not os.path.isdir(packagedir): sys.exit("path for running alembic could not be found") from alembic.config import Config from alembic import command alembic_cfg = Config(os.path.join(packagedir, 'alembic.ini')) alembic_cfg.set_main_option("sqlalchemy.url", alchemy_connection_string()) alembic_cfg.set_main_option("script_location", os.path.join(packagedir, 'alembic')) if not db.engine.has_table(dbtableprefix + 'alembic_version'): command.stamp(alembic_cfg, "head") if db.engine.has_table(dbtableprefix + 'user'): command.upgrade(alembic_cfg, "head") #db.drop_all() db.create_all() populate_tables() db.engine.dispose()
if len(a) == 2: #sys.stderr.write("Found " + a[0] + " which was " + a[1] + "\n") results[a[0]] = a[1] for key in ['Name', 'Home-page', 'Version']: if key not in results: results[key] = None sys.stderr.write("get_pip_info: returning after " + str(time.time() - start_time) + " seconds") return results if __name__ == "__main__": #import docassemble.webapp.database start_time = time.time() from docassemble.webapp.app_object import app with app.app_context(): from docassemble.webapp.db_object import db from docassemble.webapp.packages.models import Package, Install, PackageAuth from docassemble.webapp.daredis import r #app.config['SQLALCHEMY_DATABASE_URI'] = docassemble.webapp.database.alchemy_connection_string() if mode == 'initialize': sys.stderr.write("updating with mode initialize after " + str(time.time() - start_time) + " seconds\n") update_versions(start_time=start_time) any_package = Package.query.filter_by(active=True).first() if any_package is None: add_dependencies(1, start_time=start_time) update_versions(start_time=start_time) check_for_updates(doing_startup=True, start_time=start_time, invalidate_cache=False)
def main(): from docassemble.webapp.database import dbprefix if dbprefix.startswith('postgresql') and not daconfig.get( 'force text to varchar upgrade', False): do_varchar_upgrade = False else: do_varchar_upgrade = True with app.app_context(): if daconfig.get('use alembic', True): if do_varchar_upgrade: changed = False if db.engine.has_table(dbtableprefix + 'userdict'): db.session.query(UserDict).filter( db.func.length(UserDict.filename) > 255).delete( synchronize_session=False) changed = True if db.engine.has_table(dbtableprefix + 'userdictkeys'): db.session.query(UserDictKeys).filter( db.func.length(UserDictKeys.filename) > 255).delete( synchronize_session=False) changed = True if db.engine.has_table(dbtableprefix + 'chatlog'): db.session.query(ChatLog).filter( db.func.length(ChatLog.filename) > 255).delete( synchronize_session=False) changed = True if db.engine.has_table(dbtableprefix + 'uploads'): db.session.query(Uploads).filter( db.func.length(Uploads.filename) > 255).delete( synchronize_session=False) db.session.query(Uploads).filter( db.func.length(Uploads.yamlfile) > 255).delete( synchronize_session=False) changed = True if db.engine.has_table(dbtableprefix + 'objectstorage'): db.session.query(ObjectStorage).filter( db.func.length(ObjectStorage.key) > 1024).delete( synchronize_session=False) changed = True if db.engine.has_table(dbtableprefix + 'speaklist'): db.session.query(SpeakList).filter( db.func.length(SpeakList.filename) > 255).delete( synchronize_session=False) changed = True if db.engine.has_table(dbtableprefix + 'shortener'): db.session.query(Shortener).filter( db.func.length(Shortener.filename) > 255).delete( synchronize_session=False) db.session.query(Shortener).filter( db.func.length(Shortener.key) > 255).delete( synchronize_session=False) changed = True if db.engine.has_table(dbtableprefix + 'machinelearning'): db.session.query(MachineLearning).filter( db.func.length(MachineLearning.key) > 1024).delete( synchronize_session=False) db.session.query(MachineLearning).filter( db.func.length(MachineLearning.group_id) > 1024 ).delete(synchronize_session=False) changed = True if db.engine.has_table(dbtableprefix + 'globalobjectstorage'): db.session.query(GlobalObjectStorage).filter( db.func.length(GlobalObjectStorage.key) > 1024).delete( synchronize_session=False) changed = True if changed: db.session.commit() packagedir = pkg_resources.resource_filename( pkg_resources.Requirement.parse('docassemble.webapp'), 'docassemble/webapp') if not os.path.isdir(packagedir): sys.exit("path for running alembic could not be found") from alembic.config import Config from alembic import command alembic_cfg = Config(os.path.join(packagedir, 'alembic.ini')) alembic_cfg.set_main_option("sqlalchemy.url", alchemy_connection_string()) alembic_cfg.set_main_option("script_location", os.path.join(packagedir, 'alembic')) if not db.engine.has_table(dbtableprefix + 'alembic_version'): start_time = time.time() sys.stderr.write("Creating alembic stamp\n") command.stamp(alembic_cfg, "head") sys.stderr.write("Done creating alembic stamp after " + str(time.time() - start_time) + " seconds\n") if db.engine.has_table(dbtableprefix + 'user'): start_time = time.time() sys.stderr.write("Creating alembic stamp\n") sys.stderr.write("Running alembic upgrade\n") command.upgrade(alembic_cfg, "head") sys.stderr.write("Done running alembic upgrade after " + str(time.time() - start_time) + " seconds\n") #db.drop_all() start_time = time.time() try: sys.stderr.write("Trying to create tables\n") db.create_all() except: sys.stderr.write( "Error trying to create tables; trying a second time.\n") try: db.create_all() except: sys.stderr.write( "Error trying to create tables; trying a third time.\n") db.create_all() sys.stderr.write("Finished creating tables after " + str(time.time() - start_time) + " seconds.\n") populate_tables() db.engine.dispose()
import os import sys import re if __name__ == "__main__": import docassemble.base.config docassemble.base.config.load(arguments=sys.argv) from docassemble.webapp.app_object import app from docassemble.webapp.db_object import db from docassemble.webapp.core.models import Supervisors def main(): from docassemble.base.config import hostname supervisor_url = os.environ.get('SUPERVISOR_SERVER_URL', None) if supervisor_url: Supervisors.query.filter_by(hostname=hostname).delete() db.session.commit() new_entry = Supervisors(hostname=hostname, url="http://" + hostname + ":9001", role=os.environ.get('CONTAINERROLE', None)) db.session.add(new_entry) db.session.commit() if __name__ == "__main__": #import docassemble.webapp.database with app.app_context(): #app.config['SQLALCHEMY_DATABASE_URI'] = docassemble.webapp.database.alchemy_connection_string() main() db.engine.dispose()
def main(): logmessage("create_tables.main: starting") start_time = time.time() if dbprefix.startswith('postgresql') and not daconfig.get( 'force text to varchar upgrade', False): do_varchar_upgrade = False else: do_varchar_upgrade = True with app.app_context(): logmessage("create_tables.main: inside app context after " + str(time.time() - start_time) + " seconds.") if daconfig.get('use alembic', True): logmessage("create_tables.main: running alembic after " + str(time.time() - start_time) + " seconds.") insp = inspect(db.engine) if do_varchar_upgrade: changed = False if insp.has_table(dbtableprefix + 'userdict'): db.session.execute( delete(UserDict).where( db.func.length(UserDict.filename) > 255). execution_options(synchronize_session=False)) changed = True if insp.has_table(dbtableprefix + 'userdictkeys'): db.session.execute( delete(UserDictKeys).where( db.func.length(UserDictKeys.filename) > 255). execution_options(synchronize_session=False)) changed = True if insp.has_table(dbtableprefix + 'chatlog'): db.session.execute( delete(ChatLog).where( db.func.length(ChatLog.filename) > 255). execution_options(synchronize_session=False)) changed = True if insp.has_table(dbtableprefix + 'uploads'): db.session.execute( delete(Uploads).where( db.func.length(Uploads.filename) > 255). execution_options(synchronize_session=False)) db.session.execute( delete(Uploads).where( db.func.length(Uploads.yamlfile) > 255). execution_options(synchronize_session=False)) changed = True if insp.has_table(dbtableprefix + 'objectstorage'): db.session.execute( delete(ObjectStorage).where( db.func.length(ObjectStorage.key) > 1024). execution_options(synchronize_session=False)) changed = True if insp.has_table(dbtableprefix + 'speaklist'): db.session.execute( delete(SpeakList).where( db.func.length(SpeakList.filename) > 255). execution_options(synchronize_session=False)) changed = True if insp.has_table(dbtableprefix + 'shortener'): db.session.execute( delete(Shortener).where( db.func.length(Shortener.filename) > 255). execution_options(synchronize_session=False)) db.session.execute( delete(Shortener).where( db.func.length(Shortener.key) > 255). execution_options(synchronize_session=False)) changed = True if insp.has_table(dbtableprefix + 'machinelearning'): db.session.execute( delete(MachineLearning).where( db.func.length(MachineLearning.key) > 1024). execution_options(synchronize_session=False)) db.session.execute( delete(MachineLearning).where( db.func.length(MachineLearning.group_id) > 1024). execution_options(synchronize_session=False)) changed = True if insp.has_table(dbtableprefix + 'globalobjectstorage'): db.session.execute( delete(GlobalObjectStorage).where( db.func.length(GlobalObjectStorage.key) > 1024). execution_options(synchronize_session=False)) changed = True if changed: db.session.commit() packagedir = pkg_resources.resource_filename( pkg_resources.Requirement.parse('docassemble.webapp'), 'docassemble/webapp') if not os.path.isdir(packagedir): sys.exit("path for running alembic could not be found") alembic_cfg = Config(os.path.join(packagedir, 'alembic.ini')) alembic_cfg.set_main_option("sqlalchemy.url", alchemy_connection_string()) alembic_cfg.set_main_option("script_location", os.path.join(packagedir, 'alembic')) if not insp.has_table(dbtableprefix + 'alembic_version'): logmessage("create_tables.main: creating alembic stamp") command.stamp(alembic_cfg, "head") logmessage( "create_tables.main: done creating alembic stamp after " + str(time.time() - start_time) + " seconds") if insp.has_table(dbtableprefix + 'user'): logmessage("create_tables.main: creating alembic stamp") logmessage("create_tables.main: running alembic upgrade") command.upgrade(alembic_cfg, "head") logmessage( "create_tables.main: done running alembic upgrade after " + str(time.time() - start_time) + " seconds") #db.drop_all() try: logmessage("create_tables.main: trying to create tables") db.create_all() except: logmessage( "create_tables.main: error trying to create tables; trying a second time." ) try: db.create_all() except: logmessage( "create_tables.main: error trying to create tables; trying a third time." ) db.create_all() logmessage("create_tables.main: finished creating tables after " + str(time.time() - start_time) + " seconds.") if dbprefix.startswith('postgresql'): try: test_for_errors(start_time=start_time) except: logmessage( "create_tables.main: unable to test for errors after " + str(time.time() - start_time) + " seconds.") logmessage("create_tables.main: populating tables after " + str(time.time() - start_time) + " seconds.") populate_tables(start_time=start_time) logmessage("create_tables.main: disposing engine after " + str(time.time() - start_time) + " seconds.") db.engine.dispose() logmessage("create_tables.main: finishing after " + str(time.time() - start_time) + " seconds.")