Beispiel #1
0
def init(name=getpass.getuser()):
    """Create a new .pile file in the current directory. All other commands will
operate on this file."""
    fs = helpers.list_filenames()

    if len(fs) > 0:

        raise CommandError(CANNOT_INITIALIZE.format(filename = fs[0]))

    fn = name + '.pile'
    yield "Creating " + fn
    helpers.write_db(Pile(), fn)
Beispiel #2
0
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)
Beispiel #3
0
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
Beispiel #4
0
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)