def show(name=None, platform=None, priorities=None, genres=None): """Show pile games, with optional filtering.""" db = helpers.read_db() if len(db.games) == 0: raise CommandError('No games found. Use the `add` command to add some.') gs = db.search(name=name, platform=platform, priorities=priorities, genres=genres) for line in helpers.show(gs): yield line
def rm(name): """Remove a pile game""" db = helpers.read_db() gs = db.search(exact_name=name) if len(gs) == 0: raise CommandError("No games found") g = gs[0] db.games.remove(g) yield "Removing game from pile" for line in helpers.show([g]): yield line helpers.write_db(db)
def add(name, platform, on_pile_date=datetime.date.today().isoformat(), priority = PRIORITY_MED, hours = 10, genres = []): """Add a pile game""" db = helpers.read_db() if len(db.search(exact_name=name)) > 0: raise CommandError("A game with that name already exists") g = PileGame(name, platform, on_pile_date, priority, hours, genres) db.games.append(g) helpers.write_db(db) yield "Added game to pile" for line in helpers.show([g]): yield line
def edit(name, platform = None, rename = None, on_pile_date=None, priority = None, hours = None, genres = None): """Edit a pile game""" db = helpers.read_db() gs = db.search(exact_name=name) if len(gs) == 0: raise CommandError("No games found") g = gs[0] if rename: g.name = rename if platform: g.platform = platform if hours: g.hours = hours if priority: g.priority = priority if on_pile_date: g.on_pile_date = on_pile_date if genres: g.genres = genres yield "Game updated" for line in helpers.show([g]): yield line helpers.write_db(db)