Ejemplo n.º 1
0
    def refresh(self, check_inconsistencies=False, first_time=True):
        """Tries to check if it's been done a new recording. If true, it updates the repository with the new recordings.
        If error, logs it appropriately.
        Args:
            check_inconsistencies (bool): True if inconsistencies are going to be checked. False otherwise.
            first_time (bool): True if Galicaster is refreshing its repository while starting. False otherwise. Used to avoid logging that the mediapackages are added the first time.
        """
        if self.logger:
            self.logger.info("Refreshing repository list")

        if self.root != None:
            for folder in os.listdir(self.root):
                if folder in self.repo_dirs:
                    continue
                try:
                    manifest = os.path.join(self.root, folder, "manifest.xml")
                    if os.path.exists(manifest):
                        new_mp = deserializer.fromXML(manifest, self.logger)

                        if not self.__contains__(new_mp.getIdentifier()):
                            self.__list[new_mp.getIdentifier()] = new_mp
                            if check_inconsistencies:
                                self.repair_inconsistencies(new_mp)
                            self.logger and not first_time and self.logger.info("Added new MP {} of folder {}".format(new_mp.getIdentifier(), new_mp.getURI()))
                        else:
                            self.logger and first_time and self.logger.warning("Found duplicated MP id {} so ignoring {}".format(new_mp.getIdentifier(), new_mp.getURI()))
                except Exception as exc:
                    if self.logger:
                        self.logger.error('Error in deserializer {0}. Exception: {1}'.format(folder, exc))
Ejemplo n.º 2
0
 def refresh(self, check_inconsistencies=False):
     self.__list.clear()
     if self.root != None:
         for folder in os.listdir(self.root):
             if folder in self.repo_dirs:
                 continue
             try:
                 manifest = os.path.join(self.root, folder, "manifest.xml")
                 if os.path.exists(manifest):
                     new_mp = deserializer.fromXML(manifest)
                     self.__list[new_mp.getIdentifier()] = new_mp
                     if check_inconsistencies: self.repair_inconsistencies(new_mp)
             except:
                 logger.error('Error in deserializer {0}'.format(folder))
Ejemplo n.º 3
0
 def refresh(self, check_inconsistencies=False):
     self.__list.clear()
     if self.root != None:
         for folder in os.listdir(self.root):
             if folder == self.attach_dir:
                 continue
             try:
                 manifest = os.path.join(self.root, folder, "manifest.xml")
                 if os.path.exists(manifest):
                     new_mp = deserializer.fromXML(manifest)
                     self.__list[new_mp.getIdentifier()] = new_mp
                     if check_inconsistencies: self.repair_inconsistencies(new_mp)
             except:
                 logger.error('Error in deserializer {0}'.format(folder))
Ejemplo n.º 4
0
    def __refresh(self, check_inconsistencies=False):
        if self.logger:
            self.logger.info("Creating repository from {}".format(self.root))

        self.__list.clear()
        if self.root != None:
            for folder in os.listdir(self.root):
                if folder in self.repo_dirs:
                    continue
                try:
                    manifest = os.path.join(self.root, folder, "manifest.xml")
                    if os.path.exists(manifest):
                        new_mp = deserializer.fromXML(manifest, self.logger)
                        self.__list[new_mp.getIdentifier()] = new_mp
                        if check_inconsistencies: self.repair_inconsistencies(new_mp)
                except:
                    if self.logger:
                        self.logger.error('Error in deserializer {0}'.format(folder))
Ejemplo n.º 5
0
    def recover_recording(self):
        """Tries to recover a crashed mediapackage form the manifest.xml associated.
        If any exception occurs while recovering recording, calls save_crash_recording method.
        """
        try:
            self.logger and self.logger.info(
                "Trying to recover the crashed recording")

            ca_prop = None
            info = {}
            # Read info.json
            with open(os.path.join(self.get_rectemp_path(), "info.json"),
                      'r') as handle:
                info = json.load(handle)

            # Copy the capture agent properties from the original mediapackage folder (for scheduled recordings)
            if info['uri']:
                ca_prop = os.path.join(
                    info['uri'],
                    "org.opencastproject.capture.agent.properties")
                if os.path.exists(ca_prop):
                    with open(ca_prop, 'rb') as fsrc:
                        dst = os.path.join(
                            self.get_rectemp_path(),
                            "org.opencastproject.capture.agent.properties")
                        with open(dst, 'wb') as fdst:
                            self.logger.info("Copying file {} to {}".format(
                                ca_prop, dst))
                            shutil.copyfileobj(fsrc, fdst)
                            os.fsync(fdst)

            # Create MP
            mp = deserializer.fromXML(
                os.path.join(self.get_rectemp_path(), "manifest.xml"),
                self.logger)

            # Set saved data
            mp.setFromDict(info)
            # Overwrite some data
            mp.status = 4
            mp.setTitle("Recovered - " + mp.getTitle())
            if not mp.getIdentifier():
                mp.setNewIdentifier()

            # Change the filenames
            folder = self.add_after_rec(mp,
                                        info['tracks'],
                                        mp.getDuration(),
                                        add_catalogs=True,
                                        remove_tmp_files=False)
            try:
                mp.discoverDuration()
            except Exception as exc:
                self.logger and self.logger.error(
                    "Error trying to get duration of MP {}: {}".format(
                        mp.getIdentifier(), exc))
            serializer.save_in_dir(mp, self.logger, folder)
            self.logger and self.logger.info(
                "Crashed recording added to the repository")

            # Copy the capture agent properties from the original mediapackage folder (for scheduled recordings)
            if ca_prop and os.path.exists(ca_prop):
                with open(ca_prop, 'rb') as fsrc:
                    dst = os.path.join(
                        mp.getURI(),
                        "org.opencastproject.capture.agent.properties")
                    with open(dst, 'wb') as fdst:
                        self.logger.info("Copying file {} to {}".format(
                            ca_prop, dst))
                        shutil.copyfileobj(fsrc, fdst)
                        os.fsync(fdst)

            # Check if there is some extra files and move it to the mediapackage folder
            mp_dir = mp.getURI()
            for temp_file in os.listdir(self.get_rectemp_path()):
                full_path = os.path.join(self.get_rectemp_path(), temp_file)
                if os.path.isfile(full_path) and os.path.getsize(
                        full_path) and not "screenshot.jpg" in temp_file:
                    os.rename(full_path, os.path.join(mp_dir, temp_file))

        except Exception as exc:
            self.logger and self.logger.error(
                "There was an error trying to recover a recording: {}. Saving crashed recording to a rectemp folder..."
                .format(exc))
            self.save_crash_recordings()

        return
Ejemplo n.º 6
0
    def recover_recording(self):
        """Tries to recover a crashed mediapackage form the manifest.xml associated.
        If any exception occurs while recovering recording, calls save_crash_recording method.
        """
        try:
            self.logger and self.logger.info("Trying to recover the crashed recording")

            ca_prop = None
            info = {}
            # Read info.json
            with open(os.path.join(self.get_rectemp_path(), "info.json"), 'r') as handle:
                info = json.load(handle)

            # Copy the capture agent properties from the original mediapackage folder (for scheduled recordings)
            if info['uri']:
                ca_prop = os.path.join(info['uri'], "org.opencastproject.capture.agent.properties")
                if os.path.exists(ca_prop):
                    with open(ca_prop, 'rb') as fsrc:
                        dst = os.path.join(self.get_rectemp_path(), "org.opencastproject.capture.agent.properties")
                        with open(dst, 'wb') as fdst:
                            self.logger.info("Copying file {} to {}".format(ca_prop, dst))
                            shutil.copyfileobj(fsrc, fdst)
                            os.fsync(fdst)

            # Create MP
            mp = deserializer.fromXML(os.path.join(self.get_rectemp_path(), "manifest.xml"), self.logger)

            # Set saved data
            mp.setFromDict(info)
            # Overwrite some data
            mp.status = 4
            mp.setTitle("Recovered - " + mp.getTitle())
            if not mp.getIdentifier():
                mp.setNewIdentifier()

            # Change the filenames
            folder = self.add_after_rec(mp, info['tracks'], mp.getDuration(), add_catalogs=True, remove_tmp_files=False)
            try:
                mp.discoverDuration()
            except Exception as exc:
                self.logger and self.logger.error("Error trying to get duration of MP {}: {}".format(mp.getIdentifier(), exc))
            serializer.save_in_dir(mp, self.logger, folder)
            self.logger and self.logger.info("Crashed recording added to the repository")

            # Copy the capture agent properties from the original mediapackage folder (for scheduled recordings)
            if ca_prop and os.path.exists(ca_prop):
                with open(ca_prop, 'rb') as fsrc:
                    dst = os.path.join(mp.getURI(), "org.opencastproject.capture.agent.properties")
                    with open(dst, 'wb') as fdst:
                        self.logger.info("Copying file {} to {}".format(ca_prop, dst))
                        shutil.copyfileobj(fsrc, fdst)
                        os.fsync(fdst)


            # Check if there is some extra files and move it to the mediapackage folder
            mp_dir = mp.getURI()
            for temp_file in os.listdir(self.get_rectemp_path()):
                full_path = os.path.join(self.get_rectemp_path(), temp_file)
                if os.path.isfile(full_path) and os.path.getsize(full_path) and not "screenshot.jpg" in temp_file:
                    os.rename(full_path, os.path.join(mp_dir, temp_file))


        except Exception as exc:
            self.logger and self.logger.error("There was an error trying to recover a recording: {}. Saving crashed recording to a rectemp folder...".format(exc))
            self.save_crash_recordings()

        return