<s> '''<STR_LIT>''' <EOL> import gettext <EOL> import os <EOL> import time <EOL> gettext . install ( '<STR_LIT>' ) <EOL> class ConfigObject : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename = None ) : <EOL> self . _dict = dict ( DEFAULT_CONFIG ) <EOL> self . _dirty_keys = set ( ) <EOL> if filename : <EOL> if os . path . exists ( filename ) : <EOL> self . load_config ( filename ) <EOL> else : <EOL> self . _filename = filename <EOL> if not os . path . exists ( os . path . dirname ( filename ) ) : <EOL> os . mkdir ( os . path . dirname ( filename ) ) <EOL> os . mkdir ( self . get ( '<STR_LIT>' ) ) <EOL> self . save_config ( filename ) <EOL> if not os . path . isdir ( self . get ( '<STR_LIT>' ) ) : <EOL> raise ValueError , _ ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> self . get ( '<STR_LIT>' ) ) <EOL> def get ( self , key , * args ) : <EOL> """<STR_LIT>""" <EOL> return self . _dict . get ( key , * args ) <EOL> def set ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> self . _dirty_keys . add ( key ) <EOL> self . _dict [ key ] = value <EOL> def load_config ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> self . _filename = filename <EOL> fileobj = open ( filename , '<STR_LIT:r>' ) <EOL> for lineno , line in enumerate ( fileobj ) : <EOL> line = line . strip ( ) <EOL> if not line : <EOL> continue <EOL> index = line . find ( '<STR_LIT:=>' ) <EOL> if index < <NUM_LIT:0> : <EOL> raise ValueError ( <EOL> _ ( '<STR_LIT>' ) % ( lineno , <EOL> filename ) ) <EOL> key , value = line [ : index ] . strip ( ) , line [ index + <NUM_LIT:1> : ] . strip ( ) <EOL> if key in self . _dict : <EOL> try : <EOL> self . _dict [ key ] = eval ( value ) <EOL> except Exception : <EOL> if ( key == '<STR_LIT>' and <EOL> value . startswith ( '<STR_LIT>' ) ) : <EOL> self . _dict [ key ] = time . localtime ( ) [ : <NUM_LIT:3> ] <EOL> else : <EOL> raise ValueError ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % ( lineno , filename ) ) <EOL> else : <EOL> raise ValueError ( <EOL> _ ( '<STR_LIT>' ) % ( <EOL> lineno , filename ) ) <EOL> fileobj . close ( ) <EOL> def save_config ( self , filename = None ) : <EOL> """<STR_LIT>""" <EOL> if not filename : <EOL> filename = self . _filename <EOL> org_cfg = ConfigObject ( filename ) <EOL> fileobj = open ( filename , '<STR_LIT:w>' ) <EOL> for key , _unused_value in DEFAULT_CONFIG : <EOL> try : <EOL> if key in self . _dirty_keys : <EOL> value = self . _dict [ key ] <EOL> else : <EOL> value = org_cfg . get ( key , None ) <EOL> fileobj . write ( '<STR_LIT>' % ( key , value ) ) <EOL> except ( KeyError , ValueError , TypeError ) , exc : <EOL> fileobj . write ( '<STR_LIT>' + str ( exc ) ) <EOL> fileobj . close ( ) <EOL> self . _dirty_keys . clear ( ) <EOL> DEFAULT_CONFIG = [ <EOL> ( '<STR_LIT>' , os . path . expanduser ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:5> ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , ( <NUM_LIT> , <NUM_LIT> ) ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , { } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , time . localtime ( ) [ : <NUM_LIT:3> ] ) , <EOL> ( '<STR_LIT>' , dict ( downloads = <NUM_LIT:0> , rotations = <NUM_LIT:0> ) ) , <EOL> ( '<STR_LIT>' , False ) ] <EOL> DEFAULT_CONFIG_FILE = os . path . expanduser ( '<STR_LIT>' ) <EOL> config = ConfigObject ( DEFAULT_CONFIG_FILE ) <EOL> def reload_config ( ) : <EOL> """<STR_LIT>""" <EOL> config . load_config ( DEFAULT_CONFIG_FILE ) <EOL> def set_wallpaper ( filename ) : <EOL> import gconf <EOL> """<STR_LIT>""" <EOL> use = config . get ( '<STR_LIT>' ) <EOL> if use == "<STR_LIT>" : <EOL> script = ( '<STR_LIT>' <EOL> '<STR_LIT>' % filename ) <EOL> os . popen2 ( script ) <EOL> elif use == "<STR_LIT>" : <EOL> conf_client = gconf . client_get_default ( ) <EOL> conf_client . set_string ( '<STR_LIT>' , <EOL> filename ) <EOL> elif use == "<STR_LIT>" : <EOL> script = '<STR_LIT>' <EOL> script = script . replace ( '<STR_LIT>' , filename ) <EOL> os . popen2 ( script ) <EOL> elif use == "<STR_LIT>" : <EOL> script = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> script = script . replace ( '<STR_LIT>' , filename ) <EOL> os . popen2 ( script ) <EOL> elif use == "<STR_LIT>" : <EOL> set_compiz_wallpaper ( filename ) <EOL> elif use == "<STR_LIT>" : <EOL> script = config . get ( '<STR_LIT>' ) <EOL> script = script . replace ( '<STR_LIT>' , filename ) <EOL> os . popen2 ( script ) <EOL> stats = config . get ( '<STR_LIT>' ) <EOL> stats [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> config . set ( '<STR_LIT>' , stats ) <EOL> config . save_config ( ) <EOL> def set_compiz_wallpaper ( filename ) : <EOL> """<STR_LIT>""" <EOL> import gconf <EOL> screen_face = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> try : <EOL> screen , face = screen_face . split ( '<STR_LIT:U+002C>' ) <EOL> face = int ( face ) <EOL> except ValueError : <EOL> screen , face = '<STR_LIT>' , <NUM_LIT:0> <EOL> conf_client = gconf . client_get_default ( ) <EOL> screens = [ s . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> for s in conf_client . all_dirs ( '<STR_LIT>' ) <EOL> if s . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] [ : <NUM_LIT:6> ] == '<STR_LIT>' ] <EOL> if screen not in screens : <EOL> screen = screens [ <NUM_LIT:0> ] <EOL> number_of_faces = ( <EOL> conf_client . get_int ( '<STR_LIT>' % screen ) * <EOL> conf_client . get_int ( '<STR_LIT>' % screen ) ) <EOL> wallpapers = conf_client . get_list ( <EOL> '<STR_LIT>' % screen , <EOL> gconf . VALUE_STRING ) <EOL> if len ( wallpapers ) < number_of_faces : <EOL> wallpapers . extend ( [ filename ] * ( number_of_faces - len ( wallpapers ) ) ) <EOL> prefix = '<STR_LIT>' % screen <EOL> settings = { <EOL> '<STR_LIT>' : ( gconf . VALUE_STRING , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( gconf . VALUE_STRING , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( gconf . VALUE_INT , <NUM_LIT:0> ) , <EOL> '<STR_LIT>' : ( gconf . VALUE_INT , <NUM_LIT:0> ) , <EOL> } <EOL> for key , value in settings . items ( ) : <EOL> ext_list = conf_client . get_list ( prefix + key , value [ <NUM_LIT:0> ] ) <EOL> ext_list . extend ( [ value [ <NUM_LIT:1> ] ] * ( number_of_faces - len ( ext_list ) ) ) <EOL> conf_client . set_list ( prefix + key , value [ <NUM_LIT:0> ] , ext_list ) <EOL> if face >= number_of_faces or face < <NUM_LIT:0> : <EOL> face = <NUM_LIT:0> <EOL> wallpapers [ face ] = filename <EOL> conf_client . set_list ( <EOL> '<STR_LIT>' % screen , <EOL> gconf . VALUE_STRING , <EOL> wallpapers ) <EOL> if face >= number_of_faces - <NUM_LIT:1> : <EOL> screen = screens [ ( screens . index ( screen ) + <NUM_LIT:1> ) % len ( screens ) ] <EOL> face = <NUM_LIT:0> <EOL> else : <EOL> face += <NUM_LIT:1> <EOL> config . set ( '<STR_LIT>' , <EOL> '<STR_LIT>' % ( screen , face ) ) <EOL> config . save_config ( ) </s>
