#!/usr/bin/env python import os import gtk import gconf import sys class map(): def __init__(self): if len(sys.argv) == 2: if sys.argv[1] == '--set': configDir = os.path.expanduser('~/.config/sunmap/') key = '/desktop/gnome/background/picture_filename' key2 = '/desktop/gnome/background/picture_options' map = 'http://www.opentopia.com/images/cams/world_sunlight_map_rectangular.jpg' base = 'world_sunlight_map_rectangular.jpg' if os.path.isdir(configDir): pass else: os.mkdir(configDir) os.chdir(configDir) os.system('wget -nc '+map+'') client = gconf.client_get_default() client.set_string(key, (configDir+base)) client.set_string(key2, 'zoom') pass if sys.argv[1] == '--configure': if os.popen('sudo').read(): print 'To configure this, I need your password (to run as root)' print 'Please type it in below, or if you are feeling too paranoid, run this again as root (or with sudo)' os.system('sudo ./sunmap --do-configure') else: if os.popen('whoami').read() == 'root': os.system('./sunmap --do-configure') else: print 'To configure this, this task needs to be run as root' print 'Please run this again as root' pass if sys.argv[1] == '--do-configure': os.system('echo exec '+(os.getcwd())+'/sunmap --set > /etc/cron.hourly/sunmap') print 'Done!' pass print "Sorry didn't understand that!" print "" print "Usage:" print "" print "--set : Grab the Latest Sunlight Map and set it as your background" print "--configure : Configure SunMap to automatically download the latest Sunlight Map when it is available" map()