def uploadChanges(self, taskfile, projectname, path): task = self._retrieveTask(taskfile) ids, descriptors, modifydescriptors, contentlocatoruri, metadataprovideruri, description = self._extractParameters( task) metadataprovider = ServiceStub.MetadataProvider(metadataprovideruri) try: songlisting = shelve.open(path + "/" + projectname + '.info.dict', writeback=True) except KeyError: raise TaskerError( "Workflow error\nCould not restore configuration, make sure you follow the usage process." ) modifiedlist = self.listModified(taskfile, projectname, path).split('\n') try: uploadfile = 'uploadfile.xml.gz' self.printfunction(u"\n == Uploading ==\n") self.printfunction(u" - Generating file to upload\n") uf = gzip.GzipFile(uploadfile, 'w') uf.write("<?xml version='1.0' encoding='UTF-8'?>\n") uf.write("<UploadPools>\n") count = 0 for song in songlisting.keys(): #if it has been modified if song in modifiedlist: count += 1 self.printfunction(u"\n - Packing descriptors of: %s\n" % song) uf.write("<Song id='%s'>" % songlisting[song]) poolfile = path + "/" + song + ".pool" pool = Pool(poolfile) temppool = Pool() #Extract desired attributes for (scope, name) in modifydescriptors: temppool.InsertAttribute(pool, scope, name, scope, name) xml.dom.ext.PrettyPrint(temppool.doc.documentElement, uf) uf.write("</Song>\n") uf.write("</UploadPools>\n") uf.close() if count == 0: self.printfunction( u" - No valid song descriptor has been found. Not doing any upload\n" ) os.remove('uploadfile.xml.gz') return self.printfunction( u" - Uploading the modified descriptor file to the server\n") result = metadataprovider.UploadPackedDescriptors(uploadfile) if result != "OK": self.printfunction( u"\n - ERROR in the server when processing the file: %s\n" % result) else: self.printfunction( u" - File successfully uploaded: received %s\n" % result) #Clean! os.remove('uploadfile.xml.gz') songlisting.close() return 0 except: songlisting.close() return -1 raise TaskerError( "Upload Error\nError preparing files to upload. Maybe the files no longer exist?" )