#!/mit/python/bin/python
''' Command line updater to the SIPB white board.
Checks out the whiteboard.content file,
invokes $EDITOR on it, then checks it in. 
'''

import sys, os, commands, string 
#  am I eligible to use this script?
stat = commands.getoutput("pts membership "+os.environ["USER"]
                                    +" -c sipb")

if string.find(stat,'system:www') < 0 :
    print "You don't have the bits to change the Whiteboard, "+os.environ["USER"]
    print "You need to complain to someone. "
    exit

dir=os.getcwd()
editor = "emacs"
if os.environ.has_key("VISUAL"):
    editor = os.environ["VISUAL"]
elif os.environ.has_key("EDITOR"):
    editor = os.environ["EDITOR"]
# checking it out.
os.chdir("/afs/sipb/project/www/sipb")


os.system("co -l whiteboard.content")

#
# editing it.

status = 'edit'

while status[0] == 'e' :
        os.system(editor + ' whiteboard.content')
        status = raw_input('What now? edit, save, quit >')

# checking it in. 
os.system("ci -u whiteboard.content")
# the make file should  make this step unnecessary.
#os.system("touch sipb.content")
os.system("athrun gnu gmake sipb.html")

os.chdir(dir)
