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"))
def _raise_error(result): # type: (Any) -> None if not isinstance(result, dict): return code, type_, data = ( result.get("code"), result.get("type"), result.get("data", result), ) if code is None: return elif code == "1": return elif (code, type_, data) == ("2", "msg", "please login!!!"): raise exceptions.LoginError msg = cast.text(data) if six.PY2: msg = cast.binary(msg) raise ValueError(msg)
def test_dict(): assert cast.binary(dict(a=1)) == b"{'a': 1}"
def test_int(): assert cast.binary(1) == b"1"
def test_gbk(): assert cast.binary("测试", "gbk") == b'\xb2\xe2\xca\xd4'
def test_utf8(): assert cast.binary("测试", "utf-8") == b'\xe6\xb5\x8b\xe8\xaf\x95'
def test_text(): assert cast.binary("测试") == b'\xe6\xb5\x8b\xe8\xaf\x95'
def test_binary(): assert cast.binary(b"value") == b"value"