def app(app: App, name: str, path: str): echo_info("App", app) game_dir = Path(app.game_path).resolve().parent repo_path = Path(path).expanduser().resolve() repo_relative = repo_path.relative_to(game_dir) repo = game_store.Repository( id=data_utils.name_to_id(repo_relative.name, "r"), name=repo_relative.name, directory=str(repo_relative), ssh_url=None, commit=None, metadata=None, ) app.game.repositories.append(repo) phase = game_store.Phase( index=0, repository=repo.id, player=app.game.gm.username, role=game_store.Role.SOURCERER, ) game_app = game_store.App( id=data_utils.name_to_id(name, pre="a"), name=name, editable_paths=[], phases=[phase], ) app.game.apps.append(game_app) app.save_game()
def init_game(path: str, name: str, players: str, gm: str): id = data_utils.name_to_id(name) gm_user = game_store.User(username=gm, name=gm) # Create user objects from unique player ids. player_users = [ game_store.User(username=username, name=username) for username in set(n for n in players.split(",") if len(n)) ] game = game_store.Game(name=name, id=id, gm=gm_user, players=player_users, apps=[], repositories=[]) game_store.save(path, game) echo_info("New game at", path)
def handle_phase(self, phase, game_app_dir): local = self.name_to_local[phase.repository] name = local.metadata["name"] ssh_url = local.metadata["ssh_url"] phase_repo_dir = game_app_dir / local.id if phase_repo_dir.is_dir(): echo_info(f"Found existing {game_app_dir}") cloned_repo = git.Repo(phase_repo_dir) else: echo_info(f"Cloning: {ssh_url} into {game_app_dir}") cloned_repo = git.Repo.clone_from(ssh_url, phase_repo_dir) echo_info(f"Phase repo commit: {cloned_repo.head.commit.hexsha}") local.name = name local.ssh_url = ssh_url local.directory = str(phase_repo_dir) local.commit = cloned_repo.head.commit.hexsha
def publicize(app): for local, remote in app.iter_locals_remotes(): echo_info(f"Making {remote.name} public.") remote.edit(private=False)
def fetch_metadata(app): echo_info("Loading all repos...") app.get_repos() echo_info("Game time.") changed_count = 0 for local in app.game.repositories: remotes = app.ls(local.id) if not remotes: echo_info(f"No remote for {local.id}") continue remote = remotes[0] echo_info(f"Found {remote.name} for {local.id}") incoming_metadata = { "id": remote.id, "name": remote.name, "full_name": remote.full_name, "html_url": remote.clone_url, "clone_url": remote.clone_url, "ssh_url": remote.ssh_url, "isPrivate": remote.private, } if local.metadata == incoming_metadata: echo_info("No difference.") continue if local.metadata: echo_info("Original metadata:", local.metadata) echo_info("Incoming metadata:", incoming_metadata) local.metadata = incoming_metadata changed_count += 1 if changed_count < 1: echo_info("Nothing changed.") return echo_info("Writing changes to game file:", app.game_path) app.save_game()
def exec_all(app, command): for phase, local in app.iter_phase_locals(): echo_info(f"Running {command} in {local.directory}") subprocess.run(command, cwd=local.directory)