Exemplo n.º 1
0
    def setUp(self):
        patcher = patch('cgtwq.server.call', return_value='Testing')
        self.addCleanup(patcher.stop)

        self.call_method = patcher.start()
        self.select = cgtwq.Selection(
            cgtwq.Database('dummy_db').module('shot'), '1', '2')
Exemplo n.º 2
0
    def get_entry(cls, filename, pipeline, module="shot"):
        # type: (Text, Text, Text) -> cgtwq.Entry
        """Get entry from filename and pipeline

        Args:
            filename (str): Filename to determinate shot.
            pipeline (str): Server defined pipline name.
            module (str): Defaults to `shot`, Server defined module name.

        Returns:
            cgtwq.Entry: Entry
        """

        key = (filename, pipeline)
        if key in cls.cache:
            return cls.cache[key]

        shot = _get_shot(filename)
        database = cgtwq.Database(cls.get_database(filename))
        select = database.module(module).filter(
            (cgtwq.Field("pipeline") == pipeline) & (cgtwq.Field("shot.entity") == shot)
        )
        try:
            entry = select.to_entry()
        except ValueError:
            LOGGER.warning("Duplicated task: %s", shot)
            entry = CGTWQHelper.guess_entry(select)

        cls.cache[key] = entry

        return entry
Exemplo n.º 3
0
    def get_entry(cls, filename, pipeline, module='shot'):
        """Get entry from filename and pipeline

        Args:
            filename (str): Filename to determinate shot.
            pipeline (str): Server defined pipline name.
            module (str): Defaults to `shot`, Server defined module name.

        Returns:
            cgtwq.Entry: Entry
        """

        key = (filename, pipeline)
        if key in cls.cache:
            return cls.cache[key]

        shot = PurePath(filename).shot
        database = cgtwq.Database(cls.get_database(filename))
        select = database.module(module).filter(
            (cgtwq.Field('pipeline') == pipeline)
            & (cgtwq.Field('shot.shot') == shot))
        try:
            entry = select.to_entry()
        except ValueError:
            LOGGER.warning('Duplicated task: %s', shot)
            entry = CGTWQHelper.guess_entry(select)

        cls.cache[key] = entry

        return entry
Exemplo n.º 4
0
def _select():
    return (
        cgtwq.Database("proj_sdktest")
        .module("shot")
        .filter(
            cgtwq.Field("shot.entity") == "SDKTEST_EP01_01_sc001",
            cgtwq.Field("task.pipeline") == "合成",
        )
    )
Exemplo n.º 5
0
    def setUp(self):
        patcher = patch("cgtwq.server.call")
        self.addCleanup(patcher.stop)
        self.call_method = patcher.start()

        for i in (
            patch("cgtwq.DesktopClient.server_ip"),
            patch("cgtwq.DesktopClient.token"),
        ):
            self.addCleanup(i.stop)
            i.start()

        self.module = cgtwq.Database("dummy_db")["shot"]
Exemplo n.º 6
0
def main():
    client = cgtwq.DesktopClient()
    client.connect()
    win_unicode_console.enable()
    logging.basicConfig(
        level="INFO",
        format="%(levelname)-7s:%(name)s: %(message)s",
    )

    print("{:-^50}".format("Link 导入 v{}".format(__version__)))
    print(
        """\
所需表格格式:

| 镜头                  | 资产1   | 资产2   |
| --------------------- | ------ | ------- |
| SDKTEST_EP01_01_sc001 | asset1 | asset2 |
| SDKTEST_EP01_01_sc002 | asset1 |


必须有命名为镜头(支持别名:shot)的列,所有其他表头不为空的列将视为资产。

镜头的值为 shot.entity 字段
资产的值为 asset.entity 字段
"""
    )
    client = cgtwq.DesktopClient()
    client.connect()
    plugin_data = client.plugin.data()  # type: ignore
    db = cgtwq.Database(cast.text(plugin_data.database))  # type: ignore

    filename = filetools.ask_filename()
    if not filename:
        return
    workbook = openpyxl.load_workbook(filename)

    for i in xlsxtools.iter_workbook_as_dict(workbook, HEADER_ALIAS):
        shot = i.get("shot")
        if shot:
            _link(
                db,
                cast.text(shot),
                tuple(
                    cast.text(v)
                    for k, v in six.iteritems(i)
                    if (k and v and k != "shot")
                ),
            )
        else:
            LOGGER.warning("忽略不支持的数据: %s", cast.binary(i).decode("unicode-escape"))
Exemplo n.º 7
0
def import_data(data, database, module, module_type):
    """Import data to cgtw database.  """

    module = cgtwq.Database(database).module(module, module_type)
    errors = []
    for i in data:
        assert isinstance(i, RowData)
        try:
            select = module.filter(
                (cgtwq.Field('shot.entity') == i.shot)
                & (cgtwq.Field('pipeline') == i.pipeline))
        except ValueError:
            LOGGER.error('找不到对应条目: 行=%s, 数据库=%s, 镜头号=%s, 流程=%s',
                         i.index, database, i.shot, i.pipeline, )
            errors.append(NoEntry(i))
            continue

        try:
            _apply_on_selection(select, i)
        except ValueError:
            continue
    if errors:
        raise ImportError(errors)
Exemplo n.º 8
0
def dialog_create_dirs():
    """A dialog for create dirs from cgtwq.  """

    folder_input_name = b'输出文件夹'
    database_input_name = b'数据库'
    prefix_input_name = b'镜头名前缀限制'
    panel = nuke.Panel(b'为项目创建文件夹')
    panel.addSingleLineInput(database_input_name, 'proj_qqfc_2017')
    panel.addSingleLineInput(prefix_input_name, '')
    panel.addFilenameSearch(folder_input_name, 'E:/temp')
    confirm = panel.show()
    if not confirm:
        return

    try:
        database = panel.value(database_input_name)
        save_path = panel.value(folder_input_name)
        prefix = panel.value(prefix_input_name)

        for _ in progress(['连接CGTeamWork...', ], '创建文件夹'):
            try:
                select = cgtwq.Database(database)['shot_task'].filter(
                    cgtwq.Field('pipeline') == '合成')
            except cgtwq.IDError as ex:
                nuke.message(utf8('找不到对应条目\n{}'.format(ex)))
                return

        for name in progress(select['shot.shot'], '创建文件夹'):
            if not name or not name.startswith(prefix):
                continue
            _path = os.path.join(save_path, name)
            if not os.path.exists(_path):
                os.makedirs(_path)
        webbrowser.open(save_path)
    except CancelledError:
        LOGGER.debug('用户取消创建文件夹')
Exemplo n.º 9
0
    def setUp(self):
        patcher = patch('cgtwq.server.call', return_value='Testing')
        self.addCleanup(patcher.stop)

        self.call_method = patcher.start()
        self.task = cgtwq.Entry(cgtwq.Database('dummy_db')['shot'], '1')
Exemplo n.º 10
0
def _database():
    return cgtwq.Database("proj_sdktest")
Exemplo n.º 11
0
 def setUp(self):
     self.module = cgtwq.Database("proj_sdktest").module("shot")
Exemplo n.º 12
0
def test_list_filebox_by_pipeline():
    db = cgtwq.Database("proj_sdktest")
    (pipeline, ) = db.pipeline.filter(cgtwq.Field("entity") == "合成")
    pipeline.module
    filebox_list = db.filebox.list_by_pipeline(pipeline)
    assert filebox_list
Exemplo n.º 13
0
 def setUp(self):
     self.database = cgtwq.Database("proj_sdktest")
Exemplo n.º 14
0
def _select():
    cgtwq.update_setting()
    return cgtwq.Database('proj_mt').module('shot').select(
        'F950A26F-DD4E-E88B-88EE-9C09EF3F7695')
Exemplo n.º 15
0
    def test_to_entry(self):

        self.assertRaises(ValueError, self.select.to_entry)
        result = cgtwq.Database('test')['m'].select('1').to_entry()
        self.assertIsInstance(result, cgtwq.Entry)
Exemplo n.º 16
0
def _module():
    return cgtwq.Database("proj_sdktest").module("shot")
Exemplo n.º 17
0
 def test_getitem(self):
     database = cgtwq.Database("dummy_db")
     self.assertEqual(database.name, "dummy_db")
     result = database["shot"]
     self.assertIsInstance(result, cgtwq.Module)
     self.assertEqual(result.name, "shot")