Ejemplo n.º 1
0
Archivo: anfo.py Proyecto: alfador/anfo
 command = command.strip()
 try:
     # Just check which command was given, and dispatch.
     if command == 'alfador':
         commands.ALFADOR()
     elif command.startswith('delete'):
         commands.delete_song(command[6:], db)
     elif command in ['exit', 'quit', 'q']:
         exit()
     elif command == 'help':
         print
         print help_str
     elif command.startswith('info'):
         commands.info(command[4:], db)
     elif command == 'queue':
         commands.queue(db)
     elif command == 'queue_songs':
         # sqlite3 might give an error on a bad query
         try:
             songs = commands.queue_songs(db)
             pageviewer.pageviewer(songs, db)
         except sqlite3.Error, e:
             print e
     elif command.startswith('query'):
         # sqlite3 might give an error on a bad query
         try:
             songs = commands.query(command[5:], db)
             pageviewer.pageviewer(songs, db)
         except sqlite3.Error, e:
             print e
     elif command.startswith('rate'):
Ejemplo n.º 2
0
def pageviewer(songs, db):
    '''
    Launches the pageviewer, printing out the given songs.
    Arguments:
        songs - List of SongInfo to view in the pageviewer.
        db - Database object
    '''
    num_songs = len(songs)
    num_pages = max(num_songs - 1, 0) / songs_per_page + 1
    # Write songs out in pages
    page = 1

    # Whether to show the songs or not.  This can be used e.g. if a user
    # requests help and wants to see stuff without all of the songs getting
    # in the way.
    show_page = True

    while True:
        # Show the page
        # Header stuff
        if show_page:
            print 'Page %d of %d' % (page, num_pages)
            print 'Showing songs %d-%d of %d' % \
                (songs_per_page * (page - 1) + 1,
                min(songs_per_page * page, num_songs), num_songs)
            print '%6s %30s %20s %4s %2s %5s' % ('ID', 'Title', 'Artist',
                'Dur.', 'U.', 'Rati.')
            # Printing the song
            for song in songs[(page - 1) * songs_per_page : 
                                    page * songs_per_page]:
                # Print each song, replace unprintable characters
                print ('%6d %30s %20s %4d %2d %5.2f' % (song.id,
                    song.title[:30], song.artist[:20], song.duration,
                    song.user_rating, song.rating)).encode('ascii', 'replace')
        
        # Default back to showing the page.
        show_page = True

        # Prompt for input
        command = raw_input("pageviewer> ")
        command = command.strip()
        # Process the command
        try:
            if command == 'help':
                show_page = False
                print
                print help_str
            elif command in ['exit', 'quit', 'q']:
                return # Go back to main prompt
            # Page-moving commands
            elif command == 'p':
                page = max(1, page - 1)
            elif command == 'n':
                page = min(page + 1, num_pages)
            elif command.startswith('g '):
                next_page = command[2:]
                if (not next_page.isdigit() or int(next_page) <= 0 or
                    int(next_page) > num_pages):
                    show_page = False
                    print 'Invalid page number!'
                    continue
                page = int(next_page)
            # Stats commands
            elif command == 'stats':
                show_page = False
                commands.print_stats(songs)
            elif command == 'global_stats':
                show_page = False
                commands.print_global_stats(songs)
            elif command.startswith('all_the_stats'):
                show_page = False
                commands.print_all_the_stats(command, songs)
            elif command == 'queue':
                show_page = False
                commands.queue(db)
            elif command == 'queue_songs':
                # Might get an error, and also need to update certain variables
                try:
                    songs = commands.queue_songs(db)
                    num_songs = len(songs)
                    num_pages = max(num_songs - 1, 0) / songs_per_page + 1
                    page = 1
                except sqlite3.Error, e:
                    show_page = False
                    print e
            elif command.startswith('query'):
                # Might get an error, and also need to update certain variables
                try:
                    songs = commands.query(command[5:], db)
                    num_songs = len(songs)
                    num_pages = max(num_songs - 1, 0) / songs_per_page + 1
                    page = 1
                except sqlite3.Error, e:
                    show_page = False
                    print e
Ejemplo n.º 3
0
Archivo: anfo.py Proyecto: alfador/anfo
 command = command.strip()
 try :
     # Just check which command was given, and dispatch.
     if command == 'alfador':
         commands.ALFADOR()
     elif command.startswith('delete'):
         commands.delete_song(command[6:], db)
     elif command in ['exit', 'quit', 'q']:
         exit()
     elif command == 'help':
         print
         print help_str
     elif command.startswith('info'):
         commands.info(command[4:], db)
     elif command == 'queue':
         commands.queue(db)
     elif command == 'queue_songs':
         # sqlite3 might give an error on a bad query
         try:
             songs = commands.queue_songs(db)
             pageviewer.pageviewer(songs, db)
         except sqlite3.Error, e:
             print e
     elif command.startswith('query'):
         # sqlite3 might give an error on a bad query
         try:
             songs = commands.query(command[5:], db)
             pageviewer.pageviewer(songs, db)
         except sqlite3.Error, e:
             print e
     elif command.startswith('rate'):