Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
4916c080
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4916c080
编写于
4月 04, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add command line utils
上级
445310c0
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
107 addition
and
0 deletion
+107
-0
paddlehub/commands/cml_utils.py
paddlehub/commands/cml_utils.py
+107
-0
未找到文件。
paddlehub/commands/cml_utils.py
0 → 100644
浏览文件 @
4916c080
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
color_dict
=
{
"white"
:
"
\033
[1;37m%s
\033
[0m"
,
"black"
:
"
\033
[30m%s
\033
[0m"
,
"dark_gray"
:
"
\033
[1;30m%s
\033
[0m"
,
"light_gray"
:
"
\033
[0;37m%s
\033
[0m"
,
"blue"
:
"
\033
[0;34m%s
\033
[0m"
,
"light_blue"
:
"
\033
[1;34m%s
\033
[0m"
,
"green"
:
"
\033
[0;32m%s
\033
[0m"
,
"light_green"
:
"
\033
[1;32m%s
\033
[0m"
,
"cyan"
:
"
\033
[0;36m%s
\033
[0m"
,
"light_cyan"
:
"
\033
[1;36m%s
\033
[0m"
,
"red"
:
"
\033
[0;31m%s
\033
[0m"
,
"light_red"
:
"
\033
[1;31m%s
\033
[0m"
,
"purple"
:
"
\033
[0;35m%s
\033
[0m"
,
"light_purple"
:
"
\033
[1;35m%s
\033
[0m"
,
"brown"
:
"
\033
[0;33m%s
\033
[0m"
,
"yellow"
:
"
\033
[1;33m%s
\033
[0m"
}
def
colorful_text
(
color
,
text
):
if
color
not
in
color_dict
:
color
=
color_dict
[
'blue'
]
else
:
color
=
color_dict
[
color
]
return
color
%
text
class
TablePrinter
:
def
__init__
(
self
,
titles
,
placeholders
):
self
.
titles
=
titles
self
.
placeholders
=
placeholders
self
.
text
=
"
\n
"
self
.
add_title
()
def
add_horizontal_line
(
self
):
line
=
'+'
for
value
in
self
.
placeholders
:
line
+=
'-'
*
(
value
+
2
)
+
'+'
line
+=
'
\n
'
self
.
text
+=
line
def
add_title
(
self
):
self
.
add_horizontal_line
()
title_text
=
"|"
for
index
,
title
in
enumerate
(
self
.
titles
):
title
=
colorful_text
(
"light_green"
,
title
)
_ph
=
11
title_text
+=
(
"{0:^%d}|"
%
(
self
.
placeholders
[
index
]
+
2
+
_ph
)).
format
(
title
)
title_text
+=
'
\n
'
self
.
text
+=
title_text
def
add_line
(
self
,
contents
,
colors
=
None
):
self
.
add_horizontal_line
()
max_lines
=
0
marks
=
[
False
]
*
len
(
contents
)
colors
=
[
None
]
*
len
(
contents
)
if
colors
is
None
else
colors
for
index
,
content
in
enumerate
(
contents
):
content_length
=
int
(
len
(
content
)
/
self
.
placeholders
[
index
])
if
content_length
>
0
:
marks
[
index
]
=
True
if
content_length
>
max_lines
:
max_lines
=
content_length
line
=
''
offset
=
0
for
cnt
in
range
(
max_lines
+
1
):
line
+=
'|'
for
index
,
content
in
enumerate
(
contents
):
length
=
self
.
placeholders
[
index
]
split_text
=
content
[
offset
:
offset
+
length
]
if
colors
[
index
]
and
split_text
:
split_text
=
colorful_text
(
colors
[
index
],
split_text
)
_ph
=
11
else
:
_ph
=
0
align
=
"<"
if
marks
[
index
]
else
"^"
line
+=
(
"{0:%s%d}|"
%
(
align
,
self
.
placeholders
[
index
]
+
2
+
_ph
)
).
format
(
split_text
)
line
+=
'
\n
'
offset
+=
length
self
.
text
+=
line
def
get_text
(
self
):
self
.
add_horizontal_line
()
return
self
.
text
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录