def main(): if 'REMOTE_DEBUG' in os.environ: print("Starting remote debugger on port 5678") import debugpy debugpy.listen(("0.0.0.0", 5678)) print("Waiting for connection...") debugpy.wait_for_client() args = docopt(__doc__, version='fcreplay 0.9.1') # Setup logging if not checking or generating config if not args['config']: fclogging.setup_logger() if args['tasker']: if args['start']: if args['recorder']: if '--max_instances' in args: Tasker().recorder(max_instances=args['--max_instances']) else: Tasker().recorder() if args['check_top_weekly']: Tasker().check_top_weekly() if args['check_video_status']: Tasker().check_video_status() elif args['cli']: c = Cli() sys.exit(c.cmdloop()) elif args['config']: if args['validate']: Config().validate_config_file(args['<config.json>']) if args['generate']: Config().generate_config() elif args['get']: if args['game']: Getreplay().get_game_replays(game=args['<gameid>']) if args['ranked']: Getreplay().get_ranked_replays(game=args['<gameid>'], username=args['--playerid'], pages=args['--pages']) if args['replay']: Getreplay().get_replay(url=args['<url>'], player_requested=args['--playerrequested']) if args['weekly']: Getreplay().get_top_weekly() elif args['instance']: i = Instance() i.debug = args['--debug'] i.main()
def test_file_not_found(request): temp_config = tempfile._get_default_tempdir() + '/' + next( tempfile._get_candidate_names()) os.environ['FCREPLAY_CONFIG'] = temp_config with pytest.raises(SystemExit) as e: Config().config assert e.type == SystemExit, "Should exit when file doesn't exist" assert os.path.exists(temp_config), "Should create config" config = Config().config assert type(config) is dict, "Generated config should be dict" os.remove(temp_config)
def __init__(self): if 'REMOTE_DEBUG' in os.environ: import debugpy debugpy.listen(("0.0.0.0", 5678)) debugpy.wait_for_client() self.config = Config().config self.db = Database()
def __init__(self): self.config = Config().config self.db = Database() with open( pkg_resources.resource_filename( 'fcreplay', 'data/supported_games.json')) as f: self.supported_games = json.load(f)
def __init__(self): self.config = Config().config self.db = Database() self.replay = self.get_replay() self.description_text = "" # On replay start create a status file in /tmp # This is used to determine shutdown status for a replay with open('/tmp/fcreplay_status', 'w') as f: f.write(f"{self.replay.id} STARTED")
def __init__(self): self.config = Config().config self.gcloud = False self.debug = False if 'REMOTE_DEBUG' in os.environ: import debugpy self.debug = True debugpy.listen(("0.0.0.0", 5678)) debugpy.wait_for_client()
def __init__(self): config = Config().config # Create Engine try: self.engine = create_engine(config['sql_baseurl'], echo=True) Base.metadata.create_all(self.engine) except Exception as e: logging.error(f"Unable to connect to {config['sql_baseurl']}: {e}") self.Session = sessionmaker(bind=self.engine)
def __init__(self): self.config = Config().config self.GCLOUD_FUNCTION = True if 'X_GOOGLE_FUNCTION_IDENTITY' not in os.environ: logging.basicConfig( format='%(asctime)s %(name)s %(levelname)s: %(message)s', filename=self.config['logfile'], level=self.config['loglevel'], datefmt='%Y-%m-%d %H:%M:%S' ) logging.getLogger('sqlalchemy').setLevel(logging.ERROR) self.GCLOUD_FUNCTION = False
def __init__(self): self.config = Config().config self.db = Database() self.replay = self.get_replay() self.description_text = "" self.detected_characters = [] with open( pkg_resources.resource_filename( 'fcreplay', 'data/supported_games.json')) as f: self.supported_games = json.load(f) # On replay start create a status file in /tmp - Legacy? with open('/tmp/fcreplay_status', 'w') as f: f.write(f"{self.replay.id} STARTED")
def __init__(self): config = Config().config if 'DEBUG' in config['loglevel']: sql_echo = True else: logging.getLogger('sqlalchemy').setLevel(logging.ERROR) sql_echo = False # Create Engine try: log.debug(f"Creating DB Instance with: {config['sql_baseurl']}") self.engine = create_engine(config['sql_baseurl'], echo=sql_echo, pool_pre_ping=True) Base.metadata.create_all(self.engine) except Exception as e: log.error(f"Unable to connect to {config['sql_baseurl']}: {e}") raise e self.Session = sessionmaker(bind=self.engine)
def setup_logger(): config = Config().config # create logger logger = logging.getLogger('fcreplay') logger.setLevel(config['loglevel']) # create console handler and set level stream_handler = logging.StreamHandler() stream_handler.setLevel(config['loglevel']) logger.addHandler(stream_handler) # Setup logging_loki handler if config['logging_loki']['enabled']: logger.addHandler(_loki_handler(config)) # Setup file handler if we aren't running in a cloud function (which is read only) if 'X_GOOGLE_FUNCTION_IDENTITY' not in os.environ: logger.addHandler(_file_handler(config))
def __init__(self): config = Config().config if 'DEBUG' in config['loglevel']: sql_echo = True else: sql_echo = False # Create Engine try: Logging().info( f"Creating DB Instance with: {config['sql_baseurl']}") self.engine = create_engine(config['sql_baseurl'], echo=sql_echo) Base.metadata.create_all(self.engine) except Exception as e: Logging().error( f"Unable to connect to {config['sql_baseurl']}: {e}") raise e self.Session = sessionmaker(bind=self.engine)
fcreplaydestroy destroy fcreplaydestroy (-h | --help) Options: -h --help Show this screen. """ from docopt import docopt from fcreplay.database import Database from fcreplay.config import Config from fcreplay import logging from pathlib import Path import requests import socket import sys config = Config().config REGION = config['gcloud_region'] PROJECT_ID = config['gcloud_project'] def destroy_fcreplay(failed=False): """Destry the current compute engine Checks for the existance of /tmp/destroying. If it exists then don't try and destroy fcreplay Args: failed (bool, optional): Updates the replay to failed. Defaults to False. """ # Create destroying file
def __init__(self): self.config = Config().config self.font_path = "/opt/droid-fonts/droid/DroidSans.ttf" self.flag_path = "/opt/flag-icon-css-3.5.0/flags/4x3"
def __init__(self): self.config = Config().config
def __init__(self): self.config = Config().config self.REGION = self.config['gcloud_region'] self.PROJECT_ID = self.config['gcloud_project']
def test_empty_json(request): os.environ['FCREPLAY_CONFIG'] = datadir(request, 'config_empty.json') with pytest.raises(SystemExit) as e: Config().config assert e.type == SystemExit, "Should exit when file isn't valid"
def test_empty_json(request): os.environ['FCREPLAY_CONFIG'] = datadir(request, 'config_empty.json') with pytest.raises(LookupError): Config().config
def test_invalid_json(request): os.environ['FCREPLAY_CONFIG'] = datadir(request, 'config_bad.json') with pytest.raises(JSONDecodeError): Config().config
def test_valid_json(request): os.environ['FCREPLAY_CONFIG'] = datadir(request, 'config_good.json') config = Config().config assert type(config) is dict, "Should be dict"
def test_file_not_found(request): temp_config = tempfile._get_default_tempdir() + '/' + next(tempfile._get_candidate_names()) os.environ['FCREPLAY_CONFIG'] = temp_config with pytest.raises(SystemExit) as e: Config().config assert e.type == SystemExit, "Should exit when file doesn't exist"
def __init__(self): log.debug('Creating character detection instance') self.config = Config().config self.events = [{'start_time': datetime.datetime.now()}] self.finished = False self.overlay_pickle_path = f"{self.config['fcadefbneo_path']}/avi/overlay.pickle"