当前位置: 首页>>代码示例>>Python>>正文


Python util.hash_file函数代码示例

本文整理汇总了Python中mozbuild.util.hash_file函数的典型用法代码示例。如果您正苦于以下问题:Python hash_file函数的具体用法?Python hash_file怎么用?Python hash_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了hash_file函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prune

    def prune(self):
        """Prune the contents of the database.

        This removes warnings that are no longer valid. A warning is no longer
        valid if the file it was in no longer exists or if the content has
        changed.

        The check for changed content catches the case where a file previously
        contained warnings but no longer does.
        """

        # Need to calculate up front since we are mutating original object.
        filenames = self._files.keys()
        for filename in filenames:
            if not os.path.exists(filename):
                del self._files[filename]
                continue

            if self._files[filename]["hash"] is None:
                continue

            current_hash = hash_file(filename)
            if current_hash != self._files[filename]["hash"]:
                del self._files[filename]
                continue
开发者ID:sergecodd,项目名称:FireFox-OS,代码行数:25,代码来源:warnings.py

示例2: test_hash_file_known_hash

    def test_hash_file_known_hash(self):
        """Ensure a known hash value is recreated."""
        data = b'The quick brown fox jumps over the lazy cog'
        expected = 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3'

        temp = NamedTemporaryFile()
        temp.write(data)
        temp.flush()

        actual = hash_file(temp.name)

        self.assertEqual(actual, expected)
开发者ID:shanewfx,项目名称:gecko-dev,代码行数:12,代码来源:test_util.py

示例3: main

def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(dest='dir',
                        metavar='DIR',
                        help='Path to write goannalibs Android ARchive and metadata to.')
    parser.add_argument('--verbose', '-v', default=False, action='store_true',
                        help='be verbose')
    parser.add_argument('--revision',
                        help='Revision identifier to write.')
    parser.add_argument('--topsrcdir',
                        help='Top source directory.')
    parser.add_argument('--distdir',
                        help='Distribution directory (usually $OBJDIR/dist).')
    args = parser.parse_args(args)

    paths_to_hash = []

    aar = os.path.join(args.dir, 'goannalibs-{revision}.aar').format(revision=args.revision)
    paths_to_hash.append(aar)
    package_goannalibs_aar(args.topsrcdir, args.distdir, aar)

    pom = os.path.join(args.dir, 'goannalibs-{revision}.pom').format(revision=args.revision)
    paths_to_hash.append(pom)
    with open(pom, 'wt') as f:
        f.write(MAVEN_POM_TEMPLATE.format(
            groupId='org.mozilla',
            artifactId='goannalibs',
            version=args.revision,
            packaging='aar',
        ))

    ivy = os.path.join(args.dir, 'ivy-goannalibs-{revision}.xml').format(revision=args.revision)
    paths_to_hash.append(ivy)
    with open(ivy, 'wt') as f:
        f.write(IVY_XML_TEMPLATE.format(
            organisation='org.mozilla',
            module='goannalibs',
            revision=args.revision,
            publication=args.revision, # A white lie.
            name='goannalibs',
            type='aar',
            ext='aar',
        ))

    for p in paths_to_hash:
        sha = "%s.sha1" % p
        with open(sha, 'wt') as f:
            f.write(util.hash_file(p, hasher=hashlib.sha1()))
        if args.verbose:
            print(p)
            print(sha)

    return 0
开发者ID:Antonius32,项目名称:Pale-Moon,代码行数:53,代码来源:package_goannalibs_aar.py

示例4: test_hash_file_large

    def test_hash_file_large(self):
        """Ensure that hash_file seems to work with a large file."""
        data = b'x' * 1048576

        hasher = hashlib.sha1()
        hasher.update(data)
        expected = hasher.hexdigest()

        temp = NamedTemporaryFile()
        temp.write(data)
        temp.flush()

        actual = hash_file(temp.name)

        self.assertEqual(actual, expected)
开发者ID:shanewfx,项目名称:gecko-dev,代码行数:15,代码来源:test_util.py

示例5: insert

    def insert(self, warning, compute_hash=True):
        assert isinstance(warning, CompilerWarning)

        filename = warning["filename"]

        new_hash = None

        if compute_hash:
            new_hash = hash_file(filename)

        if filename in self._files:
            if new_hash != self._files[filename]["hash"]:
                del self._files[filename]

        value = self._files.get(filename, {"hash": new_hash, "warnings": set()})

        value["warnings"].add(warning)

        self._files[filename] = value
开发者ID:sergecodd,项目名称:FireFox-OS,代码行数:19,代码来源:warnings.py

示例6: insert

    def insert(self, warning, compute_hash=True):
        assert isinstance(warning, CompilerWarning)

        filename = warning['filename']

        new_hash = None

        if compute_hash:
            new_hash = hash_file(filename)

        if filename in self._files:
            if new_hash != self._files[filename]['hash']:
                del self._files[filename]

        value = self._files.get(filename, {
            'hash': new_hash,
            'warnings': set(),
        })

        value['warnings'].add(warning)

        self._files[filename] = value
开发者ID:Tripleman,项目名称:mozilla-central,代码行数:22,代码来源:warnings.py

示例7: main

def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(dest='dir',
                        metavar='DIR',
                        help='Path to write Android ARchives and metadata to.')
    parser.add_argument('--verbose', '-v', default=False, action='store_true',
                        help='be verbose')
    parser.add_argument('--revision',
                        help='Revision identifier to write.')
    parser.add_argument('--topsrcdir',
                        help='Top source directory.')
    parser.add_argument('--distdir',
                        help='Distribution directory (usually $OBJDIR/dist).')
    parser.add_argument('--appname',
                        help='Application name (usually $MOZ_APP_NAME, like "fennec").')
    args = parser.parse_args(args)

    # An Ivy 'publication' date must be given in the form yyyyMMddHHmmss, and Mozilla buildids are in this format.
    if len(args.revision) != 14:
        raise ValueError('Revision must be in yyyyMMddHHmmss format: %s' % args.revision)

    paths_to_hash = []

    groupId='org.mozilla'
    packaging_type='aar'
    gecklibs_aar = os.path.join(args.dir, 'geckolibs-{revision}.aar').format(revision=args.revision)
    paths_to_hash.append(gecklibs_aar)
    geckoview_aar = os.path.join(args.dir, 'geckoview-{revision}.aar').format(revision=args.revision)
    paths_to_hash.append(geckoview_aar)

    package_geckolibs_aar(args.topsrcdir, args.distdir, args.appname, gecklibs_aar)
    package_geckoview_aar(args.topsrcdir, args.distdir, args.appname, geckoview_aar)

    geckolibs_pom_path = os.path.join(args.dir, 'geckolibs-{revision}.pom').format(revision=args.revision)
    paths_to_hash.append(geckolibs_pom_path)
    geckolibs_pom = MAVEN_POM_TEMPLATE.format(
            groupId=groupId,
            artifactId='geckolibs',
            version=args.revision,
            packaging=packaging_type,
            dependencies=''
        )

    with open(geckolibs_pom_path, 'wt') as f:
        f.write(geckolibs_pom)

    geckoview_pom_path = os.path.join(args.dir, 'geckoview-{revision}.pom').format(revision=args.revision)
    paths_to_hash.append(geckoview_pom_path)
    geckoview_pom = MAVEN_POM_TEMPLATE.format(
        groupId=groupId,
        artifactId='geckoview',
        version=args.revision,
        packaging=packaging_type,
        dependencies=MAVEN_POM_DEPENDENCY_TEMPLATE.format(
            groupId=groupId,
            artifactId='geckolibs',
            version=args.revision,
            packaging=packaging_type
        )
    )

    with open(geckoview_pom_path, 'wt') as f:
        f.write(geckoview_pom)

    geckolibs_ivy_path = os.path.join(args.dir, 'ivy-geckolibs-{revision}.xml').format(revision=args.revision)
    paths_to_hash.append(geckolibs_ivy_path)
    with open(geckolibs_ivy_path, 'wt') as f:
        f.write(IVY_XML_TEMPLATE.format(
            organisation=groupId,
            module='geckolibs',
            revision=args.revision,
            publication=args.revision, # A white lie.
            name='geckolibs',
            type=packaging_type,
            ext=packaging_type,
            dependencies=''
        ))

    geckoview_ivy_path = os.path.join(args.dir, 'ivy-geckoview-{revision}.xml').format(revision=args.revision)
    paths_to_hash.append(geckoview_ivy_path)
    with open(geckoview_ivy_path, 'wt') as f:
        f.write(IVY_XML_TEMPLATE.format(
            organisation=groupId,
            module='geckoview',
            revision=args.revision,
            publication=args.revision, # A white lie.
            name='geckoview',
            type=packaging_type,
            ext=packaging_type,
            dependencies=IVY_XML_DEPENDENCY_TEMPLATE.format(
                organisation=groupId,
                name='geckolibs',
                revision=args.revision)
        ))

    for p in paths_to_hash:
        sha = "%s.sha1" % p
        with open(sha, 'wt') as f:
            f.write(util.hash_file(p, hasher=hashlib.sha1()))
        if args.verbose:
#.........这里部分代码省略.........
开发者ID:kleopatra999,项目名称:system-addons,代码行数:101,代码来源:package_geckolibs_aar.py

示例8: main


#.........这里部分代码省略.........
    parser.add_argument(
        "--purge-old",
        default=False,
        action="store_true",
        help="Delete any existing output files in the output directory.",
    )
    args = parser.parse_args(args)

    # An Ivy 'publication' date must be given in the form yyyyMMddHHmmss, and Mozilla buildids are in this format.
    if len(args.revision) != 14:
        raise ValueError("Revision must be in yyyyMMddHHmmss format: %s" % args.revision)

    paths_to_hash = []

    groupId = "org.mozilla"
    packaging_type = "aar"
    gecklibs_aar = os.path.join(args.dir, "geckolibs-{revision}.aar").format(revision=args.revision)
    paths_to_hash.append(gecklibs_aar)
    geckoview_aar = os.path.join(args.dir, "geckoview-{revision}.aar").format(revision=args.revision)
    paths_to_hash.append(geckoview_aar)

    if args.purge_old:
        old_output_finder = FileFinder(args.dir, find_executables=False)
        for p, f in old_output_finder.find("geckoview-*.*"):
            os.remove(f.path)
        for p, f in old_output_finder.find("geckolibs-*.*"):
            os.remove(f.path)
        for p, f in old_output_finder.find("ivy-*.*"):
            os.remove(f.path)

    package_geckolibs_aar(args.topsrcdir, args.distdir, args.appname, gecklibs_aar)
    package_geckoview_aar(args.topsrcdir, args.distdir, args.appname, geckoview_aar)

    geckolibs_pom_path = os.path.join(args.dir, "geckolibs-{revision}.pom").format(revision=args.revision)
    paths_to_hash.append(geckolibs_pom_path)
    geckolibs_pom = MAVEN_POM_TEMPLATE.format(
        groupId=groupId, artifactId="geckolibs", version=args.revision, packaging=packaging_type, dependencies=""
    )

    with open(geckolibs_pom_path, "wt") as f:
        f.write(geckolibs_pom)

    geckoview_pom_path = os.path.join(args.dir, "geckoview-{revision}.pom").format(revision=args.revision)
    paths_to_hash.append(geckoview_pom_path)
    geckoview_pom = MAVEN_POM_TEMPLATE.format(
        groupId=groupId,
        artifactId="geckoview",
        version=args.revision,
        packaging=packaging_type,
        dependencies=MAVEN_POM_DEPENDENCY_TEMPLATE.format(
            groupId=groupId, artifactId="geckolibs", version=args.revision, packaging=packaging_type
        ),
    )

    with open(geckoview_pom_path, "wt") as f:
        f.write(geckoview_pom)

    geckolibs_ivy_path = os.path.join(args.dir, "ivy-geckolibs-{revision}.xml").format(revision=args.revision)
    paths_to_hash.append(geckolibs_ivy_path)
    with open(geckolibs_ivy_path, "wt") as f:
        f.write(
            IVY_XML_TEMPLATE.format(
                organisation=groupId,
                module="geckolibs",
                revision=args.revision,
                publication=args.revision,  # A white lie.
                name="geckolibs",
                type=packaging_type,
                ext=packaging_type,
                dependencies="",
            )
        )

    geckoview_ivy_path = os.path.join(args.dir, "ivy-geckoview-{revision}.xml").format(revision=args.revision)
    paths_to_hash.append(geckoview_ivy_path)
    with open(geckoview_ivy_path, "wt") as f:
        f.write(
            IVY_XML_TEMPLATE.format(
                organisation=groupId,
                module="geckoview",
                revision=args.revision,
                publication=args.revision,  # A white lie.
                name="geckoview",
                type=packaging_type,
                ext=packaging_type,
                dependencies=IVY_XML_DEPENDENCY_TEMPLATE.format(
                    organisation=groupId, name="geckolibs", revision=args.revision
                ),
            )
        )

    for p in paths_to_hash:
        sha = "%s.sha1" % p
        with open(sha, "wt") as f:
            f.write(util.hash_file(p, hasher=hashlib.sha1()))
        if args.verbose:
            print(p)
            print(sha)

    return 0
开发者ID:LongyunZhang,项目名称:gecko-dev,代码行数:101,代码来源:package_geckolibs_aar.py


注:本文中的mozbuild.util.hash_file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。