(XML):<default type="label"> <posx>80</posx> <posy>60</posy> <label>-</label> <font>font13</font> <textcolor>white</textcolor></default>
(Python):import xbmc# Execute shell commands and freezes XBMC until shell is closedcmd = "System.ExecWait" # Execute shell commands#cmd = "System.Exec" command = '%s("%s")' % ( cmd, "C:\\Program Files\\Mozilla Firefox\\firefox.exe" )xbmc.executebuiltin( command )
(Python):#pour récupérer le log level actuel (utile pour le rétablir si besoin après l'exécution du script)actualloglevel = xbmc.executehttpapi("GetLogLevel").replace("<li>","") #pour régler le loglevel sur la valeur désirée (ici à 1):status = xbmc.executehttpapi("SetLogLevel(1)").replace("<li>","")#si tout c'est bien passé, status contient "OK"
(Python):import xbmc def get_system_platform(): """ fonction: pour recuperer la platform que xbmc tourne """ platform = "unknown" if xbmc.getCondVisibility( "system.platform.linux" ): platform = "linux" elif xbmc.getCondVisibility( "system.platform.xbox" ): platform = "xbox" elif xbmc.getCondVisibility( "system.platform.windows" ): platform = "windows" elif xbmc.getCondVisibility( "system.platform.osx" ): platform = "osx" return platform
(Python):if os.environ.get( "OS", "" ).lower() == "os x": print "Platform MAC"
(Python):# If the dir exists with the requested name, simply return it __all__ = [ # public names "XBMC_IS_HOME", "SPECIAL_XBMC_DIR", "SPECIAL_HOME_DIR", "SPECIAL_TEMP_DIR", "SPECIAL_PROFILE_DIR", "SPECIAL_MASTERPROFILE_DIR", "SPECIAL_XBMC_HOME", "SPECIAL_SCRIPT_DATA", ] import osimport sysfrom xbmc import translatePath PLATFORM_MAC = os.environ.get( "OS", "" ).lower() == "os x" try: scriptname = sys.modules[ "__main__" ].__script__except: scriptname = os.path.basename( os.getcwd() ) SPECIAL_XBMC_DIR = translatePath( "special://xbmc/" )if PLATFORM_MAC or not os.path.isdir( SPECIAL_XBMC_DIR ): SPECIAL_XBMC_DIR = translatePath( "Q:\\" ) SPECIAL_HOME_DIR = translatePath( "special://home/" )if PLATFORM_MAC or not os.path.isdir( SPECIAL_HOME_DIR ): SPECIAL_HOME_DIR = translatePath( "U:\\" ) SPECIAL_TEMP_DIR = translatePath( "special://temp/" )if PLATFORM_MAC or not os.path.isdir( SPECIAL_TEMP_DIR ): SPECIAL_TEMP_DIR = translatePath( "Z:\\" ) SPECIAL_PROFILE_DIR = translatePath( "special://profile/" )if PLATFORM_MAC or not os.path.isdir( SPECIAL_PROFILE_DIR ): SPECIAL_PROFILE_DIR = translatePath( "P:\\" ) SPECIAL_MASTERPROFILE_DIR = translatePath( "special://masterprofile/" )if PLATFORM_MAC or not os.path.isdir( SPECIAL_MASTERPROFILE_DIR ): SPECIAL_MASTERPROFILE_DIR = translatePath( "T:\\" ) SPECIAL_XBMC_HOME = ( SPECIAL_HOME_DIR, SPECIAL_XBMC_DIR )[ ( os.environ.get( "OS", "xbox" ).lower() == "xbox" ) ] XBMC_IS_HOME = SPECIAL_HOME_DIR == SPECIAL_XBMC_DIR SPECIAL_SCRIPT_DATA = os.path.join( SPECIAL_PROFILE_DIR, "script_data", scriptname )if not os.path.isdir( SPECIAL_SCRIPT_DATA ): os.makedirs( SPECIAL_SCRIPT_DATA )
(Python):import xbmc # Quit Quit XBMC (same as XBMC.Dashboard on Xbox) # Suspend Suspends (S3 / S1 depending on bios setting) the System (not working on Xbox due to hardware limitations)# Hibernate Hibernate (S5) the System (not working on Xbox due to hardware limitations)# Powerdown Powerdown system# Minimize Minimize XBMC to tools barstate = { "quit": 0, "suspend": 1, "hibernate": 2, "powerdown": 4, "minimize": 5 } # print current user setting shutdownstateuser_state = xbmc.executehttpapi( "GetGuiSetting(0;system.shutdownstate)" ).replace( "<li>", "" )print user_state# force setting shutdownstate to minimizeprint xbmc.executehttpapi( "SetGUISetting(0;system.shutdownstate;%i)" % state[ "minimize" ] ).replace( "<li>", "" )# print forced setting shutdownstateprint xbmc.executehttpapi( "GetGuiSetting(0;system.shutdownstate)" ).replace( "<li>", "" ) # XBMC.ShutDown Trigger default Shutdown action defined in System Settings,# Default Powerdown on Xbox and Quit on Linux / OSX / Windowsxbmc.shutdown() # replace preference user setting shutdown stateprint xbmc.executehttpapi( "SetGUISetting(0;system.shutdownstate;%i)" % int( user_state ) ).replace( "<li>", "" )
(Python):import xbmc xbmc.executebuiltin( "XBMC.Minimize()" )
(Python):import os folder = os.getcwd().replace(';','') def del_all_files_dirs(folder): for root, dirs, files in os.walk(folder, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) os.rmdir(folder) print '%s deleted'%folder for root, dirs, files in os.walk(folder , topdown=False): for name in dirs: print 'entering %s ...'%os.path.join(root, name) if '.svn' in name: del_all_files_dirs(os.path.join(root,name)) print 'Well done'
(Python):import osimport string def replaces( source, search_for, replace_with ): # set temporary files back = os.path.splitext( source )[ 0 ] + ".bak" temp = os.path.splitext( source )[ 0 ] + ".tmp" # remove temp file if exists try: os.remove( temp ) except os.error: pass # open source and temp file fi = open( source ) fo = open( temp, "w" ) # read lines of source file for line in fi.readlines(): # temp file, write line with replaced str fo.write( string.replace( line, search_for, replace_with ) ) # end replace close source and temp file fi.close() fo.close() # remove backup file if exists try: os.remove( back ) except os.error: pass # now rename original file into backup os.rename( source, back ) # and rename temp into new source os.rename( temp, source ) source_file = "test_replaces.xml"search_for = "Salut"replace_with = "Bonjour" replaces( source_file, search_for, replace_with )
(Python):def splitlist( iterable, start=0, step=30, end=0 ): """Return a list containing an slice of iterable. start (!) defaults to 0.; step is split index, (!) defaults to 30.; end (!) defaults to 0. For example, splitlist(range(4)) returns [[0, 1, 2, 3]]. """ try: splited = [] if end <= 0: end = len( iterable ) for index in xrange( step, end, step ): splited.append( iterable[ start:index ] ) start = index splited.append( iterable[ start:end ] ) return splited except: from traceback import print_exc print_exc() return [ iterable ]
(Python):import stringmaliste = list( string.printable )print malisteprint # splitlist( iterable, start=0, step=30, end=0 ) )splited = splitlist( maliste ) print "Nombre total d'items", len( maliste ) print "Nombre de listes", len( splited ) for count, liste in enumerate( splited ): print "liste #", count+1 print len( liste ), liste print""" >>> ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~', ' ', '\t', '\n', '\r', '\x0b', '\x0c'] Nombre total d'items 100Nombre de listes 4liste # 130 ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't'] liste # 230 ['u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X'] liste # 330 ['Y', 'Z', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`'] liste # 410 ['{', '|', '}', '~', ' ', '\t', '\n', '\r', '\x0b', '\x0c'] >>> """
(Python):from BeautifulSoup import BeautifulStoneSoup soup = BeautifulStoneSoup((open(os.path.join(CACHEDIR, XMLFile), 'r')).read())cat_scrapers = soup.find("scrapers") if cat_scrapers != None: for item in cat_scrapers.findAll("entry"): if hasattr(item.title,'string'): if item.title.string != None: title = item.title.string.encode("cp1252") if hasattr(item.version,'string'): if item.version.string != None: version = item.version.string.encode("utf-8") if hasattr(item.lang,'string'): if item.lang.string != None: language = item.lang.string.encode("utf-8") if hasattr(item.date,'string'): if item.date.string != None: date = item.date.string.encode("cp1252") if hasattr(item.previewvideourl,'string'): if item.previewvideourl.string != None: previewVideoURL = item.previewvideourl.string.encode("utf-8")
(Python):import elementtree.ElementTree as ET elems = ET.parse( open( os.path.join( CACHEDIR, XMLFile ), "r" ) ).getroot()cat_scrapers = elems.find( "scrapers" ).findall( "entry" ) for item in cat_scrapers: title = item.findtext( "title" ) version = item.findtext( "version" ) language = item.findtext( "lang" ) date = item.findtext( "date" ) added = item.findtext( "added" ) previewVideoURL = item.findtext( "previewVideoURL" )