本文整理汇总了Python中pagure.LOG.debug方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.debug方法的具体用法?Python LOG.debug怎么用?Python LOG.debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pagure.LOG
的用法示例。
在下文中一共展示了LOG.debug方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view_file
# 需要导入模块: from pagure import LOG [as 别名]
# 或者: from pagure.LOG import debug [as 别名]
def view_file(repo, identifier, filename, username=None):
""" Displays the content of a file or a tree for the specified repo.
"""
repo = pagure.lib.get_project(SESSION, repo, user=username)
if not repo:
flask.abort(404, 'Project not found')
reponame = pagure.get_repo_path(repo)
repo_obj = pygit2.Repository(reponame)
if repo_obj.is_empty:
flask.abort(404, 'Empty repo cannot have a file')
if identifier in repo_obj.listall_branches():
branchname = identifier
branch = repo_obj.lookup_branch(identifier)
commit = branch.get_object()
else:
try:
commit = repo_obj.get(identifier)
branchname = identifier
except ValueError:
if 'master' not in repo_obj.listall_branches():
flask.abort(404, 'Branch no found')
# If it's not a commit id then it's part of the filename
commit = repo_obj[repo_obj.head.target]
branchname = 'master'
if commit and not isinstance(commit, pygit2.Blob):
content = __get_file_in_tree(
repo_obj, commit.tree, filename.split('/'), bail_on_tree=True)
if not content:
flask.abort(404, 'File not found')
content = repo_obj[content.oid]
else:
content = commit
if not content:
flask.abort(404, 'File not found')
if isinstance(content, pygit2.Blob):
if content.is_binary or not pagure.lib.could_be_text(content.data):
ext = filename[filename.rfind('.'):]
if ext in (
'.gif', '.png', '.bmp', '.tif', '.tiff', '.jpg',
'.jpeg', '.ppm', '.pnm', '.pbm', '.pgm', '.webp', '.ico'):
try:
Image.open(StringIO(content.data))
output_type = 'image'
except IOError as err:
LOG.debug(
'Failed to load image %s, error: %s', filename, err
)
output_type = 'binary'
else:
output_type = 'binary'
else:
try:
lexer = guess_lexer_for_filename(
filename,
content.data
)
except (ClassNotFound, TypeError):
lexer = TextLexer()
content = highlight(
content.data,
lexer,
HtmlFormatter(
noclasses=True,
style="tango",)
)
output_type = 'file'
else:
content = sorted(content, key=lambda x: x.filemode)
output_type = 'tree'
return flask.render_template(
'file.html',
select='tree',
repo=repo,
username=username,
branchname=branchname,
filename=filename,
content=content,
output_type=output_type,
repo_admin=is_repo_admin(repo),
)
示例2: view_file
# 需要导入模块: from pagure import LOG [as 别名]
# 或者: from pagure.LOG import debug [as 别名]
def view_file(repo, identifier, filename, username=None):
""" Displays the content of a file or a tree for the specified repo.
"""
repo = pagure.lib.get_project(SESSION, repo, user=username)
if not repo:
flask.abort(404, "Project not found")
reponame = pagure.get_repo_path(repo)
repo_obj = pygit2.Repository(reponame)
if repo_obj.is_empty:
flask.abort(404, "Empty repo cannot have a file")
if identifier in repo_obj.listall_branches():
branchname = identifier
branch = repo_obj.lookup_branch(identifier)
commit = branch.get_object()
else:
try:
commit = repo_obj.get(identifier)
branchname = identifier
except ValueError:
if "master" not in repo_obj.listall_branches():
flask.abort(404, "Branch no found")
# If it's not a commit id then it's part of the filename
commit = repo_obj[repo_obj.head.target]
branchname = "master"
if isinstance(commit, pygit2.Tag):
commit = commit.get_object()
if commit and not isinstance(commit, pygit2.Blob):
content = __get_file_in_tree(repo_obj, commit.tree, filename.split("/"), bail_on_tree=True)
if not content:
flask.abort(404, "File not found")
content = repo_obj[content.oid]
else:
content = commit
if not content:
flask.abort(404, "File not found")
if isinstance(content, pygit2.Blob):
ext = filename[filename.rfind(".") :]
if ext in (
".gif",
".png",
".bmp",
".tif",
".tiff",
".jpg",
".jpeg",
".ppm",
".pnm",
".pbm",
".pgm",
".webp",
".ico",
):
try:
Image.open(StringIO(content.data))
output_type = "image"
except IOError as err:
LOG.debug("Failed to load image %s, error: %s", filename, err)
output_type = "binary"
elif not content.is_binary and pagure.lib.could_be_text(content.data):
file_content = content.data.decode("utf-8")
try:
lexer = guess_lexer_for_filename(filename, file_content)
except (ClassNotFound, TypeError):
lexer = TextLexer()
content = highlight(file_content, lexer, HtmlFormatter(noclasses=True, style="tango"))
output_type = "file"
else:
output_type = "binary"
else:
content = sorted(content, key=lambda x: x.filemode)
output_type = "tree"
return flask.render_template(
"file.html",
select="tree",
repo=repo,
username=username,
branchname=branchname,
filename=filename,
content=content,
output_type=output_type,
repo_admin=is_repo_admin(repo),
)