def results(self, value):
        print("Selected shot: " + value[0])
        shot_name = value[0]

        self.body = Project().get_body(shot_name)
        self.element = self.body.get_element(Asset.HIP)
        if self.element.get_last_version() >= 0:
            #check if checked out
            if self.element.is_assigned():
                assigned_user = self.element.get_assigned_user()
                username = Environment().get_user().get_username()
                if not assigned_user == username:
                    qd.error("This shot is currently checked out by " +
                             assigned_user)
                    return
            else:
                username = Environment().get_user().get_username()
                self.element.update_assigned_user(username)

            path = self.element.get_last_publish()[3]
            if path:
                hou.hipFile.load(path)

        else:
            qd.error("Nothing was cloned")
Exemple #2
0
	def __init__(self, filepath):
		'''
		creates a Body instance describing the asset or shot stored in the given filepath
		'''
		self._env = Environment()
		self._filepath = filepath
		self._pipeline_file = os.path.join(filepath, Body.PIPELINE_FILENAME)
		if not os.path.exists(self._pipeline_file):
			raise EnvironmentError('not a valid body: ' + self._pipeline_file + ' does not exist')
		self._datadict = pipeline_io.readfile(self._pipeline_file)
    def layout_comment(self, value):
        comment = value[0]
        username = Environment().get_user().get_username()
        self.element.update_app_ext(".usda")
        self.element.publish(username, self.savePath, comment,
                             self.layout_name)

        if self.element.get_last_version() == 0:
            # if it is the first publish, we have to make the referencing file as well
            # create a reference node
            ref = hou.node("/stage").createNode("reference")
            # set the values to reference the main publish file, etc.
            ref.parm("primpath").set("/layout")
            ref.parm("filepath1").set(self.element.get_last_publish()[3])
            # create a USD ROP node and connect it to the ref node
            refrop = hou.node("/stage").createNode("usd_rop")
            refrop.setInput(0, ref)
            # set the values in the ROP and save to disk alongside the main publish
            refrop.parm("lopoutput").set(
                os.path.join(self.element._filepath,
                             self.layout_name + "_ref.usda"))
            refrop.parm("enableoutputprocessor_simplerelativepaths").set(0)
            refrop.parm("execute").pressButton()
            #   this only needs to be done once since with every new publish, the file being referenced gets updated
            ref.destroy()
            refrop.destroy()
    def comment_results(self, value):
        comment = str(value)

        username = Environment().get_user().get_username()
        name = self.asset_name

        self.element.update_app_ext(".usda")
        self.element.publish(username, self.path, comment, name)
    def comment_results(self, value):
        comment = str(value)

        username = Environment().get_user().get_username()
        name = self.shot_name

        self.element.update_app_ext(".hipnc")
        self.element.publish(username, self.path, comment, name)
        self.element.update_assigned_user("")
    def comment_results(self, value):
        comment = str(value)
        path = os.path.join(self.body.get_filepath(), Asset.HDA)
        self.element = Element(path)

        username = Environment().get_user().get_username()

        name = self.fileName
        self.element.update_app_ext(".hda")
        self.element.publish(username, self.filepath, comment, name)
    def comment_results(self, value):
        comment = str(value)

        username = Environment().get_user().get_username()
        name = self.asset_name
        basePath = self.element._filepath

        #usdElem = self.element.deepcopy()

        path = os.path.join(basePath, "temp.obj")
        self.element.update_app_ext(".obj")
        self.element.publish(username, path, comment, name)

        path = os.path.join(basePath, "temp.usda")
        self.usdElem.update_app_ext(".usda")
        self.usdElem.publish(username, path, comment, name)
    def layout_results(self, value):
        layout_name = value[0]
        layout = self.project.get_layout(layout_name)
        layout_element = layout.get_element(Asset.LAYOUT)
        src = os.path.join(layout_element._filepath, layout_name + "_ref.usda")
        dst = os.path.join(self.element._filepath, self.shot_name + ".usda")

        shutil.copy(src, dst)
        pio.set_permissions(dst)

        # basically set up a fake publish since we're not doing version control on this file
        self.element._datadict[self.element.LATEST_VERSION] = 0
        timestamp = pio.timestamp()
        username = Environment().get_user().get_username()
        self.element._datadict[self.element.PUBLISHES].append((username, timestamp, "initial publish", dst))
        self.element._update_pipeline_file()

        self.open_scene_file(dst)
    def shot_comment(self, value):
        # hou.hipFile.setName('newName_v01')  #this will change the name of the file: can be versioned. So that's nice.
        comment = value
        if comment is None:
            comment = "Publish by " + \
                str(user.get_username()) + \
                '. Ask them to leave a comment next time lol'
        # FIXME: make variable more specific to shot?
        chosen_shot = self.chosen_shot
        project = Project()

        print('Selected shot name: ' + chosen_shot)
        # print(project.get_body(chosen_shot))
        shot_body = project.create_shot(chosen_shot)
        if shot_body is None:
            shot_body = project.get_shot(chosen_shot)
        if shot_body is None:
            print("Something is horribly wrong. Talk to Stephanie")
            return
        filepath = shot_body.get_filepath()
        shot_element = shot_body.get_element("hip")
        shot_element.update_app_ext(".hip")
        prev_vers = shot_element.get_last_version()
        # path = os.path.abspath(inspect.getfile(project.get_body(chosen_shot)))      #trying to get path here.
        filepath = os.path.join(shot_element._filepath, chosen_shot + ".hip")
        #
        print('file path is ', filepath)
        hou.hipFile.setName(filepath)
        src = hou.hipFile.save()
        # # hou.hipFile.saveAndIncrementFileName()      #this actually works! Dunno if I want to use it though.
        #
        # #Publish
        user = Environment().get_user()
        pipeline_io.set_permissions(src)
        # try that asset name is body name.
        dst = self.publish_element(shot_element, user, filepath, comment)
 def asset_comment(self, value):
     comment = value[0]
     username = Environment().get_user().get_username()
     self.element.publish(username, self.path, comment, self.asset_name)
    def comment_results(self, value):
        comment = str(value)
        username = Environment().get_user().get_username()

        self.element.update_app_ext(".hda")
        self.element.publish(username, self.filepath, comment, self.name)
Exemple #12
0
	def get_parent_dir():
		return Environment().get_layouts_dir()
Exemple #13
0
	def get_parent_dir():
		'''
		return the parent directory that bodies of this type are stored in
		'''
		return Environment().get_assets_dir()
Exemple #14
0
	def get_parent_dir():
		return Environment().get_sequences_dir()
Exemple #15
0
	def get_parent_dir():
		return Environment().get_shots_dir()
Exemple #16
0
class Body(object):
	'''
	Abstract class describing bodies that make up a project.
	'''
	PIPELINE_FILENAME = '.body'

	NAME = 'name'
	REFERENCES = 'references'
	DESCRIPTION = 'description'
	TYPE = 'type'
	FRAME_RANGE = 'frame_range'
	CAMERA_NUMBER = 'camera_number'

	@staticmethod
	def create_new_dict(name):
		'''
		populate a dictionary with all the fields needed to create a new body
		'''
		datadict = {}
		datadict[Body.NAME] = name
		datadict[Body.REFERENCES] = []
		datadict[Body.DESCRIPTION] = ''
		datadict[Body.TYPE] = AssetType.ASSET
		datadict[Body.FRAME_RANGE] = 0
		return datadict

	@staticmethod
	def get_parent_dir():
		'''
		return the parent directory that bodies of this type are stored in
		'''
		return Environment().get_assets_dir()

	def __init__(self, filepath):
		'''
		creates a Body instance describing the asset or shot stored in the given filepath
		'''
		self._env = Environment()
		self._filepath = filepath
		self._pipeline_file = os.path.join(filepath, Body.PIPELINE_FILENAME)
		if not os.path.exists(self._pipeline_file):
			raise EnvironmentError('not a valid body: ' + self._pipeline_file + ' does not exist')
		self._datadict = pipeline_io.readfile(self._pipeline_file)

	def __str__(self):
		name = self.get_name()
		filepath = self.get_filepath()
		type = self.get_type()

		return "<Body Object of TYPE " + str(type) + " with NAME " + str(name) + " AT " + str(filepath) + ">"

	def get_name(self):

		return self._datadict[Body.NAME]

	def get_filepath(self):
		return self._filepath

	def is_shot(self):
		if self.get_type() == AssetType.SHOT:
			return True
		else:
			return False

	def is_set(self):
		if self.get_type() == AssetType.SET:
			return True
		else:
			return False

	def is_asset(self):
		return True

	def is_tool(self):

		raise NotImplementedError('subclass must implement is_tool')

	def is_crowd_cycle(self):

		raise NotImplementedError('subclass must implement is_crowd_cycle')

	def get_description(self):

		return self._datadict[Body.DESCRIPTION]

	def get_type(self):

		return self._datadict[Body.TYPE]

	def update_type(self, new_type):

		self._datadict[Body.TYPE] = new_type
		pipeline_io.writefile(self._pipeline_file, self._datadict)

	def get_frame_range(self):

		return self._datadict[Body.FRAME_RANGE]

	def set_frame_range(self, frame_range):
		self._datadict[Body.FRAME_RANGE] = frame_range
		pipeline_io.writefile(self._pipeline_file, self._datadict)

	def update_frame_range(self, frame_range):

		self._datadict[Body.FRAME_RANGE] = frame_range
		pipeline_io.writefile(self._pipeline_file, self._datadict)

	def get_camera_number(self):
		return self._datadict[Body.CAMERA_NUMBER]

	def set_camera_number(self, num):
		self._datadict[Body.CAMERA_NUMBER] = num
		pipeline_io.writefile(self._pipeline_file, self._datadict)

	def version_prop_json(self, prop, filepath):
		files = os.listdir(filepath)

		latest_version = -1
		for file in files:
			filename, ext = os.path.splitext(file)

			if not str(ext) == ".json":
				continue
			if str(prop) not in str(filename):
				continue

			name_and_version = str(filename).split("_")
			version = name_and_version[-1]

			if int(version) > latest_version:
				latest_version = int(version)

		latest_version += 1

		return latest_version, str(latest_version)

	def get_element(self, department, name=Element.DEFAULT_NAME, force_create=False):
		'''
		get the element object for this body from the given department. Raises EnvironmentError
		if no such element exists.
		department -- the department to get the element from
		name -- the name of the element to get. Defaults to the name of the
				element created by default for each department.
		'''
		print('looking for element', name)

		element_dir = os.path.join(self._filepath, department)
		if not os.path.exists(element_dir):
			if force_create:
				try:
					self.create_element(department, name)
				except Exception as e:
					print(e)
			else:
				raise EnvironmentError('no such element: ' + element_dir + ' does not exist')

		return Element(element_dir)

	def create_element(self, department, name):
		'''
		create an element for this body from the given department and return the
		resulting element object. Raises EnvironmentError if the element already exists.
		department -- the department to create the element for
		name -- the name of the element to create
		'''
		dept_dir = os.path.join(self._filepath, department)
		if not os.path.exists(dept_dir):
			pipeline_io.mkdir(dept_dir)
		
		empty_element = Element()
		datadict = empty_element.create_new_dict(name, department, self.get_name())
		if os.path.exists(os.path.join(dept_dir, empty_element.PIPELINE_FILENAME)):
			print("element already exists: " + dept_dir)
			return None

		pipeline_io.writefile(os.path.join(dept_dir, empty_element.PIPELINE_FILENAME), datadict)
		return self.set_app_ext(department, dept_dir)

	def set_app_ext(self, department, filepath=None):
		'''
		this function sets the file extension for an element.
		'''
		element = Element(filepath)

		if department == Asset.GEO:
			element.update_app_ext(".obj")
			return element
		elif department == Asset.ANIMATION or department == Asset.CAMERA:
			element.update_app_ext(".abc")
			return element
		elif department == Asset.RIG:
			element.update_app_ext(".mb")
			return element
		else:
			return element

	def list_elements(self, department):
		'''
		return a list of all elements for the given department in this body
		'''
		subdir = os.path.join(self._filepath, department)
		if not os.path.exists(subdir):
			return []
		dirlist = os.listdir(subdir)
		elementlist = []
		for elementdir in dirlist:
			abspath = os.path.join(subdir, elementdir)
			if os.path.exists(os.path.join(abspath, Element.PIPELINE_FILENAME)):
				elementlist.append(elementdir)
		elementlist.sort()
		return elementlist

	def add_reference(self, reference):
		'''
		Add the given reference to this body. If it already exists, do nothing. If reference is not a valid
		body, raise an EnvironmentError.
		'''
		ref_asset_path = os.path.join(self._env.get_assets_dir(), reference, Body.PIPELINE_FILENAME)
		ref_shot_path = os.path.join(self._env.get_shots_dir(), reference, Body.PIPELINE_FILENAME)
		ref_crowd_path = os.path.join(self._env.get_crowds_dir(), reference, Body.PIPELINE_FILENAME)
		if not os.path.exists(ref_asset_path) and not os.path.exists(ref_shot_path) and not os.path.exists(ref_crowd_path):
			raise EnvironmentError(reference + ' is not a valid body')
		if reference not in self._datadict[Body.REFERENCES]:
			self._datadict[Body.REFERENCES].append(reference)
		pipeline_io.writefile(self._pipeline_file, self._datadict)

	def remove_reference(self, reference):
		'''
		Remove the given reference, if it exists, and return True. Otherwise do nothing, and return False.
		'''
		try:
			self._datadict[Body.REFERENCES].remove(reference)
			return True
		except ValueError:
			return False
		pipeline_io.writefile(self._pipeline_file, self._datadict)

	def update_description(self, description):

		self._datadict[Body.DESCRIPTION] = description
		pipeline_io.writefile(self._pipeline_file, self._datadict)

	def get_references(self):
		'''
		Return a list of all references for this body.
		'''
		return self._datadict[Body.REFERENCES]

	def has_relation(self, attribute, relate, value):
		'''
		Return True if this body has the given attribute and if the given relationship
		to the the given value. Return False otherwise
		'''
		if attribute not in self._datadict:
			return False
		return relate(self._datadict[attribute],value)
Exemple #17
0
	def get_parent_dir():
		return Environment().get_tools_dir()
    def comment_results(self, value):
        comment = str(value)
        username = Environment().get_user().get_username()

        self.element.update_app_ext(".hda")
        self.element.publish(username, self.tempPath, comment, self.definition.nodeTypeName())