def add_project(name, template, project_format, gen): """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, name) if os.path.isdir(project_dir): return ( False, "Project folder '{0}' already exists.".format(name), ) template_filepath = os.path.join(epp_root, "templates", "project_dirs", template) if not os.path.isfile(template_filepath): return (False, "Template '{0}' does not exists".format(template)) args = project_format.to_dict("format_") args["PROJECTNAME"] = name sh = StructHandler(template_filepath, project_root_dir, 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(project_dir, "project_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(project_dir, "project_template.xml")) ret = create_generation(name, project_dir, project_root_dir, gen) if not ret[0]: return ret return (True, '{0} successfully created.'.format(name))
def import_formats(filepath, destpath): """docstring for import_formats""" with open(filepath, "r") as f: formats = f.read().decode("utf-8") formats_dict = lua.decode(formats) destdir = os.path.dirname(destpath) if not os.path.isdir(destdir): os.makedirs(destdir) formats_setting = settings.XMLSettings(destpath, root="formats") topic = "format" for name, keys in formats_dict.items(): for key, value in keys.items(): # Ignore lists like Guides if not isinstance(value, (tuple, list, dict, set)): # Only if not exists if formats_setting.get(topic, key, topic_attr={"name": name}) is None: formats_setting.set(topic, key, str(value), {"name": name}) else: pass
def install_epp(args): """docstring for install_epp""" struct_file = osplus.app_path("_templates", "install.xml") print struct_file if not os.path.isfile(struct_file): return False install_path = args['install_path'] overwrite = False if not os.path.isdir(install_path): os.makedirs(install_path) else: overwrite = raw_input("Install Directory already exists. Do you want to keep old files [yes]/no? ") or "yes" not in ("yes", "y", "true") print "Creating directory strucutre ..." sh = StructHandler(struct_file, install_path, overwrite, True, args) print "Creating config file ..." sett = settings.XMLSettings( os.path.join(install_path, "config.xml") ) return overwrite
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
def _setup(self): """ Setup the widgets """ epp_root = osplus.get_env("EPP_ROOT") if not os.path.isdir(epp_root): QMessageBox.critical( self, "Error", "Could not find EPP ROOT directory.\n{0}".format(epp_root)) return False self.settings = settings.XMLSettings( os.path.join(epp_root, "config.xml")) self.PROJECTROOT = self.settings.get("paths", "projectdir") if self.PROJECTROOT is None: QMessageBox.critical( self, "Error", "No Project Directory configured in config.xml.") return False self._setup_header(epp_root) self._setup_status() self.cmbProject.currentIndexChanged.connect(self.update_shots) self.update_project() self._setup_defaults() return True
def project_format(projectname): """docstring for project_format""" epp_root = osplus.get_env("EPP_ROOT") cur_settings = settings.XMLSettings(os.path.join(epp_root, "config.xml") ) project_root = cur_settings.get("paths", "projectdir", None) project_settings = settings.XMLSettings(os.path.join(project_root, projectname, "project_config.xml") ) fields = ("name", "width", "height", "framerate", "aspectx", "aspecty",) format_dict = {} for field in fields: format_dict[field] = project_settings.get("format", field) return format_dict
def project_root_path(): """docstring for project_root""" epp_root = osplus.get_env("EPP_ROOT") cur_settings = settings.XMLSettings(os.path.join(epp_root, "config.xml") ) project_root = cur_settings.get("paths", "projectdir", None) return project_root
def fset(self, value): if value is None: return if os.path.isfile(value): self.varset = settings.XMLSettings(value) else: self.varset = None self._varfile = value
def _setup(self): """ Setup the widgets """ epp_root = osplus.get_env("EPP_ROOT") if not os.path.isdir(epp_root): log.error("Could not find EPP ROOT directory.\n{0}".format(epp_root), True) return False self.settings = settings.XMLSettings(os.path.join(epp_root, "config.xml") ) self.PROJECTROOT = self.settings.get("paths", "projectdir") if not self.PROJECTROOT.endswith(os.path.sep): self.PROJECTROOT = self.PROJECTROOT + os.path.sep if self.PROJECTROOT is None: log.error("No Project Directory configured in config.xml.", True) return False self._setup_header(epp_root) self._setup_name_widget(epp_root) self._setup_status() # Require Generation if not self._setup_generation(): msg = "Could not establish connection with Generation. Make sure it is running." log.error(msg, True) return False # Need edit rights for this one! if not self._gen.allow_changes(True): return False if not self._setup_project(): msg = "Project directory from Generation Project invalid: {0}".format(self.PROJECTDIR) log.error(msg, True) return False if not self._setup_shot(): msg = "Project directory from Generation Project invald: {0}".format(self.PROJECTDIR) log.error(msg, True) return False # We can't work without structs if not self._setup_structs(epp_root): msg = "Could not find directory structure files in templates.\n{0}".format(os.path.join(epp_root, "templates", "shot_dirs")) log.error(msg, True) return False return True
def _setup(self): """ Setup the widgets """ epp_root = osplus.get_env("EPP_ROOT") if not os.path.isdir(epp_root): QMessageBox.critical( self, "Error", "Could not find EPP ROOT directory.\n{0}".format(epp_root)) return False self.settings = settings.XMLSettings( os.path.join(epp_root, "config.xml")) self.PROJECTROOT = self.settings.get("paths", "projectdir") if self.PROJECTROOT is None: QMessageBox.critical( self, "Error", "No Project Directory configured in config.xml.") return False self._setup_header(epp_root) self._setup_status() # Require Generation if not self._setup_generation(): msg = "Could not establish connection with Generation. Make sure it is running." log.error(msg, True) return False # Need edit rights for this one! if not self._gen.allow_changes(True): log.warning("Project locked.") return False if not self._setup_project(): msg = "Project directory from Generation Project invalid: {0}".format( self.PROJECTDIR) log.error(msg, True) return False if not self._setup_shot(): msg = "Project directory from Generation Project invald: {0}".format( self.PROJECTDIR) log.error(msg, True) return False return True
def _setup(self): """ Setup the widgets """ _fu = fu_controller() if not _fu.status(True): log.error("Fusion not running.", True) return False epp_root = osplus.get_env("EPP_ROOT") if not os.path.isdir(epp_root): log.error( "Could not find EPP ROOT directory.\n{0}".format(epp_root), True) return False self.settings = settings.XMLSettings( os.path.join(epp_root, "config.xml")) self.PROJECTROOT = self.settings.get("paths", "projectdir") if self.PROJECTROOT is None: log.error("No Project Directory configured in config.xml.", True) return False self._setup_header(epp_root) self._setup_status() self.cmbProject.currentIndexChanged.connect(self.update_shots) self.update_project() # Make sure enter does not add to combo box self.cmbName.installEventFilter(self) self.cmbProject.currentIndexChanged.connect(self._validate_path) self.cmbShot.currentIndexChanged.connect(self.update_names) self.cmbShot.currentIndexChanged.connect(self._validate_path) self.cmbName.currentIndexChanged.connect(self._validate_path) self.cmbName.lineEdit().textChanged.connect(self._validate_path) self.cmbName.lineEdit().textChanged.connect(self._get_last_version) self.spnVersion.valueChanged.connect(self._validate_path) self.butNext.clicked.connect(self._get_last_version) self._setup_defaults() self.update_names() return True
def _setup(self): """ Setup the widgets """ epp_root = osplus.get_env("EPP_ROOT") if not os.path.isdir(epp_root): QMessageBox.critical(self, "Error", "Could not find EPP ROOT directory.\n{0}".format(epp_root)) return False self.settings = settings.XMLSettings(os.path.join(epp_root, "config.xml") ) self.PROJECTROOT = self.settings.get("paths", "projectdir") if self.PROJECTROOT is None: QMessageBox.critical(self, "Error", "No Project Directory configured in config.xml.") return False self._setup_header(epp_root) self._setup_status() self.cmbProject.currentIndexChanged.connect(self.update_shots) self.update_project() # Make sure enter does not add to combo box #self.cmbName.installEventFilter(self) self.cmbProject.currentIndexChanged.connect(self._validate_path) self.cmbFormat.currentIndexChanged.connect(self._validate_path) #self.cmbShot.currentIndexChanged.connect(self.update_names) self.cmbShot.currentIndexChanged.connect(self._validate_path) self.lneName.textChanged.connect(self._validate_path) #self.cmbName.lineEdit().textChanged.connect(self._get_last_version) self.spnVersion.valueChanged.connect(self._validate_path) ret = self._setup_defaults() if not ret[0]: QMessageBox.critical(self, "Error", ret[1]) return False self._setup_formats() self.butMatch.clicked.connect(self._match_version) self.butMatchName.clicked.connect(self._match_name) return True
def create_generation(projectname, shotname, project_dir, shot_dir, shot_root, gen, cur_settings, insertpos, clip=None): """docstring for create_generation""" if not gen.status(True): return (False, "Generation not running.") epp_root = osplus.get_env("EPP_ROOT") source_filename = cur_settings.get("standin", "source", "standin.png", create=True) source_filepath = os.path.join(epp_root, "templates", "images", source_filename) if not os.path.isfile(source_filepath): return (False, "Standin not found.") do_tag = cur_settings.get("standin", "tag", "True", create=True).lower() in ['true', 'yes', '1'] # STANDIN dest = os.path.join(shot_dir, "standin.png") if do_tag: project_config = settings.XMLSettings(os.path.join(project_dir, "project_config.xml") ) width = int(project_config.get("format", "width", "1920")) height = int(project_config.get("format", "height", "1080")) aspectx = float(project_config.get("format", "aspectx", "1.0")) aspecty = float(project_config.get("format", "aspecty", "1.0")) x = float(cur_settings.get("standin", "x", "0.08", create=True)) y = 1.0-float(cur_settings.get("standin", "y", "0.51", create=True)) # Fusion Space font = cur_settings.get("standin", "font", "Lucida Sans Unicode", create=True) fontsize = float(cur_settings.get("standin", "fontsize", "0.15", create=True)) fontbold = cur_settings.get("standin", "fontbold", "False", create=True).lower() in ['true', 'yes', '1'] fontitalic = cur_settings.get("standin", "fontitalic", "False", create=True).lower() in ['true', 'yes', '1'] r = int(cur_settings.get("standin", "fontred", "255", create=True)) g = int(cur_settings.get("standin", "fontgreen", "255", create=True)) b = int(cur_settings.get("standin", "fontblue", "255", create=True)) ret = tag_image(source_filepath, dest, shotname, font, fontsize, x, y, width, height, aspectx, aspecty, r, g, b, fontbold, fontitalic) else: ret = False if not ret: # Fall back to default shutil.copy(source_filepath, dest) # Generation return gen.insert_shot(projectname, shotname, dest, shot_root, insertpos, clip)
def _setup(self): """ Setup the widgets """ epp_root = osplus.get_env("EPP_ROOT") if not os.path.isdir(epp_root): QMessageBox.critical( self, "Error", "Could not find EPP ROOT directory.\n{0}".format(epp_root)) return False self.settings = settings.XMLSettings( os.path.join(epp_root, "config.xml")) self.PROJECTROOT = self.settings.get("paths", "projectdir") if self.PROJECTROOT is None: QMessageBox.critical( self, "Error", "No Project Directory configured in config.xml.") return False self._setup_header(epp_root) self._setup_name_widget(epp_root) self._setup_formats(epp_root) self._setup_status() # Require Generation if not self._setup_generation(): QMessageBox.critical( self, "Error", "Could not establish connection with Generation. Make sure it is running." ) return False # We can't work without structs if not self._setup_structs(epp_root): QMessageBox.critical( self, "Error", "Could not find directory structure files in templates.\n{0}". format(os.path.join(epp_root, "templates", "project_dirs"))) return False return True
def _setup_formats(self, epp_root): """docstring for _setup_formats""" format_settings = settings.XMLSettings(os.path.join( epp_root, "templates", "formats.xml"), root="formats", cache=True) if len(format_settings) < 1: return self.cmbFormatTemplate.addItem("Custom") for cur_format in sorted(format_settings): if not "name" in cur_format[1].keys(): continue cur_name = cur_format[1]['name'] if cur_name.lower() == "custom": continue self.cmbFormatTemplate.addItem(cur_format[1]['name']) # For later access self.format_settings = format_settings # Events self.FORMAT_DIRTY = False self.LOCK = False self.spnWidth.valueChanged.connect(self._format_value_changed) self.spnHeight.valueChanged.connect(self._format_value_changed) self.spnFPS.valueChanged.connect(self._format_value_changed) self.spnFPS.valueChanged.connect(self._format_value_changed) self.spnAspectX.valueChanged.connect(self._format_value_changed) self.spnAspectY.valueChanged.connect(self._format_value_changed) self.cmbFormatTemplate.currentIndexChanged[str].connect( self._format_changed)
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]))
if len(selected_versions) < 1: return (False, "No versions selected.") for version in selected_versions: meta = version.Metadata(gen.frame()) path = meta['Data']['File']['Path'] mat = PAT_FILEBASENAME.findall(path) if len(mat): shotname = mat[0] gen.add_meta(version, shotname) log.info("Setting metadata of {0} to {1}".format( version.Name, shotname)) else: log.warning("Skipping " + os.path.basename(path)) return (True, "") if __name__ == '__main__': from epp.gen.controller import gen_controller epp_root = osplus.get_env("EPP_ROOT") cur_settings = settings.XMLSettings(os.path.join(epp_root, "config.xml")) patterns = cur_settings.findall("shotpattern", "pattern") gen = gen_controller() ret, msg = generate_meta(gen, patterns.values()[1]) if not ret: log.error(msg)