Example #1
0
    def _setup_shot(self):
        """Setup the shot directory."""

        project_template = os.path.join(self.PROJECTDIR, "project_template.xml")
        project_vars = os.path.join(self.PROJECTDIR, "project_vars.xml")

        if not os.path.isfile(project_template):
            return False

        # Optional
        if not os.path.isfile(project_vars):
            project_vars = None
        else:
            # The project name right now does not include \\ so query it!
            projectvars = settings.XMLSettings(project_vars)
            self.PROJECTNAME = projectvars.get("creationvars", "projectname")
        
        dq = DirQuery(project_template, project_vars)

        try:
            self.SHOTDIR = dq.get_path("shots", self.PROJECTROOT)
        except:
            self.SHOTDIR = None
            return False

        if not self.SHOTDIR.lower().startswith(self.PROJECTDIR.lower()):
            return False

        return True
Example #2
0
    def _setup_shot(self):
        """Setup the shot directory."""

        project_template = os.path.join(self.PROJECTDIR,
                                        "project_template.xml")
        project_vars = os.path.join(self.PROJECTDIR, "project_vars.xml")

        if not os.path.isfile(project_template):
            return False

        # Optional
        if not os.path.isfile(project_vars):
            project_vars = None
        else:
            # The project name right now does not include \\ so query it!
            projectvars = settings.XMLSettings(project_vars)
            self.PROJECTNAME = projectvars.get("creationvars", "projectname")

        dq = DirQuery(project_template, project_vars)

        try:
            self.SHOTDIR = dq.get_path("shots", self.PROJECTROOT)
        except:
            self.SHOTDIR = None
            return False

        if not self.SHOTDIR.lower().startswith(self.PROJECTDIR.lower()):
            return False

        self.update_shots()

        return True
Example #3
0
def shot_id_path(projectname, shotname, id_):
    """docstring for shot_id_path"""
    shot_dir = shot_path(projectname, shotname)
    shot_root_dir = shot_root_path(projectname)

    if not os.path.isdir(shot_dir):
        return ""

    shot_template = os.path.join(shot_dir, "shot_template.xml")
    shot_vars = os.path.join(shot_dir, "shot_vars.xml")

    if not os.path.isfile(shot_template) or not os.path.isfile(shot_vars):
        return ""

    dq = DirQuery(shot_template, shot_vars)
    id_path = dq.get_path(id_, shot_root_dir)

    return id_path
Example #4
0
    def create_project(self, projectname, project_dir, project_root):
        """docstring for create_project"""

        projectname_clean = projectname.replace(os.path.sep, "_")

        project_template = os.path.join(project_dir, "project_template.xml")
        project_vars = os.path.join(project_dir, "project_vars.xml")

        if not os.path.isfile(project_template):
            return (False, "Project tempalte not found.")

        # Optional
        if not os.path.isfile(project_vars):
            project_vars = None

        dq = DirQuery(project_template, project_vars)
        gen_dir = dq.get_path("generation", project_root)

        if gen_dir == "":
            return (False,
                    "'generation' tag not found in project_template.xml")

        gen_filepath = osplus.unitostr(
            os.path.join(gen_dir, projectname_clean + ".genprj"))

        #lock = self.app.UpdateLock()

        # Requires build 2013.0213
        # Create Project with Sub and Track
        proj = self.app.ProjectCreate(projectname, True)

        self.app.ProjectActivate(proj)
        sub = proj.SubGet()

        # By convention epp expects the mainsub to be named like the project
        sub.Name = projectname
        self.app.LoadSub(sub)

        # Requires Gen Build 2013.0702 or later
        proj.SaveAs(gen_filepath)

        #self.app.UpdateUnlock(lock)

        return (True, "")
Example #5
0
def project_id_path(projectname, id_):
    """docstring for shot"""

    project_root = project_root_path()
    project_dir = project_path(projectname)

    if not os.path.isdir(project_dir):
        return ""

    project_template = os.path.join(project_dir, "project_template.xml")
    project_vars = os.path.join(project_dir, "project_vars.xml")

    if not os.path.isfile(project_template) or not os.path.isfile(project_vars):
        return ""

    dq = DirQuery(project_template, project_vars)
    id_path = dq.get_path(id_, project_root)

    return id_path
Example #6
0
    def create_project(self, projectname, project_dir, project_root):
        """docstring for create_project"""

        projectname_clean = projectname.replace(os.path.sep, "_")

        project_template = os.path.join(project_dir, "project_template.xml")
        project_vars = os.path.join(project_dir, "project_vars.xml")

        if not os.path.isfile(project_template):
            return (False, "Project tempalte not found.")

        # Optional
        if not os.path.isfile(project_vars):
            project_vars = None

        dq = DirQuery(project_template, project_vars)
        gen_dir = dq.get_path("generation", project_root)

        if gen_dir == "":
            return (False, "'generation' tag not found in project_template.xml")

        gen_filepath = osplus.unitostr(os.path.join(gen_dir, projectname_clean + ".genprj"))

        #lock = self.app.UpdateLock()

        # Requires build 2013.0213 
        # Create Project with Sub and Track
        proj = self.app.ProjectCreate(projectname, True)

        self.app.ProjectActivate(proj)
        sub = proj.SubGet()

        # By convention epp expects the mainsub to be named like the project
        sub.Name = projectname
        self.app.LoadSub(sub)

        # Requires Gen Build 2013.0702 or later
        proj.SaveAs(gen_filepath)

        #self.app.UpdateUnlock(lock)

        return (True, "")
Example #7
0
def add_shot(projectname, shotname, template, gen, insertpos, clip=None):
    """docstring for add_project"""

    epp_root = osplus.get_env("EPP_ROOT")

    if not os.path.isdir(epp_root):
        return (False, "Could not find EPP ROOT directory. Set the EPP_ROOT env variable first.", )

    cur_settings = settings.XMLSettings(os.path.join(epp_root, "config.xml") )
    project_root_dir = cur_settings.get("paths", "projectdir", None)

    if project_root_dir is None:
        return (False, "Don't know the project root dir. Please set it in your config.xml first.", )

    project_dir = os.path.join(project_root_dir, projectname)

    project_template = os.path.join(project_dir, "project_template.xml")
    project_vars = os.path.join(project_dir, "project_vars.xml")
    project_shots = os.path.join(project_dir, "project_shots.xml")

    if not os.path.isfile(project_template):
        return (False, "Project Template not found.")

    # Optional
    if not os.path.isfile(project_vars):
        project_vars = None
    
    dq = DirQuery(project_template, project_vars)

    try:
        shot_root = dq.get_path("shots", project_root_dir)
    except:
        return (False, "Shot directory not found")

    if not shot_root.lower().startswith(project_dir.lower()):
        return (False, "Shot and project directories do not match.")

    shot_dir = os.path.join(shot_root, shotname)

    if os.path.isdir(shot_dir):
        return (False, "Shot folder '{0}' already exists.".format(shotname),)

    template_filepath = os.path.join(epp_root, "templates", "shot_dirs", template)
    
    if not os.path.isfile(template_filepath):
        return (False, "Template '{0}' does not exists".format(template))

    ####
    #TODO: Better off in its own module

    import lxml.etree as etree
    from lxml.etree import ElementTree
    from lxml.etree import Element, SubElement, Comment, tostring, XMLParser
    root = Element('shots')
    if os.path.isfile(project_shots):
        with open(project_shots, 'rt') as f:
            parser = XMLParser(remove_blank_text=True)
            tree = etree.parse(f, parser)
            
            if tree.find(".//shot[@name='{0}']".format(shotname)) is not None:
                return (False, "Shot '{0}' already exists in shotlist.".format(shotname),)

            root = tree.getroot()

    shot_item = SubElement(root, 'shot', name=shotname)
    shot_item.text = '"{0}"'.format(shotname)

    with open(project_shots, 'w') as f:
        f.write(tostring(root, pretty_print=True, encoding="utf-8", xml_declaration=True))

    ####

    args = {}
    args["SHOTNAME"] = shotname

    sh = StructHandler(template_filepath, shot_root, False, True, args)

    # We save all input variables for later path reconstruction
    # We don't save all env vars though
    proj_settings = settings.XMLSettings(os.path.join(shot_dir, "shot_vars.xml") )
    for key, value in args.items():
        proj_settings.set("creationvars", key, str(value))
    for key, value in sh.used_environ.items():
        proj_settings.set("creationenvars", key, str(value))
    #print(template_filepath, project_dir, False, True, args)

    # Copy the template for reference
    shutil.copy(template_filepath, os.path.join(shot_dir, "shot_template.xml"))

    ret = create_generation(projectname, shotname, project_dir, shot_dir, shot_root, gen, cur_settings, insertpos, clip)

    if ret[0]:
        return (True, '{0} successfully created.'.format(shotname))
    else:
        return (False, '{0} created, but Generation link failed.\n{1}'.format(shotname, ret[1]))