#! /usr/bin/env python
print "\n-------- Installing Guido van Robot ---------"

from os.path import exists
import sys,os
from os import makedirs, mkdir, system
import compileall
if os.environ['USER'] != 'root':
    print "Only root can install this"
    sys.exit(1)

if not exists('/usr/local/GvR'):
    makedirs('/usr/local/GvR')
if not exists('/usr/local/share/icons'):
    makedirs('/usr/local/share/icons')
if not exists('/usr/local/share/locale'):
    makedirs('/usr/local/share/locale')
if not exists('/usr/local/man/man1'):
    makedirs('/usr/local/man/man1')
    
system('cp -rf *.py /usr/local/GvR/')
system('chmod 0755 /usr/local/GvR/gvr.py')
system('cp -f gvrrc /usr/local/GvR/')
system('cp gvr.sh /usr/local/bin/gvr')
system('cp -rf po /usr/local/GvR/')
system('cp -rf bitmaps /usr/local/GvR/')


try:
    system('cp -f bitmaps/gvrIcon-big.png /usr/local/share/icons/gvrIcon-big.png')
except Exception,info:
    print info

system('cp -rf docs /usr/local/GvR/')
system('cp -f docs/gvr.1.gz /usr/local/man/man1/gvr.1.gz')
system('cp -rf examples /usr/local/GvR/')
system('cp -rf locale/* /usr/local/share/locale')

system('chmod a+rx /usr/local/bin/gvr')

# python2.3.4 does not support the quiet option for 
# compileall
try:
    print "Trying to compiling modules to bytecode."
    compileall.compile_dir('/usr/local/GvR',quiet=1)
except:
    compileall.compile_dir('/usr/local/GvR')
print "Installation complete."
print "To start Guido van Robot -> gvr [Enter]"
print "Be sure to check the website http://gvr.sf.net, for additional information\nand lessons."
print "\nEnjoy\n"
