How to use the classes.logger.log.error function in classes

To help you get started, we’ve selected a few classes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OpenShot / openshot-qt / src / windows / main_window.py View on Github external
# If statement is required, as if the user hits "Cancel"
                # on the "load file" dialog, it is interpreted as trying
                # to open a file with a blank name. This could use some
                # improvement.
                if file_path != "":
                    # Prepare to use status bar
                    self.statusBar = QStatusBar()
                    self.setStatusBar(self.statusBar)

                    log.info("File not found at {}".format(file_path))
                    self.statusBar.showMessage(_("Project {} is missing (it may have been moved or deleted). It has been removed from the Recent Projects menu.".format(file_path)), 5000)
                    self.remove_recent_project(file_path)
                    self.load_recent_menu()

        except Exception as ex:
            log.error("Couldn't open project {}".format(file_path))
            QMessageBox.warning(self, _("Error Opening Project"), str(ex))

        # Restore normal cursor
        get_app().restoreOverrideCursor()
github OpenShot / openshot-qt / src / windows / preview_thread.py View on Github external
# Create an instance of a libopenshot Timeline object
            self.clip_reader = openshot.Timeline(width, height, openshot.Fraction(fps["num"], fps["den"]), sample_rate, channels, channel_layout)
            self.clip_reader.info.channel_layout = channel_layout
            self.clip_reader.info.has_audio = True
            self.clip_reader.info.has_video = True
            self.clip_reader.info.video_length = 999999
            self.clip_reader.info.duration = 999999
            self.clip_reader.info.sample_rate = sample_rate
            self.clip_reader.info.channels = channels

            try:
                # Add clip for current preview file
                new_clip = openshot.Clip(path)
                self.clip_reader.AddClip(new_clip)
            except:
                log.error('Failed to load media file into video player: %s' % path)
                return

            # Assign new clip_reader
            self.clip_path = path

            # Keep track of previous clip readers (so we can Close it later)
            self.previous_clips.append(new_clip)
            self.previous_clip_readers.append(self.clip_reader)

            # Open and set reader
            self.clip_reader.Open()
            self.player.Reader(self.clip_reader)

        # Close and destroy old clip readers (leaving the 3 most recent)
        while len(self.previous_clip_readers) > 3:
            log.info('Removing old clips from preview: %s' % self.previous_clip_readers[0])
github OpenShot / openshot-qt / src / classes / project_data.py View on Github external
if not key:
            log.warning("Cannot get empty key.")
            return None
        if not isinstance(key, list):
            key = [key]

        # Get reference to internal data structure
        obj = self._data

        # Iterate through key list finding sub-objects either by name or by an object match criteria such as {"id":"ADB34"}.
        for key_index in range(len(key)):
            key_part = key[key_index]

            # Key_part must be a string or dictionary
            if not isinstance(key_part, dict) and not isinstance(key_part, str):
                log.error("Unexpected key part type: {}".format(type(key_part).__name__))
                return None

            # If key_part is a dictionary and obj is a list or dict, each key is tested as a property of the items in the current object
            # in the project data structure, and the first match is returned.
            if isinstance(key_part, dict) and isinstance(obj, list):
                # Overall status of finding a matching sub-object
                found = False
                # Loop through each item in object to find match
                for item_index in range(len(obj)):
                    item = obj[item_index]
                    # True until something disqualifies this as a match
                    match = True
                    # Check each key in key_part dictionary and if not found to be equal as a property in item, move on to next item in list
                    for subkey in key_part.keys():
                        # Get each key in dictionary (i.e. "id", "layer", etc...)
                        subkey = subkey.lower()
github OpenShot / openshot-qt / src / classes / json_data.py View on Github external
def convert_paths_to_absolute(self, file_path, data):
        """ Convert all paths to absolute using regex """
        try:
            # Get project folder
            path_context["new_project_folder"] = os.path.dirname(file_path)
            path_context["existing_project_folder"] = os.path.dirname(file_path)
            path_context["new_project_assets"] = get_assets_path(file_path, create_paths=False)
            path_context["existing_project_assets"] = get_assets_path(file_path, create_paths=False)

            # Optimized regex replacement
            data = re.sub(path_regex, self.replace_string_to_absolute, data)

        except Exception as ex:
            log.error("Error while converting relative paths to absolute paths: %s" % str(ex))

        return data
github OpenShot / openshot-qt / src / classes / json_data.py View on Github external
""" Convert all paths relative to this filepath """
        try:
            # Get project folder
            path_context["new_project_folder"] = os.path.dirname(file_path)
            path_context["new_project_assets"] = get_assets_path(file_path, create_paths=False)
            path_context["existing_project_folder"] = os.path.dirname(file_path)
            path_context["existing_project_assets"] = get_assets_path(file_path, create_paths=False)
            if previous_path and file_path != previous_path:
                path_context["existing_project_folder"] = os.path.dirname(previous_path)
                path_context["existing_project_assets"] = get_assets_path(previous_path, create_paths=False)

            # Optimized regex replacement
            data = re.sub(path_regex, self.replace_string_to_relative, data)

        except Exception as ex:
            log.error("Error while converting absolute paths to relative paths: %s" % str(ex))

        return data
github OpenShot / openshot-qt / src / windows / main_window.py View on Github external
s = settings.get_settings()
            app.updates.save_history(app.project, s.get("history-limit"))

            # Save project to file
            app.project.save(file_path)

            # Set Window title
            self.SetWindowTitle()

            # Load recent projects again
            self.load_recent_menu()

            log.info("Saved project {}".format(file_path))

        except Exception as ex:
            log.error("Couldn't save project %s. %s" % (file_path, str(ex)))
            QMessageBox.warning(self, _("Error Saving Project"), str(ex))
github OpenShot / openshot-qt / src / classes / exceptions.py View on Github external
def ExceptionHandler(exeception_type, exeception_value, exeception_traceback):
    """Callback for any unhandled exceptions"""
    log.error('Unhandled Exception', exc_info=(exeception_type, exeception_value, exeception_traceback))

    # Build string of stack trace
    stacktrace = "Python %s" % "".join(traceback.format_exception(exeception_type, exeception_value, exeception_traceback))

    # Report traceback to webservice (if enabled)
    track_exception_stacktrace(stacktrace, "openshot-qt")
github OpenShot / openshot-qt / src / classes / json_data.py View on Github external
def read_from_file(self, file_path, path_mode="ignore"):
        """ Load JSON settings from a file """
        try:
            with open(file_path, 'r') as f:
                contents = f.read()
                if contents:
                    if path_mode == "absolute":
                        # Convert any paths to absolute
                        contents = self.convert_paths_to_absolute(file_path, contents)
                    return json.loads(contents, strict=False)
        except Exception as ex:
            msg = ("Couldn't load {} file: {}".format(self.data_type, ex))
            log.error(msg)
            raise Exception(msg)
        msg = ("Couldn't load {} file, no data.".format(self.data_type))
        log.warning(msg)
        raise Exception(msg)
github OpenShot / openshot-qt / src / windows / main_window.py View on Github external
found_track = True
                continue

        # Calculate new track number (based on gap delta)
        new_track_number = selected_layer_number
        if track_number_delta > 2:
            # New track number (pick mid point in track number gap)
            new_track_number = selected_layer_number - int(round(track_number_delta / 2.0))
        else:
            # Loop through tracks from insert point and above
            for track in reversed(sorted(all_tracks, key=itemgetter('number'))):
                if track.get("number") >= selected_layer_number:
                    existing_track = Track.get(number=track.get("number"))
                    if not existing_track:
                        # Log error and fail silently, and continue
                        log.error('No track object found with number: %s' % track.get("number"))
                        continue
                    existing_layer = existing_track.data["number"]
                    existing_track.data["number"] = existing_layer + 1000000
                    existing_track.save()

                    # Loop through clips and transitions for track, moving up to new layer
                    for clip in Clip.filter(layer=existing_layer):
                        clip.data["layer"] = int(clip.data["layer"]) + 1000000
                        clip.save()

                    for trans in Transition.filter(layer=existing_layer):
                        trans.data["layer"] = int(trans.data["layer"]) + 1000000
                        trans.save()

        # Create new track at vacated layer
        track = Track()