Пример #1
0
    def set_env(self, key, value, pre=False):
        """
        Set an environment variable that is propigated to
        every frame.

        @type  key:  str
        @param key: Name of environement variable.

        @type value: str
        @param value: Value to associate with the name.

        @type pre: boolean
        @param pre: If this value is set to true, the environement
                    variable is applied pre-setshot.  The default
                    is for the environment variable to be set
                    post set shot.

        """
        if self.__env.has_key(key):
            logger.warn("Overwriting outline env var: %s, from %s to %s",
                        key, self.__env[key], value)

        if not isinstance(key, (str)):
            raise OutlineException("Invalid key type for env var: %s",
                                   type(key))

        if not isinstance(value, (str)):
            raise OutlineException("Invalid value type for env var: %s",
                                   type(value))

        self.__env[key] = (value, pre)
Пример #2
0
def load_json(json):
    """
    Parse a json repesentation of an outline file.

    @type  json: str
    @param json: A json string.

    @rtype: L{Outline}
    @return: The resulting outline object.
    """

    def decode_layer(layer):
        """
        Python 2.5.1 doesn't accept unicode strings as keyword
        arguments in class constructors.  For this reason, they
        must be converted to byte strings.
        """
        result = { }
        for k, v in layer.iteritems():
            result[str(k)] = v
        del result["module"]
        del result["name"]
        return result

    data = simplejson.loads(json)
    ol = Outline(current=True)

    if data.has_key("name"):
        ol.set_name(data["name"])
    if data.has_key("range"):
        ol.set_frame_range(data["range"])

    for layer in data["layers"]:
        try:
            # Get the fully qualified module name, foo.bar.blah
            s_module = ".".join(layer["module"].split(".")[0:-1])
            # Get the class to instantiated.
            s_class = layer["module"].split(".")[-1]

            # Import the module and instantiate the class.
            module = __import__(s_module, globals(), locals(), [s_class])
            cls =  getattr(module, s_class)
            cls(layer["name"], **decode_layer(layer))

        except KeyError:
            error = "Json error, layer missing 'name' or 'module' definition"
            raise OutlineException(error)

        except Exception, e:
            msg = "Failed to load plugin: %s , %s"
            raise OutlineException(msg % (s_class, e))
Пример #3
0
    def add_layer(self, layer):
        """Adds a new layer."""

        if not layer.get_arg("register"):
            return

        if layer in self.__layers:
            logger.info("The layer %s was already added to this outline." %
                        layer.get_name())
            return

        if self.is_layer(layer.get_name()):
            raise OutlineException("The layer %s already exists"
                                   % layer.get_name())

        self.__layers.append(layer)
        layer.set_outline(self)
        layer.after_init(self)

        try:
            if getattr(layer, "get_children"):
                for child in layer.get_children():
                    child.set_outline(self)
                    child.after_init(self)
        except AttributeError:
            pass

        # If we're in setup mode, run setup ASAP
        if self.__mode == constants.OUTLINE_MODE_SETUP:
            layer.setup()

        logger.info("adding layer: %s" % layer.get_name())
Пример #4
0
    def get_layer(self, name):
        """Return an later by name."""

        layer_map = dict([(evt.get_name(), evt) for evt in self.__layers])
        try:
            return layer_map[name]
        except Exception, e:
            raise OutlineException("invalid layer name: %s, %s" % (name, e))
Пример #5
0
    def remove_layer(self, layer):
        """Remove an existing layer."""

        if self.__mode >= constants.OUTLINE_MODE_SETUP:
            msg = "Cannot remove layers to an outline not in init mode."
            raise OutlineException(msg)

        if layer in self.__layers:
            self.__layers.remove(layer)
Пример #6
0
 def load_session(self):
     """
     Reloads the session
     """
     if is_session_path(self.get_path()):
         self.__session = Session(self)
     else:
         msg = "failed to load outline %s, not part of a session."
         raise OutlineException(msg % self.get_path())
Пример #7
0
def parse_outline_script(path):
    """
    Parse a native outline script and add any layers to
    the current outline's layer list. The current outline
    is optionally set when an outline oject is created by
    passing current=True to the constructor.

    Once the current outline is set, you can execute as many
    outline scripts as you want and the resulting layers become
    part of the current outline.

    @type  path: str
    @param path: The path to the outline file.
    """
    try:
        logger.info("parsing outline file %s" % path)
        execfile(path, {})
    except Exception, exp:
        logger.warn("failed to parse as python file, %s" % exp)
        raise OutlineException("failed to parse outline file: %s, %s" %
                               (path, exp))
Пример #8
0
def load_outline(path):
    """
    Load an outline script. The path can be either an
    outline script or serialized outline script.

    @type  path: str
    @param path: The path to the outline file. Serialized
    outline files must be named with the .yaml extension.
    Anything else is considered a python outline script.

    @rtype: L{Outline}
    @return: The resutling Outline object.
    """
    logger.info("loading outline: %s" % path)

    # The wan cores may not see this file right away
    # The avere cache will hold a negative cache for 30 seconds, extending every time it is checked
    # The local cache will cache for 30 seconds as well
    if path and not os.path.exists(path):
        logger.info(
            'Outline file does not exist, sleeping 35 seconds before checking again due to possible file cache latency.'
        )
        time.sleep(35)

    ext = os.path.splitext(path)
    if ext[1] == ".yaml" or path.find("cue_archive") != -1:
        ol = yaml.load(file(path, 'r'))
        Outline.current = ol
        if not isinstance(ol, Outline):
            raise OutlineException("The file %s did not produce "
                                   "an Outline object." % path)
    else:
        # If the file is not .yaml, assume its a python script
        ol = Outline(path=path, current=True)

    # If the script is inside of a session
    if is_session_path(path):
        ol.load_session()

    return ol
Пример #9
0
    def get_arg(self, key, default=None):
        """
        Return the value assoiciated with the given key.  Throw an
        OutlineException if the key does not exist.  If a default value
        is provided then that value is returned instead of throwing
        an OutlineException.

        If the default value is None, an OutlineException is thrown.

        @type  key:  string
        @param key: The name of the argument.

        @rtype: mixed
        @return: The value associated with the given key.
        """
        try:
            if default == None:
                return self.__args.get(key)
            else:
                return self.__args.get(key, default)
        except KeyError:
            raise OutlineException("No arg mapping exists for the value %s",
                                   key)
Пример #10
0
 def set_mode(self, mode):
     """Set the current mode of the outline."""
     if mode < self.__mode:
         raise OutlineException("You cannot go back to previous modes.")
     self.__mode = mode
Пример #11
0
    def setup(self):
        """
        Sets up the outline to run frames.

        A new session is created for the outline and setup()
        methods are run for each layer.

           - Creates a new session
           - Checks require arguments on all layers.
           - Runs tge setup() method for all layers.
           - Serializes outline structure into the session.
           - Sets the outline state to READY.

        """
        if self.__mode >= constants.OUTLINE_MODE_SETUP:
            raise OutlineException("This outline is already setup.")

        self.setup_depends()

        self.__mode = constants.OUTLINE_MODE_SETUP
        self.__session = Session(self)

        # Run setup() for every layer assuming the frame range
        # can be determined.  If there is no frame range, the layer
        # is not going to be launched to the cue.
        for layer in self.__layers:
            if layer.get_frame_range():
                layer.setup()

        # Remove self from the current outline.
        if Outline.current == self:
            Outline.current = None

        if self.__serialize:
            yaml_file = os.path.join(self.__session.get_path(),
                                     "outline.yaml")

            # Set a new path before serialzing the outline file.
            logger.info("setting new outline path: %s" % yaml_file)
            self.set_path(yaml_file)

            # Copy the session over to a local variable and unset
            # self.__session. We do not want the session to be
            # archived with the outline because relaunching the
            # job using the serialized outline will fail.
            session = self.__session
            self.__session = None

            # Now copy outline file in.
            logger.info("serializing outline script to session path.")
            session.put_data(os.path.basename(yaml_file), self)

            # Switch the session back in.
            self.__session = session

        elif not self.__serialize and self.get_path():
            logger.info("copying outline script to session path.")
            self.__session.put_file(self.get_path(), None, "script.outline")
        else:
            raise OutlineException("Failed to serialize outline, "
                                   "Procedural outlines must always "
                                   "use serialization.")

        # Set our new mode and save.
        self.set_mode(constants.OUTLINE_MODE_READY)
        self.__session.save()