开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

乘着船/python-for-android

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (22)
标签 (20)
master
develop
release-2024年01月21日
Pillow_post_get_bbox
release-2022年12月20日
release-2022年09月04日
release-2020年06月02日
release-2020年04月29日
release-2020年03月30日
develop-merge-master-2
release-2020年04月01日
release-2019年10月06日
feature/entry_point_from_getextra
release-2019年08月09日
release-2019年07月08日
release-2019年06月06日
feature/add_kivent_recipes_again
dump_restore_manifest
stable
old_toolchain
v2024.01.21
v2023.09.16
v2023.05.21
v2023.02.10
v2023.01.28
v2022.12.20
v2022.09.04
v2022.07.20
v2022.03.13
v2021.09.05
v2020.06.02
v2020.04.29
v2020.03.30
v2019.10.06
v2019.08.09
v2019.07.08
v2019.06.06
0.7.0
0.6.0
0.5.3
master
分支 (22)
标签 (20)
master
develop
release-2024年01月21日
Pillow_post_get_bbox
release-2022年12月20日
release-2022年09月04日
release-2020年06月02日
release-2020年04月29日
release-2020年03月30日
develop-merge-master-2
release-2020年04月01日
release-2019年10月06日
feature/entry_point_from_getextra
release-2019年08月09日
release-2019年07月08日
release-2019年06月06日
feature/add_kivent_recipes_again
dump_restore_manifest
stable
old_toolchain
v2024.01.21
v2023.09.16
v2023.05.21
v2023.02.10
v2023.01.28
v2022.12.20
v2022.09.04
v2022.07.20
v2022.03.13
v2021.09.05
v2020.06.02
v2020.04.29
v2020.03.30
v2019.10.06
v2019.08.09
v2019.07.08
v2019.06.06
0.7.0
0.6.0
0.5.3
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (22)
标签 (20)
master
develop
release-2024年01月21日
Pillow_post_get_bbox
release-2022年12月20日
release-2022年09月04日
release-2020年06月02日
release-2020年04月29日
release-2020年03月30日
develop-merge-master-2
release-2020年04月01日
release-2019年10月06日
feature/entry_point_from_getextra
release-2019年08月09日
release-2019年07月08日
release-2019年06月06日
feature/add_kivent_recipes_again
dump_restore_manifest
stable
old_toolchain
v2024.01.21
v2023.09.16
v2023.05.21
v2023.02.10
v2023.01.28
v2022.12.20
v2022.09.04
v2022.07.20
v2022.03.13
v2021.09.05
v2020.06.02
v2020.04.29
v2020.03.30
v2019.10.06
v2019.08.09
v2019.07.08
v2019.06.06
0.7.0
0.6.0
0.5.3
logger.py 8.15 KB
一键复制 编辑 原始数据 按行查看 历史
Mikhail Zakharov 提交于 2021年01月07日 21:39 +08:00 . print recipe ENV on failure and P4A_FULL_DEBUG
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
import logging
import os
import re
import sh
from sys import stdout, stderr
from math import log10
from collections import defaultdict
from colorama import Style as Colo_Style, Fore as Colo_Fore
# monkey patch to show full output
sh.ErrorReturnCode.truncate_cap = 999999
class LevelDifferentiatingFormatter(logging.Formatter):
def format(self, record):
if record.levelno > 30:
record.msg = '{}{}[ERROR]{}{}: '.format(
Err_Style.BRIGHT, Err_Fore.RED, Err_Fore.RESET,
Err_Style.RESET_ALL) + record.msg
elif record.levelno > 20:
record.msg = '{}{}[WARNING]{}{}: '.format(
Err_Style.BRIGHT, Err_Fore.RED, Err_Fore.RESET,
Err_Style.RESET_ALL) + record.msg
elif record.levelno > 10:
record.msg = '{}[INFO]{}: '.format(
Err_Style.BRIGHT, Err_Style.RESET_ALL) + record.msg
else:
record.msg = '{}{}[DEBUG]{}{}: '.format(
Err_Style.BRIGHT, Err_Fore.LIGHTBLACK_EX, Err_Fore.RESET,
Err_Style.RESET_ALL) + record.msg
return super().format(record)
logger = logging.getLogger('p4a')
# Necessary as importlib reloads this,
# which would add a second handler and reset the level
if not hasattr(logger, 'touched'):
logger.setLevel(logging.INFO)
logger.touched = True
ch = logging.StreamHandler(stderr)
formatter = LevelDifferentiatingFormatter('%(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
info = logger.info
debug = logger.debug
warning = logger.warning
error = logger.error
class colorama_shim:
def __init__(self, real):
self._dict = defaultdict(str)
self._real = real
self._enabled = False
def __getattr__(self, key):
return getattr(self._real, key) if self._enabled else self._dict[key]
def enable(self, enable):
self._enabled = enable
Out_Style = colorama_shim(Colo_Style)
Out_Fore = colorama_shim(Colo_Fore)
Err_Style = colorama_shim(Colo_Style)
Err_Fore = colorama_shim(Colo_Fore)
def setup_color(color):
enable_out = (False if color == 'never' else
True if color == 'always' else
stdout.isatty())
Out_Style.enable(enable_out)
Out_Fore.enable(enable_out)
enable_err = (False if color == 'never' else
True if color == 'always' else
stderr.isatty())
Err_Style.enable(enable_err)
Err_Fore.enable(enable_err)
def info_main(*args):
logger.info(''.join([Err_Style.BRIGHT, Err_Fore.GREEN] + list(args) +
[Err_Style.RESET_ALL, Err_Fore.RESET]))
def info_notify(s):
info('{}{}{}{}'.format(Err_Style.BRIGHT, Err_Fore.LIGHTBLUE_EX, s,
Err_Style.RESET_ALL))
def shorten_string(string, max_width):
''' make limited length string in form:
"the string is very lo...(and 15 more)"
'''
string_len = len(string)
if string_len <= max_width:
return string
visible = max_width - 16 - int(log10(string_len))
# expected suffix len "...(and XXXXX more)"
if not isinstance(string, str):
visstring = str(string[:visible], errors='ignore')
else:
visstring = string[:visible]
return u''.join((visstring, u'...(and ',
str(string_len - visible), u' more)'))
def get_console_width():
try:
cols = int(os.environ['COLUMNS'])
except (KeyError, ValueError):
pass
else:
if cols >= 25:
return cols
try:
cols = max(25, int(os.popen('stty size', 'r').read().split()[1]))
except Exception:
pass
else:
return cols
return 100
def shprint(command, *args, **kwargs):
'''Runs the command (which should be an sh.Command instance), while
logging the output.'''
kwargs["_iter"] = True
kwargs["_out_bufsize"] = 1
kwargs["_err_to_out"] = True
kwargs["_bg"] = True
is_critical = kwargs.pop('_critical', False)
tail_n = kwargs.pop('_tail', None)
full_debug = False
if "P4A_FULL_DEBUG" in os.environ:
tail_n = 0
full_debug = True
filter_in = kwargs.pop('_filter', None)
filter_out = kwargs.pop('_filterout', None)
if len(logger.handlers) > 1:
logger.removeHandler(logger.handlers[1])
columns = get_console_width()
command_path = str(command).split('/')
command_string = command_path[-1]
string = ' '.join(['{}->{} running'.format(Out_Fore.LIGHTBLACK_EX,
Out_Style.RESET_ALL),
command_string] + list(args))
# If logging is not in DEBUG mode, trim the command if necessary
if logger.level > logging.DEBUG:
logger.info('{}{}'.format(shorten_string(string, columns - 12),
Err_Style.RESET_ALL))
else:
logger.debug('{}{}'.format(string, Err_Style.RESET_ALL))
need_closing_newline = False
try:
msg_hdr = ' working: '
msg_width = columns - len(msg_hdr) - 1
output = command(*args, **kwargs)
for line in output:
if isinstance(line, bytes):
line = line.decode('utf-8', errors='replace')
if logger.level > logging.DEBUG:
if full_debug:
stdout.write(line)
stdout.flush()
continue
msg = line.replace(
'\n', ' ').replace(
'\t', ' ').replace(
'\b', ' ').rstrip()
if msg:
if "CI" not in os.environ:
stdout.write(u'{}\r{}{:<{width}}'.format(
Err_Style.RESET_ALL, msg_hdr,
shorten_string(msg, msg_width), width=msg_width))
stdout.flush()
need_closing_newline = True
else:
logger.debug(''.join(['\t', line.rstrip()]))
if need_closing_newline:
stdout.write('{}\r{:>{width}}\r'.format(
Err_Style.RESET_ALL, ' ', width=(columns - 1)))
stdout.flush()
except sh.ErrorReturnCode as err:
if need_closing_newline:
stdout.write('{}\r{:>{width}}\r'.format(
Err_Style.RESET_ALL, ' ', width=(columns - 1)))
stdout.flush()
if tail_n is not None or filter_in or filter_out:
def printtail(out, name, forecolor, tail_n=0,
re_filter_in=None, re_filter_out=None):
lines = out.splitlines()
if re_filter_in is not None:
lines = [line for line in lines if re_filter_in.search(line)]
if re_filter_out is not None:
lines = [line for line in lines if not re_filter_out.search(line)]
if tail_n == 0 or len(lines) <= tail_n:
info('{}:\n{}\t{}{}'.format(
name, forecolor, '\t\n'.join(lines), Out_Fore.RESET))
else:
info('{} (last {} lines of {}):\n{}\t{}{}'.format(
name, tail_n, len(lines),
forecolor, '\t\n'.join([s for s in lines[-tail_n:]]),
Out_Fore.RESET))
printtail(err.stdout.decode('utf-8'), 'STDOUT', Out_Fore.YELLOW, tail_n,
re.compile(filter_in) if filter_in else None,
re.compile(filter_out) if filter_out else None)
printtail(err.stderr.decode('utf-8'), 'STDERR', Err_Fore.RED)
if is_critical or full_debug:
env = kwargs.get("_env")
if env is not None:
info("{}ENV:{}\n{}\n".format(
Err_Fore.YELLOW, Err_Fore.RESET, "\n".join(
"export {}='{}'".format(n, v) for n, v in env.items())))
info("{}COMMAND:{}\ncd {} && {} {}\n".format(
Err_Fore.YELLOW, Err_Fore.RESET, os.getcwd(), command,
' '.join(args)))
warning("{}ERROR: {} failed!{}".format(
Err_Fore.RED, command, Err_Fore.RESET))
if is_critical:
exit(1)
else:
raise
return output
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/buddygr/python-for-android.git
git@gitee.com:buddygr/python-for-android.git
buddygr
python-for-android
python-for-android
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /