コード例 #1
0
ファイル: __main__.py プロジェクト: srdqty/fcreplay
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()
コード例 #2
0
ファイル: test_config.py プロジェクト: Yohadev/fcreplay
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)
コード例 #3
0
ファイル: getreplay.py プロジェクト: Yohadev/fcreplay
    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()
コード例 #4
0
ファイル: getreplay.py プロジェクト: srdqty/fcreplay
    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)
コード例 #5
0
    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")
コード例 #6
0
ファイル: loop.py プロジェクト: Yohadev/fcreplay
    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()
コード例 #7
0
    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)
コード例 #8
0
    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
コード例 #9
0
ファイル: replay.py プロジェクト: ehtrashy/fcreplay
    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")
コード例 #10
0
ファイル: database.py プロジェクト: ehtrashy/fcreplay
    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)
コード例 #11
0
ファイル: fclogging.py プロジェクト: srdqty/fcreplay
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))
コード例 #12
0
ファイル: database.py プロジェクト: Yohadev/fcreplay
    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)
コード例 #13
0
  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
コード例 #14
0
ファイル: updatethumbnail.py プロジェクト: srdqty/fcreplay
 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"
コード例 #15
0
ファイル: record.py プロジェクト: srdqty/fcreplay
 def __init__(self):
     self.config = Config().config
コード例 #16
0
ファイル: gcloud.py プロジェクト: Yohadev/fcreplay
    def __init__(self):
        self.config = Config().config

        self.REGION = self.config['gcloud_region']
        self.PROJECT_ID = self.config['gcloud_project']
コード例 #17
0
ファイル: test_config.py プロジェクト: srdqty/fcreplay
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"
コード例 #18
0
ファイル: test_config.py プロジェクト: Yohadev/fcreplay
def test_empty_json(request):
    os.environ['FCREPLAY_CONFIG'] = datadir(request, 'config_empty.json')
    with pytest.raises(LookupError):
        Config().config
コード例 #19
0
ファイル: test_config.py プロジェクト: Yohadev/fcreplay
def test_invalid_json(request):
    os.environ['FCREPLAY_CONFIG'] = datadir(request, 'config_bad.json')
    with pytest.raises(JSONDecodeError):
        Config().config
コード例 #20
0
ファイル: test_config.py プロジェクト: Yohadev/fcreplay
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"
コード例 #21
0
ファイル: test_config.py プロジェクト: srdqty/fcreplay
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"
コード例 #22
0
 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"