def runGenericExtractProgram(self, cmdParts, splitDelimiter=": "):
     items = []
     
     # cmdparts may contain none if a utility needed for processing was not 
     # found.  For example, ID3File needs id3tool.  If it doesn't exist on the 
     # $PATH, the extractor may call the generic extract with None as the tool, 
     # which of course wouldn't work.
     if self.filename is None or cmdParts is None or cmdParts[0] is None:
         # print("Skipping generic extract program on %s; filename missing" % self.location)
         return items;
     
     try:
         pipe = subprocess.Popen(cmdParts, stdout=subprocess.PIPE,
                               stderr=None, stdin=None, 
                               shell=False)
         
         rh = pipe.stdout
         for line in rh.readlines():
             parts = line.split(splitDelimiter, 2)
             if len(parts) != 2: continue
             items.append((parts[0].strip(), parts[1].strip()))
         filetype.qClose(rh)            
         pipe.wait()
     except Exception, err:
         template = "{0} Arguments:\n{1!r}"
         message = template.format(type(err).__name__, err.args)         
         print("Failed to run generic extract program %s: %s" % (cmdParts, message))
 def cleanup(self):
     filetype.qClose(self.writehandle)
     filetype.qClose(self.fh)
             
     if self.deleteFileOnCleanup:
         os.remove(self.filename)
                     
     return True
 def getFileMagic(self):
     if self.filemagic is not None:
         return self.filemagic
     else:
         if self.filename is None:
             raise Exception, "Filemagic was missing from stream"
                     
         if filetype.FILE_UTIL:
             pipe = subprocess.Popen([filetype.FILE_UTIL, "-b", self.filename],
                                     stdout=subprocess.PIPE, stderr=None, stdin=None,
                                     shell=False)
             readhandle = pipe.stdout
             line = readhandle.readline()
             if line is not None: line = line.strip()
             filetype.qClose(readhandle)
             pipe.wait()
             return line
         else: return "Not supported"