def _create_ptask_area(ptask): parent = ptask.parent if parent: parent_area = parent.area if not parent or not parent_area: parent_area = PTaskArea("") # project root parent_area.provision(ptask.name) # write a hidden file to the area to identify the type area = ptask.area ptask_type_file = os.path.join(area.path, PTaskArea._PTASK_TYPE_FILENAME) with open(ptask_type_file, 'w') as fh: fh.write(ptask.type) try: os.chmod(ptask_type_file, 0640) except Exception as e: Logger.get().warning( "Unable to set permissions for ptask type file: " + \ ptask_type_file ) return area
def cli(cls): """Execute the action from a command line context. Automatically sets the 'interactive' property to True. """ # ----- add common options # log_level option for stdout log_level_parser = argparse.ArgumentParser(add_help=False) log_level_parser.add_argument( '--log_level', choices=Logger.levels, default=Logger.log_level, help="set the stdout logging level. Choices: " + str(Logger.levels), metavar="level", type=str, ) # set the log level for stdout (parsed, remainder) = log_level_parser.parse_known_args() Logger.set_level(parsed.log_level) # parse the remaining args parser = cls.get_parser() cls.setup_cl_args(parser) kwargs = vars(parser.parse_args(remainder)) # create the instance try: instance = cls(**kwargs) except Exception as e: import traceback traceback.print_exc() cls.get_logger().critical(str(e)) return ActionRunStatus.FAILURE # because we're running on the command line, set the interactive # property to True instance.interactive = True # call the action try: instance() except Exception as e: import traceback traceback.print_exc() instance.status = ActionRunStatus.FAILURE else: instance.status = ActionRunStatus.SUCCESS return instance.status
def set_permissions(self, mode): files = os.listdir(self.path) for file_name in sorted(files): path = os.path.join(self.path, file_name) try: os.chmod(path, mode) except Exception as e: Logger.get().warning( "Unable to set permissions for path: {p}".format(p=path))
def set_permissions(self, mode): files = os.listdir(self.path) for file_name in sorted(files): path = os.path.join(self.path, file_name) try: os.chmod(path, mode) except Exception as e: Logger.get().warning( "Unable to set permissions for path: {p}".format(p=path) )
def provision(self, directory): path = os.path.join(self.path, directory) # create the directory if it doesn't exist if not os.path.exists(path): try: os.makedirs(path) except Exception as e: raise PTaskAreaError( "Unable to provision area directory: " + str(e)) # ensure the permissions are set properly try: os.chmod(path, 0770) except Exception as e: Logger.get().warning( "Unable to set permissions for ptask area provisioning: " + \ path )
def provision(self, directory): path = os.path.join(self.path, directory) # create the directory if it doesn't exist if not os.path.exists(path): try: os.makedirs(path) except Exception as e: raise PTaskAreaError("Unable to provision area directory: " + str(e)) # ensure the permissions are set properly try: os.chmod(path, 0770) except Exception as e: Logger.get().warning( "Unable to set permissions for ptask area provisioning: " + \ path )
def import_product_representation(cls, session, representation, *args, **kwargs): product = representation.product_version.product if representation.type != "ma": raise EntityError( "Don't know how to import {cat} of type {typ}".format( cat=cls.category, type=representation.type) ) repr_path = cls.get_import_file(session, product.name, product.category, representation) name = product.name instances = kwargs.get('instances', 1) instance_start = kwargs.get('instance_start', 0) exportable = kwargs.get('exportable', True) group_reference = kwargs.get('group_reference', False) entities_to_create = [] if instances == 1 and instance_start == 0: session.cmds.file( repr_path, reference=True, groupReference=group_reference, groupName=name, mergeNamespacesOnClash=True, namespace=":" ) if exportable: if group_reference: entities_to_create.append((name, name, None)) else: ref_node = session.cmds.file( repr_path, referenceNode=True, query=True) if not ref_node: Logger.get().warning( "No reference node found for " + repr_path) else: entities_to_create.append( (cls._get_top_level_ref_objs(session, ref_node), name, None)) else: for inst in range(instance_start, instance_start + instances): inst_name = name + "_" + str(inst) session.cmds.file( repr_path, reference=True, groupReference=group_reference, groupName=inst_name, mergeNamespacesOnClash=True, namespace=":" ) if exportable: if group_reference: entities_to_create.append((inst_name, name, inst)) else: ref_node = session.cmds.file( repr_path, referenceNode=True, query=True) if not ref_node: Logger.get().warning( "No reference node found for " + repr_path) else: entities_to_create.append( (cls._get_top_level_ref_objs(session, ref_node), name, inst)) entities = [] if exportable: for (obj_name, name, inst) in entities_to_create: set_name = cls.get_set_name(name, inst) session.cmds.sets(obj_name, name=set_name) entities.append(cls.get(name, session, instance=inst)) return entities
def import_product_representation(cls, session, representation, *args, **kwargs): product = representation.product_version.product if representation.type != "ma": raise EntityError( "Don't know how to import {cat} of type {typ}".format( cat=cls.category, type=representation.type)) repr_path = cls.get_import_file(session, product.name, product.category, representation) name = product.name instances = kwargs.get('instances', 1) instance_start = kwargs.get('instance_start', 0) exportable = kwargs.get('exportable', True) group_reference = kwargs.get('group_reference', False) entities_to_create = [] if instances == 1 and instance_start == 0: session.cmds.file(repr_path, reference=True, groupReference=group_reference, groupName=name, mergeNamespacesOnClash=True, namespace=":") if exportable: if group_reference: entities_to_create.append((name, name, None)) else: ref_node = session.cmds.file(repr_path, referenceNode=True, query=True) if not ref_node: Logger.get().warning("No reference node found for " + repr_path) else: entities_to_create.append( (cls._get_top_level_ref_objs(session, ref_node), name, None)) else: for inst in range(instance_start, instance_start + instances): inst_name = name + "_" + str(inst) session.cmds.file(repr_path, reference=True, groupReference=group_reference, groupName=inst_name, mergeNamespacesOnClash=True, namespace=":") if exportable: if group_reference: entities_to_create.append((inst_name, name, inst)) else: ref_node = session.cmds.file(repr_path, referenceNode=True, query=True) if not ref_node: Logger.get().warning( "No reference node found for " + repr_path) else: entities_to_create.append( (cls._get_top_level_ref_objs( session, ref_node), name, inst)) entities = [] if exportable: for (obj_name, name, inst) in entities_to_create: set_name = cls.get_set_name(name, inst) session.cmds.sets(obj_name, name=set_name) entities.append(cls.get(name, session, instance=inst)) return entities
def get_logger(cls): if not hasattr(cls, '_logger'): cls._logger = Logger.get(".".join([cls.name, cls.target_type])) return cls._logger