def main(): "" args = docopt(__doc__, version="0.0") config_file = args["--config"] appconfig = loadConfig(config_file) cookie_secret = appconfig.get("SECURE_COOKIE_SECRET") if args["serve"]: serve(config_file, cookie_secret=cookie_secret)
def main(): """""" config_file = "site.cfg" config = loadConfig(config_file) db_file = config["SQLITE_DATABASE_URI"] db = sqlite3.connect(db_file) add_bit_icons_in_file_system(db) update_bit_icon_expiration(db, config["BIT_ICON_EXPIRATION"])
def main(): """ Prints out the value for a config name in the site.cfg file. """ config_file = sys.argv[1] name = sys.argv[2] config = loadConfig(config_file) value = config[name] print(value)
def main(): config_file = "site.cfg" config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") app = make_app(config=config_file, cookie_secret=cookie_secret, database_writable=True) logger.setLevel(logging.DEBUG if config["DEBUG"] else logging.INFO) with app.app_context(): migrate(config)
def __init__(self, config_file, **kw): config = loadConfig(config_file) config.update(kw) logger.setLevel(logging.DEBUG if config["DEBUG"] else logging.INFO) self.halt = False self.config = config self.greenlet_list = [] self.pubsub = get_redis_connection( self.config, decode_responses=False).pubsub(ignore_subscribe_messages=False) self.active_puzzles = set() signal.signal(signal.SIGINT, self.cleanup)
def main(): args = docopt(__doc__) config_file = args["--config"] show_list = args.get("--list") config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") app = make_app(config=config_file, cookie_secret=cookie_secret) with app.app_context(): if not show_list: render_all() else: list_all()
def main(): """ Prints out the value for a config name in the site.cfg file. """ config_file = sys.argv[1] name = sys.argv[2] config = loadConfig(config_file) value = config[name] if isinstance(value, (str, int, float, bool)): print(value) elif isinstance(value, (list, set)): print(" ".join(map(str, value)))
def main(): args = docopt(__doc__, version="0.0") config_file = args["--config"] config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") count = int(args.get("--count")) size = args.get("--size") max_pieces = int(args.get("--pieces")) min_pieces = int(args.get("--min-pieces")) puzzles = args.get("--puzzles") app = make_app(config=config_file, cookie_secret=cookie_secret, database_writable=True) with app.app_context(): if args.get("players"): print("Creating {} players".format(count)) generate_users(count) elif args.get("puzzles"): print( "Creating {count} puzzles at {size} with up to {max_pieces} pieces" .format(count=count, size=size, max_pieces=max_pieces, min_pieces=min_pieces)) generate_puzzles(count=count, size=size, min_pieces=min_pieces, max_pieces=max_pieces) elif args.get("instances"): print( "Creating {count} puzzle instances with up to {max_pieces} pieces" .format(count=count, max_pieces=max_pieces, min_pieces=min_pieces)) generate_puzzle_instances(count=count, min_pieces=min_pieces, max_pieces=max_pieces) elif args.get("activity"): print("Simulating puzzle activity") puzzle_ids = [] if puzzles: puzzle_ids = puzzles.split(",") simulate_puzzle_activity(puzzle_ids, count=count)
def main(): "" args = docopt(__doc__) config_file = args["--config"] task_name = args.get("--task") show_list = args.get("--list") if task_name: OneOffTask = globals().get(task_name) if not issubclass(OneOffTask, Task): print("{} is not a task in the list".format(task_name)) return if show_list: for item in globals(): Item = globals().get(item) if isinstance(Item, type) and issubclass(Item, Task): print(item) return config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") app = make_app( config=config_file, cookie_secret=cookie_secret, ) with app.app_context(): # Check if running a one-off, otherwise just run main if task_name: OneOffTask = globals().get(task_name) if issubclass(OneOffTask, Task): # Run the task oneOffTask = OneOffTask() oneOffTask() else: try: current_app.logger.info( "Delaying start of initial task by 20 seconds.") sleep(20) all_tasks() except requests.exceptions.ConnectionError as err: current_app.logger.warning( "Connection error. Retrying in {} seconds... \nError: {}". format(SCHEDULER_RETRY_INTERVAL, err)) sleep(SCHEDULER_RETRY_INTERVAL)
def main(): "" args = docopt(__doc__) config_file = args["--config"] config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") redis_connection = get_redis_connection(config, decode_responses=False) app = make_app(config=config_file, cookie_secret=cookie_secret) with app.app_context(): with Connection(redis_connection): worker = Worker(list(map(Queue, listen))) # If the render process has an exception worker.push_exc_handler(handle_fail) worker.work(with_scheduler=True)
def main(): "" args = docopt(__doc__) config_file = args["--config"] config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") redis_connection = get_redis_connection(config, decode_responses=False) app = make_app(config=config_file, cookie_secret=cookie_secret) with app.app_context(): with Connection(redis_connection): worker = Worker(list(map(Queue, listen))) # TODO: handle exceptions # worker.push_exc_handler(pieceTranslate.handle_piece_error) worker.work()
def main(): """""" config_file = "site.cfg" config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") args = docopt(__doc__) is_destructive = args["--destructive"] app = make_app( config=config_file, cookie_secret=cookie_secret, ) with app.app_context(): if current_app.config["LOCAL_PUZZLE_RESOURCES"]: move_all_from_s3(is_destructive=is_destructive) else: move_all_to_s3(is_destructive=is_destructive)
monkey.patch_all() from socket import SHUT_RDWR from gevent import sleep from geventwebsocket import WebSocketApplication from geventwebsocket.exceptions import WebSocketError from api.tools import loadConfig, get_redis_connection # Prevent too many files open errors by limiting the number of possible # connections that can be open. MAX_CONNECTIONS = 300 config_file = sys.argv[1] config = loadConfig(config_file) logging.basicConfig() logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG if config["DEBUG"] else logging.INFO) class DivulgeApplication(WebSocketApplication): @property def redis(self): return get_redis_connection(config) def kill_connection(self, reason): logger.debug("kill connection {0}".format(self.ws.handler.client_address)) self.ws.send(reason)
def main(): config_file = "site.cfg" config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") app = make_app(config=config_file, cookie_secret=cookie_secret, database_writable=True) logger.setLevel(logging.DEBUG if config["DEBUG"] else logging.INFO) with app.app_context(): cur = db.cursor() # Always create the PuzzleMassive table in case it doesn't exist. cur.execute(read_query_file("create_table_puzzle_massive.sql")) db.commit() script_file = sys.argv[0] migrate_scripts = glob( f"{os.path.dirname(script_file)}/migrate_puzzle_massive_database_version_[0-9][0-9][0-9].py" ) if len(migrate_scripts) == 0: logger.warning( f"No migrate scripts found for glob: '{os.path.dirname(script_file)}/migrate_puzzle_massive_database_version_[0-9][0-9][0-9].py'" ) cur.close() sys.exit(0) next_migrate_script = get_next_migrate_script(migrate_scripts) sanity_count = 0 while next_migrate_script: version = version_number(next_migrate_script) logger.info( f"Executing {next_migrate_script} to migrate from PuzzleMassive database version {version}." ) logger.debug(f"sanity count {sanity_count}") sanity_count = sanity_count + 1 # Execute the next_migrate_script try: output = subprocess.run([sys.executable, next_migrate_script], check=True, capture_output=True) except subprocess.CalledProcessError as err: logger.debug(str(err)) logger.error(f"Failed when executing {next_migrate_script}.") logger.info(f"\n{err.stdout.decode()}\n") logger.error(f"\n{err.stderr.decode()}\n") cur.close() sys.exit(1) logger.info(f"\n{output.stdout.decode()}\n") logger.info(f"\n{output.stderr.decode()}\n") # Bump the database_version assuming that the migrate script was # successful. now = datetime.datetime.utcnow().isoformat() logger.info( f"Successfully executed {next_migrate_script} and will now update database_version to be {version + 1}." ) cur.execute( read_query_file("upsert_puzzle_massive.sql"), { "key": "database_version", "label": "Database Version", "description": f"Puzzle Massive Database version updated on {now}. Only update this via the {script_file}", "intvalue": version + 1, "textvalue": None, "blobvalue": None }) db.commit() next_migrate_script = get_next_migrate_script(migrate_scripts) if sanity_count > len(migrate_scripts): logger.error( "Exiting out of while loop for checking next migrate scripts." ) break else: logger.info("PuzzleMassive database version is up to date.") cur.close()
def main(): args = docopt(__doc__, version="0.0") config_file = args["--config"] config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") count = int(args.get("--count")) size = args.get("--size") max_pieces = int(args.get("--pieces")) min_pieces = int(args.get("--min-pieces")) puzzles = args.get("--puzzles") delay = float(args.get("--delay")) dictConfig({ "version": 1, "formatters": { "default": { "format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s", } }, "handlers": { "wsgi": { "class": "logging.StreamHandler", "stream": "ext://flask.logging.wsgi_errors_stream", "formatter": "default", } }, "root": { "level": "INFO", "handlers": ["wsgi"] }, }) app = make_app(config=config_file, cookie_secret=cookie_secret, database_writable=True) with app.app_context(): if args.get("players"): current_app.logger.info("Creating {} players".format(count)) generate_users(count) elif args.get("puzzles"): current_app.logger.info( "Creating {count} puzzles at {size} with up to {max_pieces} pieces" .format(count=count, size=size, max_pieces=max_pieces, min_pieces=min_pieces)) generate_puzzles(count=count, size=size, min_pieces=min_pieces, max_pieces=max_pieces) elif args.get("instances"): current_app.logger.info( "Creating {count} puzzle instances with up to {max_pieces} pieces" .format(count=count, max_pieces=max_pieces, min_pieces=min_pieces)) generate_puzzle_instances(count=count, min_pieces=min_pieces, max_pieces=max_pieces) elif args.get("activity"): current_app.logger.info("Simulating puzzle activity") puzzle_ids = [] if puzzles: puzzle_ids = puzzles.split(",") simulate_puzzle_activity(puzzle_ids, count=count, max_delay=delay)