Beispiel #1
0
    def get_user_id(self):
        """Get user id.

        Example:
          >>> user_profile_info = {
                        "userId": 10001136,
                        "userName": "******",
                        "platform": 2,
                        "phone": "173333333333",
                        "email": "",
                        "company": "",
                        "name": "",
                        "job": "",
                        "communicationNumber": "",
                        "softType": 2000,
                        "softStatus": 1,
                        "businessType": 1,
                        "status": 1,
                        "infoStatus": 0,
                        "accountType": 1,
                    }
        Returns: str

        """
        user_profile_info = User(self.connect).query_user_profile()
        user_id = user_profile_info.get('userId', '')
        if user_id == '':
            raise RayvisionError(1000000, r'Failed to get user number!')
        return str(user_id)
Beispiel #2
0
    def get_user_id(self):
        """Get user id.

        Example:
            user_profile_info = {
                "userId": 10001136,
                "userName": "******",
                "platform": 2,
                "phone": "173333333333",
                "email": "",
                "company": "",
                "name": "",
                "job": "",
                "communicationNumber": "",
                "softType": 2000,
                "softStatus": 1,
                "businessType": 1,
                "status": 1,
                "infoStatus": 0,
                "accountType": 1,
            }
        Returns:
            int: The ID number of the current user.

        """
        try:
            return self.user.user_id
        except KeyError:
            raise RayvisionError(1000000, 'Failed to get user number!')
Beispiel #3
0
    def __init__(self, access_id, access_key, domain='task.renderbus.com',
                 platform='4', protocol='https', local_os='windows',
                 logger=None):
        """Please note that this is API parameter initialization.

        Args:
            access_id (str): The access id of API.
            access_key (str): The access key of the API.
            domain (str, optional): The domain address of the API.
            platform (str, optional): The platform of renderFarm.
            protocol (str, optional): The requests protocol.
            local_os (str, optional): The name of current system,support
                "window" and "linux"
            logger (logging.Logger, optional): The logging logger instance.

        """
        self.logger = logger or logging.getLogger(__name__)
        self.user_info = {'local_os': local_os}
        connect = Connect(access_id, access_key, protocol, domain, platform)
        self.user = User(connect)
        self.task = Task(connect)
        self.query = Query(connect)
        self.tag = Tag(connect)
        self.env = RenderEnv(connect)
        self.project = Tag(connect)

        try:
            self._login()
        except HTTPError:
            self.logger.error('Login failed.')
            raise RayvisionError(20020, 'Login failed.')
Beispiel #4
0
def append_to_upload(files_paths, upload_path):
    """Add the asset information you need to upload to upload_info.

    Args:
        files_paths (str or list): You need to add the uploaded asset path.
        upload_path (str): Upload json path.

    """
    upload_info = check_and_read(upload_path)
    if isinstance(files_paths, str):
        files_paths = files_paths.replace("\\", "/")
        if not os.path.exists(files_paths):
            raise RayvisionError(1000004,
                                 "{} is not found".format(files_paths))

        status = check_upload_file(files_paths, upload_info)
        if status:
            return

        upload_info["asset"].append(
            {
                "local": files_paths.replace("\\", "/"),
                "server": convert_path(files_paths),
            }, )
    elif isinstance(files_paths, list):
        for files_path in files_paths:
            files_path = files_path.replace("\\", "/")
            if not os.path.exists(files_path):
                raise RayvisionError(1000004,
                                     "{} is not found".format(files_path))

            status = check_upload_file(files_path, upload_info)
            if status:
                continue

            upload_info["asset"].append({
                "local": files_path.replace("\\", "/"),
                "server": convert_path(files_path),
            })
    else:
        raise RayvisionError(
            1000003, "files_paths must be a str or list.".format(files_paths))

    json_save(upload_path, upload_info)
Beispiel #5
0
    def set_render_config(self):
        """Add the configuration of the rendering environment in task_info.

        Raises: RayvisionError
            if the software name is not supported software or if the cg_id is
                null.

        """
        self.logger.info('[Rayvision_utils set rendering configuration'
                         ' information start .....]')
        self.logger.info('INPUT:')
        self.logger.info('=' * 20)
        self.logger.info('cg_name: %s', self.render_software)
        self.logger.info('cg_version: %s', self.software_version)
        self.logger.info('plugin_config: %s', self.plugin_config)
        self.logger.info('project_name: %s', self.project_name)
        self.logger.info('=' * 20)

        try:
            cg_id = CG_SETTING[self.render_software]
        except KeyError:
            raise RayvisionError(
                1000000, ('Not matching the correct DCC software {},'
                          'please check again'.format(self.render_software)))

        if cg_id is None:
            raise RayvisionError(1000000, r'Please input correct cg_name!')

        self.task_info['task_info']['cg_id'] = cg_id

        if self.project_name is not None:
            project_id = self.check_and_add_project_name(self.project_name)

            self.task_info['task_info']['project_name'] = self.project_name
            self.task_info['task_info']['project_id'] = project_id

        software_config_dict = dict()
        software_config_dict['cg_name'] = self.render_software
        software_config_dict['cg_version'] = self.software_version
        software_config_dict['plugins'] = self.plugin_config
        self.task_info['software_config'] = software_config_dict

        self.logger.info('[Rayvision_utils set rendering configuration'
                         'information end .....]')
Beispiel #6
0
    def is_scene_have_error(self):
        """Check the scene.

        Determine whether the scene has an error based on the number of
        serious errors.

        Raises:
            RayvisionError: There is a problem with the scene.

        """
        if self.errors_number > 0:
            return_message = (
                r'There are {0} errors. error_warn_info_list:{1}'.format(
                    self.errors_number, self.error_warn_info_list))
            # Analysis completed with errors.
            raise RayvisionError(1000000, return_message)
Beispiel #7
0
    def check_task_info(self, task_info):
        """Check and add the required parameter information."""
        if not task_info:
            raise RayvisionError(2000, "task info can't be empty.")

        task_id = task_info["task_info"].get("task_id", None)
        user_id = task_info["task_info"].get("user_id", None)
        project_id = task_info["task_info"].get("project_id", None)
        if not bool(task_id):
            task_info["task_info"]["task_id"] = str(self.api.task._generate_task_id())
        if not bool(user_id):
            task_info["task_info"]["user_id"] = str(self.api.get_user_id())
        if not bool(project_id):
            if task_info["task_info"].get("project_name"):
                project_id = str(self.api.check_and_add_project_name(task_info["task_info"]["project_name"]))
            else:
                project_id = "0"
            task_info["task_info"]["project_id"] = project_id
        return task_info
Beispiel #8
0
    def get_task_id(self):
        """Get task id.

        Example::

            task_id_info = {
                    "taskIdList": [1658434],
                    "aliasTaskIdList": [2W1658434],
                    "userId": 100093088
                }

        Returns: str

        """
        task_id_info = Task(self.connect).create_task(count=1,
                                                      out_user_id=None)
        task_id = task_id_info.get('taskIdList', [''])[0]
        if task_id == '':
            # Task ID creating failed
            raise RayvisionError(1000000, r'Failed to create task number!')
        return str(task_id)
Beispiel #9
0
def append_to_task(additional_info, task_path, cover=True):
    """Add new field information in task_info.

    Args:
        additional_info (dict): Information that needs to be added
        cover (bool): If the added field already exists, whether to overwrite it,
            The default is overwrite.

    """
    task_info = check_and_read(task_path)
    task_append_info = task_info.get("additional_info", {})
    if not cover:
        for append_key in additional_info:
            if append_key in task_append_info.keys():
                raise RayvisionError(
                    1000002,
                    "{} already exists, cannot be added".format(append_key))
    else:
        task_append_info.update(additional_info)
        task_info["additional_info"] = task_append_info

    json_save(task_path, task_info)
Beispiel #10
0
    def _generate_task_id(self):
        """Get task id.

        Example::

            task_id_info = {
                    "taskIdList": [1658434],
                    "aliasTaskIdList": [2W1658434],
                    "userId": 100093088
                }

        Returns:
            int: The ID number of the task.

        """
        if not self._has_submit and self._task_id:
            return self._task_id
        task_id_info = self.create_task(count=1, out_user_id=None)
        task_id_list = task_id_info.get("taskIdList")
        if not task_id_list:
            raise RayvisionError(1000000, 'Failed to create task number!')
        self._task_id = task_id_list[0]
        self._has_submit = False
        return self._task_id
Beispiel #11
0
    def __init__(self,
                 access_id=None,
                 access_key=None,
                 domain='task.renderbus.com',
                 platform='4',
                 protocol='https',
                 logger=None,
                 log_folder=None,
                 log_name=None,
                 log_level="DEBUG",
                 ):
        """Please note that this is API parameter initialization.

        Args:
            access_id (str, optional): The access id of API.
            access_key (str, optional): The access key of the API.
            domain (str, optional): The domain address of the API.
            platform (str, optional): The platform of renderFarm.
            protocol (str, optional): The requests protocol.
            logger (logging.Logger, optional): The logging logger instance.
            log_folder (str, optional): Custom log save location.
            log_name (str): Custom log file name.
            log_level (str, optional): Custom log level, default "DEBUG".
        """
        self.logger = logger
        if not self.logger:
            init_logger(PACKAGE_NAME, log_folder, log_name)
            self.logger = logging.getLogger(__name__)
            self.logger.setLevel(level=log_level.upper())

        access_id = access_id or os.getenv("RAYVISION_API_ACCESS_ID")
        if not access_id:
            raise TypeError(
                'Required "access_id" not specified. Pass as argument or set '
                'in environment variable RAYVISION_API_ACCESS_ID.'
            )
        access_key = access_key or os.getenv("RAYVISION_API_KEY")
        if not access_id:
            raise TypeError(
                'Required "access_key" not specified. Pass as argument or set '
                'in environment variable RAYVISION_API_KEY.'
            )

        self._connect = Connect(access_id,
                                access_key,
                                protocol,
                                domain,
                                platform,
                                logger=self.logger)

        # Initial all api instance.
        self.user = UserOperator(self._connect)
        self.task = TaskOperator(self._connect)
        self.query = QueryOperator(self._connect)
        self.tag = TagOperator(self._connect)
        self.env = RenderEnvOperator(self._connect)
        self.transmit = TransmitOperator(self._connect)

        try:
            self._login()
        except HTTPError:
            raise RayvisionError(20020, 'Login failed.')
Beispiel #12
0
def check_and_read(json_path):
    files_paths = json_path.replace("\\", "/")
    if not os.path.exists(files_paths):
        raise RayvisionError(1000004, "{} is not found".format(files_paths))
    return json_load(files_paths)