laterbase.py 2.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
# Laterbase, part of GNU FM -- a free network service for sharing your
# music listening habits
#
#    Copyright (C) 2009, 2012 Free Software Foundation, Inc
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import os
import getpass
import fileinput

LATERBASE = os.path.abspath("/home/" + getpass.getuser() + "/.laterbase")

def showhelp():
    print " "
    print "88        db    888888 888888 8888Yb 8888Yb    db    .dP8Y8 888888 "
    print "88       dPYb     88   88__   88__dP 88__dP   dPYb   `Ybo.8 88__   "
    print "88  .o  dP__Yb    88   8888   888Yb  8888Yb  dP__Yb  o.`Y8b 8888   "
    print "88ood8 dP8888Yb   88   888888 88  Yb 88oodP dP8888Yb 8bodP' 888888 "
    print " "
    print "Got a job you really don't want to do? Stick it on the laterbase!"
    print " "
    print "Usage:"
    print " "
    print "(Put this nice python script in somewhere useful like /usr/bin/lb)"
    print " "
    print "Then, just type lb wash car"
    print "And hey Presto, 'wash car' is added to your laterbase."


if (len(sys.argv) > 1):
    if( sys.argv[1] == 'list' ):
        try:
            ins = open( LATERBASE, "r" )
            for line in ins:
mattl's avatar
mattl committed
48
                print "* " + line
49 50 51 52 53 54 55 56 57 58 59 60 61
            ins.close()
        except IOError as e:
            print "You don't have anything on your laterbase. Try lb <item> to add something to the laterbase."

    elif( sys.argv[1] == 'help' ):
        showhelp()
    else:
        
        n = ""

        for x in range (1,len(sys.argv)):
            n = n + sys.argv[x] + " "

mattl's avatar
mattl committed
62
        n = n.strip() + "\n"
63 64 65 66 67 68 69 70 71 72 73 74

        try:
            f = open(LATERBASE, "a")
            try:
                f.write (n)
                print "Added '" + n + "' to the laterbase."
            finally:
                f.close()
        except IOError:
            print "Cannot write to ~/.laterbase."