Ejemplo n.º 1
0
    def _load(self):
        """ Load any saved data from a file """
        if not os.path.exists(self.save_file):
            return True
        saved_data = []
        try:
            savefile = open(self.save_file, 'r')
            saved_data = cPickle.load(savefile)
            savefile.close()
        except (IOError, cPickle.UnpicklingError):
            err = sys.exc_info()[1]
            self.logger.warning("Failed to load saved data: %s" % err)
            return False
        for interaction in saved_data:
            # check that shutdown wasnt called early
            if self.terminate.isSet():
                return False

            try:
                self.queue.put_nowait(interaction)
            except Full:
                self.logger.warning("Reporting: Queue is full, failed to "
                                    "load saved interaction data")
                break
        try:
            os.unlink(self.save_file)
        except OSError:
            self.logger.error("Reporting: Failed to unlink save file: %s" %
                              self.save_file)
        self.logger.info("Reporting: Loaded saved interaction data")
        return True
Ejemplo n.º 2
0
 def load_state(self):
     """ If using the builtin yum parser, load saved state from
     :attr:`cachefile`.  If using the Python yum libraries, yum
     handles caching and state and this method is a no-op."""
     if not self.use_yum:
         data = open(self.cachefile)
         (self.packages, self.deps, self.provides, self.filemap,
          self.url_map) = cPickle.load(data)
Ejemplo n.º 3
0
Archivo: Yum.py Proyecto: zenazn/bcfg2
 def load_state(self):
     """ If using the builtin yum parser, load saved state from
     :attr:`cachefile`.  If using the Python yum libraries, yum
     handles caching and state and this method is a no-op."""
     if not self.use_yum:
         data = open(self.cachefile)
         (self.packages, self.deps, self.provides,
          self.filemap, self.url_map) = cPickle.load(data)
Ejemplo n.º 4
0
    def load_state(self):
        """ Load saved state from :attr:`cachefile`.  If caching and
        state is handled by the package library, then this function
        does not need to be implemented.

        :raises: OSError - If the saved data cannot be read
        :raises: cPickle.UnpicklingError - If the saved data is corrupt """
        data = open(self.cachefile, 'rb')
        (self.pkgnames, self.deps, self.provides, self.essentialpkgs,
         self.recommends) = cPickle.load(data)
Ejemplo n.º 5
0
    def load_state(self):
        """ Load saved state from :attr:`cachefile`.  If caching and
        state is handled by the package library, then this function
        does not need to be implemented.

        :raises: OSError - If the saved data cannot be read
        :raises: cPickle.UnpicklingError - If the saved data is corrupt """
        data = open(self.cachefile, 'rb')
        (self.pkgnames, self.deps, self.provides,
         self.essentialpkgs) = cPickle.load(data)
Ejemplo n.º 6
0
    def _load(self):
        """Load any pending data from a file."""
        if not os.path.exists(self.pending_file):
            return True
        pending_data = []
        try:
            savefile = open(self.pending_file, 'r')
            pending_data = cPickle.load(savefile)
            savefile.close()
        except (IOError, cPickle.UnpicklingError):
            err = sys.exc_info()[1]
            self.logger.warning("Failed to load pending data: %s" % err)
            return False
        for (pmetadata, pdata) in pending_data:
            # check that shutdown wasnt called early
            if self.terminate.isSet():
                return False

            try:
                while True:
                    try:
                        metadata = self.core.build_metadata(pmetadata)
                        break
                    except MetadataRuntimeError:
                        pass

                    self.terminate.wait(5)
                    if self.terminate.isSet():
                        return False

                self.work_queue.put_nowait(
                    (metadata,
                     lxml.etree.XML(pdata, parser=Bcfg2.Server.XMLParser)))
            except Full:
                self.logger.warning("Queue.Full: Failed to load queue data")
                break
            except lxml.etree.LxmlError:
                lxml_error = sys.exc_info()[1]
                self.logger.error("Unable to load saved interaction: %s" %
                                  lxml_error)
            except MetadataConsistencyError:
                self.logger.error("Unable to load metadata for save "
                                  "interaction: %s" % pmetadata)
        try:
            os.unlink(self.pending_file)
        except OSError:
            self.logger.error("Failed to unlink save file: %s" %
                              self.pending_file)
        self.logger.info("Loaded pending %s data" % self.name)
        return True
Ejemplo n.º 7
0
    def _load(self):
        """Load any pending data from a file."""
        if not os.path.exists(self.pending_file):
            return True
        pending_data = []
        try:
            savefile = open(self.pending_file, 'r')
            pending_data = cPickle.load(savefile)
            savefile.close()
        except (IOError, cPickle.UnpicklingError):
            err = sys.exc_info()[1]
            self.logger.warning("Failed to load pending data: %s" % err)
            return False
        for (pmetadata, pdata) in pending_data:
            # check that shutdown wasnt called early
            if self.terminate.isSet():
                return False

            try:
                while True:
                    try:
                        metadata = self.core.build_metadata(pmetadata)
                        break
                    except MetadataRuntimeError:
                        pass

                    self.terminate.wait(5)
                    if self.terminate.isSet():
                        return False

                self.work_queue.put_nowait(
                    (metadata,
                     lxml.etree.XML(pdata, parser=Bcfg2.Server.XMLParser)))
            except Full:
                self.logger.warning("Queue.Full: Failed to load queue data")
                break
            except lxml.etree.LxmlError:
                lxml_error = sys.exc_info()[1]
                self.logger.error("Unable to load saved interaction: %s" %
                                  lxml_error)
            except MetadataConsistencyError:
                self.logger.error("Unable to load metadata for save "
                                  "interaction: %s" % pmetadata)
        try:
            os.unlink(self.pending_file)
        except OSError:
            self.logger.error("Failed to unlink save file: %s" %
                              self.pending_file)
        self.logger.info("Loaded pending %s data" % self.name)
        return True
Ejemplo n.º 8
0
    def fetch(self):
        """Fetch the next object"""
        event = None
        fmonfd = self.fmon.fileno()
        if self.fmon.pending():
            event = self.fmon.get_event()
        elif fmonfd:
            select.select([fmonfd], [], [], self.timeout)
            if self.fmon.pending():
                event = self.fmon.get_event()
        else:
            # pseudo.. if nothings pending sleep and loop
            time.sleep(self.timeout)

        if not event or event.filename == self.work_path:
            return None

        #deviate from the normal routines here we only want one event
        etype = event.code2str()
        self.debug_log("Recieved event %s for %s" % (etype, event.filename))
        if os.path.basename(event.filename)[0] == '.':
            return None
        if etype in ('created', 'exists'):
            self.debug_log("Handling event %s" % event.filename)
            payload = os.path.join(self.work_path, event.filename)
            try:
                payloadfd = open(payload, "rb")
                interaction = cPickle.load(payloadfd)
                payloadfd.close()
                os.unlink(payload)
                return interaction
            except IOError:
                self.logger.error("Failed to read payload: %s" %
                                  traceback.format_exc().splitlines()[-1])
            except cPickle.UnpicklingError:
                self.logger.error("Failed to unpickle payload: %s" %
                                  traceback.format_exc().splitlines()[-1])
                payloadfd.close()
                raise TransportError
        return None
Ejemplo n.º 9
0
    def fetch(self):
        """Fetch the next object"""
        event = None
        fmonfd = self.fmon.fileno()
        if self.fmon.pending():
            event = self.fmon.get_event()
        elif fmonfd:
            select.select([fmonfd], [], [], self.timeout)
            if self.fmon.pending():
                event = self.fmon.get_event()
        else:
            # pseudo.. if nothings pending sleep and loop
            time.sleep(self.timeout)

        if not event or event.filename == self.work_path:
            return None

        #deviate from the normal routines here we only want one event
        etype = event.code2str()
        self.debug_log("Recieved event %s for %s" % (etype, event.filename))
        if os.path.basename(event.filename)[0] == '.':
            return None
        if etype in ('created', 'exists'):
            self.debug_log("Handling event %s" % event.filename)
            payload = os.path.join(self.work_path, event.filename)
            try:
                payloadfd = open(payload, "rb")
                interaction = cPickle.load(payloadfd)
                payloadfd.close()
                os.unlink(payload)
                return interaction
            except IOError:
                self.logger.error("Failed to read payload: %s" %
                    traceback.format_exc().splitlines()[-1])
            except cPickle.UnpicklingError:
                self.logger.error("Failed to unpickle payload: %s" %
                    traceback.format_exc().splitlines()[-1])
                payloadfd.close()
                raise TransportError
        return None
Ejemplo n.º 10
0
Archivo: Apt.py Proyecto: ab/bcfg2
 def load_state(self):
     data = open(self.cachefile)
     (self.pkgnames, self.deps, self.provides,
      self.essentialpkgs) = cPickle.load(data)
Ejemplo n.º 11
0
Archivo: Yum.py Proyecto: ab/bcfg2
 def load_state(self):
     if not self.use_yum:
         data = open(self.cachefile)
         (self.packages, self.deps, self.provides,
          self.filemap, self.url_map) = cPickle.load(data)
Ejemplo n.º 12
0
Archivo: Pac.py Proyecto: Bcfg2/bcfg2
 def load_state(self):
     data = open(self.cachefile, 'rb')
     (self.pkgnames, self.deps, self.provides,
      self.recommends, self.pacgroups) = cPickle.load(data)
Ejemplo n.º 13
0
Archivo: Pac.py Proyecto: ab/bcfg2
 def load_state(self):
     data = open(self.cachefile)
     self.pkgnames, self.deps, self.provides = cPickle.load(data)
Ejemplo n.º 14
0
 def load_state(self):
     data = open(self.cachefile, 'rb')
     (self.pkgnames, self.deps, self.provides, self.recommends,
      self.pacgroups) = cPickle.load(data)