當前位置: 首頁>>代碼示例>>Python>>正文


Python LOG.debug方法代碼示例

本文整理匯總了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),
    )
開發者ID:Sadin,項目名稱:pagure,代碼行數:92,代碼來源:repo.py

示例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),
    )
開發者ID:aavrug,項目名稱:pagure,代碼行數:95,代碼來源:repo.py


注:本文中的pagure.LOG.debug方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。