Beispiel #1
0
    def saveAs(self, fName, packed=False):
        "Create a new ballot loader and save ballots"

        extension = os.path.splitext(fName)[1][1:]
        loaderClass = getLoaderPluginClass(extension)
        if loaderClass is None:
            # If we don't know then the default is blt format
            loaderClass = getLoaderPluginClass("blt")
        self.loader = loaderClass()
        self.loader.save(self, fName, packed)
Beispiel #2
0
 def saveAs(self, fName, packed=False):
   "Create a new ballot loader and save ballots"
   
   extension = os.path.splitext(fName)[1][1:]
   loaderClass = getLoaderPluginClass(extension)
   if loaderClass is None:
     # If we don't know then the default is blt format
     loaderClass = getLoaderPluginClass("blt")
   self.loader = loaderClass()
   self.loader.save(self, fName, packed)
Beispiel #3
0
    def loadUnknown(self, fName, exclude0=True):
        "Load a file of unknown format."

        # Try the loader that claims this extension first.  If that one doesn't
        # work then we try the others.  Get the loader classes in the right order.
        extension = os.path.splitext(fName)[1][1:]
        loaderClasses = getLoaderPlugins("classes", exclude0)
        bestGuess = getLoaderPluginClass(extension, exclude0)
        if bestGuess is not None:
            loaderClasses.remove(bestGuess)
            loaderClasses.insert(0, bestGuess)

        errorMsg = "Could not load ballots from file %s." % fName

        # Try them in order
        for loaderClass in loaderClasses:
            try:
                self.loader = loaderClass()
                self.loader.load(self, fName)
            except RuntimeError((msg, )):
                errorMsg += "\n" + msg.strip()
            else:
                break
        else:
            # None of the ballot loaders succeeded so raise an exception
            if self.exceptionQueue is None:
                raise RuntimeError(errorMsg)
            else:
                self.exceptionQueue.put(errorMsg)
Beispiel #4
0
  def loadUnknown(self, fName, exclude0 = True):
    "Load a file of unknown format."
    
    # Try the loader that claims this extension first.  If that one doesn't 
    # work then we try the others.  Get the loader classes in the right order.
    extension = os.path.splitext(fName)[1][1:]
    loaderClasses = getLoaderPlugins("classes", exclude0)
    bestGuess = getLoaderPluginClass(extension, exclude0)
    if bestGuess is not None:
      loaderClasses.remove(bestGuess)
      loaderClasses.insert(0, bestGuess)

    errorMsg = "Could not load ballots from file %s." % fName
      
    # Try them in order
    for loaderClass in loaderClasses:
      try:
        self.loader = loaderClass()
        self.loader.load(self, fName)
      except RuntimeError as msg:
        errorMsg += "\n" + msg.strip()
      else:
        break
    else:
      # None of the ballot loaders succeeded so raise an exception
      if self.exceptionQueue is None:
        raise RuntimeError(errorMsg)
      else:
        self.exceptionQueue.put(errorMsg)
Beispiel #5
0
  def loadKnown(self, fName, extension=None, exclude0 = True):
    "Load a file based on its file extension."
    
    if extension is None:
      extension = os.path.splitext(fName)[1][1:]
    loaderClass = getLoaderPluginClass(extension, exclude0)
    if loaderClass is None:
      raise RuntimeError, "Do not know how to load files with extension %s." % (extension)

    self.loader = loaderClass()
    self.loader.load(self, fName)
Beispiel #6
0
    def loadKnown(self, fName, extension=None, exclude0=True):
        "Load a file based on its file extension."

        if extension is None:
            extension = os.path.splitext(fName)[1][1:]
        loaderClass = getLoaderPluginClass(extension, exclude0)
        if loaderClass is None:
            raise RuntimeError, "Do not know how to load files with extension %s." % (
                extension)

        self.loader = loaderClass()
        self.loader.load(self, fName)