import os import stat import re import gnomevfs class Desktop: def __init__(self,data): self.data = data def Save(self,path,mode="none"): f = open(path + os.sep + self.data[1]+".desktop","w") f.write("[Desktop Entry]\n") f.write("Version=1.0\n") f.write("Encoding=UTF-8\n") f.write("Type=Application\n") #change name if it is index.html if self.data[3]=="index.html": f.write("Name="+self.data[1].split('.')[1]+"\n") else: f.write("Name="+self.data[3]+"\n") f.write("Resource Path="+self.data[2]+"\n") if mode=="none": f.write("Exec=lliurex-resource-player '"+self.data[2]+"'\n") f.write("Icon="+self.data[4]+"\n") f.write("TryExec=/usr/bin/lliurex-resource-player\n") if mode=="scorm": f.write("Exec=lliurex-scorm-player "+self.data[2]+"\n") #ToDo: must use current theme icon f.write("Icon=/usr/share/pixmaps/lliurex-recursos/scorm.png\n") f.write("TryExec=/usr/bin/lliurex-resource-player\n") f.close() os.chmod(path + os.sep + self.data[1]+".desktop",stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR) def Load(self,path): desktopname="" f = open(path,"r") for line in f: match = re.match("\[(?P
.*)\]",line) #if not match == None: #print "Section " + match.group("section") match = re.match("(?P.*)=(?P.*)",line) if not match==None: #print match.group("name") + " -> " + match.group("value") if match.group("name")=="Resource Path": desktopname = match.group("value") # [type , desktopname , completepath, name,iconname] self.data=("none",desktopname,"","","") f.close()