How to use the sc2reader.utils.get_files function in sc2reader

To help you get started, we’ve selected a few sc2reader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GraylinKim / sc2reader / examples / sc2store.py View on Github external
def main():
    args = parse_args()
    db = load_session(args)

    for path in args.paths:
        for file_name in sc2reader.utils.get_files(path, depth=0):
            print "CREATING: {0}".format(file_name)
            db.add(Game(sc2reader.read_file(file_name), db))

    db.commit()

    print list(db.query(distinct(Person.name)).all())
github GraylinKim / sc2reader / examples / sc2autosave.py View on Github external
def scan(args, state):
    args.log.write("SCANNING: {0}\n".format(args.source))
    files = sc2reader.utils.get_files(
        path=args.source,
        regex=args.exclude_files,
        allow=False,
        exclude=args.exclude_dirs,
        depth=args.depth,
        followlinks=args.follow_links)
    return filter(lambda f: os.path.getctime(f) > state.last_sync, files)
github GraylinKim / sc2reader / sc2reader / factories / sc2factory.py View on Github external
def _load_resources(self, resources, options=None, **new_options):
        """Collections of resources or a path to a directory"""
        options = options or self._get_options(Resource, **new_options)

        # Path to a folder, retrieve all relevant files as the collection
        if isinstance(resources, basestring):
            resources = utils.get_files(resources, **options)

        for resource in resources:
            yield self._load_resource(resource, options=options)
github GraylinKim / sc2reader / sc2reader / scripts / sc2printer.py View on Github external
help="print observers")

    replay_args = parser.add_argument_group('Replay Options')
    replay_args.add_argument('--messages', action="store_true", default=False,
                             help="print(in-game player chat messages [default off]")
    replay_args.add_argument('--version', action="store_true", default=True,
                             help="print(the release string as seen in game [default on]")

    s2gs_args = parser.add_argument_group('Game Summary Options')
    s2gs_args.add_argument('--builds', action="store_true", default=False,
                           help="print(player build orders (first 64 items) [default off]")

    arguments = parser.parse_args()
    for path in arguments.paths:
        depth = -1 if arguments.recursive else 0
        for filepath in utils.get_files(path, depth=depth):
            name, ext = os.path.splitext(filepath)
            if ext.lower() == '.sc2replay':
                print("\n--------------------------------------\n{0}\n".format(filepath))
                printReplay(filepath, arguments)
            elif ext.lower() == '.s2gs':
                print("\n--------------------------------------\n{0}\n".format(filepath))
                printGameSummary(filepath, arguments)
github GraylinKim / sc2reader / sc2reader / scripts / sc2parse.py View on Github external
def main():
    parser = argparse.ArgumentParser(description="Recursively parses replay files, inteded for debugging parse issues.")
    parser.add_argument('--one_each', help="Attempt to parse only one Ladder replay for each release_string", action="store_true")
    parser.add_argument('--ladder_only', help="If a non-ladder game fails, ignore it", action="store_true")
    parser.add_argument('folders', metavar='folder', type=str, nargs='+', help="Path to a folder")
    args = parser.parse_args()

    releases_parsed = set()
    for folder in args.folders:
        print("dealing with {0}".format(folder))
        for path in sc2reader.utils.get_files(folder, extension='SC2Replay'):
            try:
                rs = sc2reader.load_replay(path, load_level=0).release_string
                already_did = rs in releases_parsed
                releases_parsed.add(rs)
                if not args.one_each or not already_did:
                    replay = sc2reader.load_replay(path, debug=True, load_level=1)
                    if not args.one_each or replay.is_ladder:
                        replay = sc2reader.load_replay(path, debug=True)

                        human.pids = set([human.pid for human in replay.humans])
                        event_pids = set([event.player.pid for event in replay.events if getattr(event, 'player', None)])
                        player_pids = set([player.pid for player in replay.players if player.is_human])
                        ability_pids = set([event.player.pid for event in replay.events if 'CommandEvent' in event.name])
                        if human.pids != event_pids:
                            print('Event Pid problem!  pids={pids} but event pids={event_pids}'.format(pids=human.pids, event_pids=event_pids))
                            print(' with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))
github GraylinKim / sc2reader / sc2reader / scripts / sc2replayer.py View on Github external
def main():
    parser = argparse.ArgumentParser(
        description="""Step by step replay of game events; shows only the
        Initialization, Command, and Selection events by default. Press any
        key to advance through the events in sequential order."""
    )

    parser.add_argument('FILE', type=str, help="The file you would like to replay")
    parser.add_argument('--player', default=0, type=int, help="The number of the player you would like to watch. Defaults to 0 (All).")
    parser.add_argument('--bytes', default=False, action="store_true", help="Displays the byte code of the event in hex after each event.")
    parser.add_argument('--hotkeys', default=False, action="store_true", help="Shows the hotkey events in the event stream.")
    parser.add_argument('--cameras', default=False, action="store_true", help="Shows the camera events in the event stream.")
    args = parser.parse_args()

    for filename in sc2reader.utils.get_files(args.FILE):
        replay = sc2reader.load_replay(filename, debug=True)
        print("Release {0}".format(replay.release_string))
        print("{0} on {1} at {2}".format(replay.type, replay.map_name, replay.start_time))
        print("")
        for team in replay.teams:
            print(team)
            for player in team.players:
                print("  {0}".format(player))
        print("\n--------------------------\n\n")

        # Allow picking of the player to 'watch'
        if args.player:
            events = replay.player[args.player].events
        else:
            events = replay.events