def cmd_deck(arg): """Create or load an active deck. Required: Deck name to load, or to create if it does not exist. """ global active_deck if not arg: raise UsageError('NAME') try: with open(deck.filename(arg), "rb") as f: active_deck = pickle.load(f) print('Loaded deck \'' + active_deck.name + '\'.') except IOError: active_deck = deck.Deck(arg) print('Created new deck \'' + active_deck.name + '\'.')
def cmd_save(arg): """Save the active deck.""" assert_activedeck() with open(deck.filename(active_deck.name), "wb") as f: pickle.dump(active_deck, f) print('Saved deck \'' + active_deck.name + '\'.')