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


Python File.checksum方法代码示例

本文整理汇总了Python中models.File.checksum方法的典型用法代码示例。如果您正苦于以下问题:Python File.checksum方法的具体用法?Python File.checksum怎么用?Python File.checksum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.File的用法示例。


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

示例1: main

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import checksum [as 别名]

#.........这里部分代码省略.........
    outbox_model.goauthtoken = args.goauthtoken or cfg.get('goauthtoken')
    if not outbox_model.goauthtoken and \
        (not outbox_model.username or not outbox_model.password):
        parser.error('Ermrest username and password must be given.')
    outbox_model.bulk_ops_max = args.bulk_ops_max or \
                                cfg.get('bulk_ops_max', __BULK_OPS_MAX)
    outbox_model.bulk_ops_max = int(outbox_model.bulk_ops_max)
        
    
    # Roots
    roots = args.root or cfg.get('roots')
    if not roots or not len(roots):
        parser.error('At least one root directory must be given.')
    for root in roots:
        outbox_model.roots.append(root)
    
    # Add include/exclusion patterns
    excludes = args.exclude or cfg.get('excludes')
    if excludes and len(excludes):
        for exclude in excludes:
            outbox_model.excludes.append(re.compile(exclude))
    
    includes = args.include or cfg.get('includes')
    if includes and len(includes):
        for include in includes:
            outbox_model.includes.append(re.compile(include))
    
    # Establish Ermrest client connection
    try:
        client = ErmrestClient(outbox_model.url, outbox_model.username, 
                            outbox_model.password, outbox_model.goauthtoken)
        client.connect()
    except MalformedURL as err:
        print >> sys.stderr, ('ERROR: %s' % err)
        return __EXIT_FAILURE
    except UnresolvedAddress as err:
        print >> sys.stderr, ('ERROR: %s' % err)
        return __EXIT_FAILURE
    except NetworkError as err:
        print >> sys.stderr, ('ERROR: %s' % err)
        return __EXIT_FAILURE
    except ProtocolError as err:
        print >> sys.stderr, ('ERROR: %s' % err)
        return __EXIT_FAILURE
    
    state = OutboxStateDAO(outbox_model.state_db)
    worklist = []
    found = 0
    skipped = 0
    registered = 0
    added = 0

    # walk the root trees, cksum as needed, create worklist to be registered
    for root in outbox_model.roots:
        for (rfpath, size, mtime, user, group) in \
                tree_scan_stats(root, outbox_model.excludes, outbox_model.includes):
            filename = create_uri_friendly_file_path(root, rfpath)
            fargs = {'filename': filename, 'mtime': mtime, 'size': size, \
                    'username': user, 'groupname': group}
            f = File(**fargs)
            found += 1
            
            # Check if file exists in local state db
            exists = state.find_file(filename)
            if not exists:
                # Case: New file, not seen before
                logger.debug("New: %s" % filename)
                f.checksum = sha256sum(filename)
                state.add_file(f)
                worklist.append(f)
                added += 1
            elif not exists.rtime:
                # Case: File has not been registered
                logger.debug("Not registered: %s" % filename)
                worklist.append(exists)
            else:
                # Case: File does not meet any criteria for processing
                logger.debug("Skipping: %s" % filename)
                skipped += 1
    
    # Register files in worklist
    if len(worklist):
        client.add_subjects(worklist, outbox_model.bulk_ops_max)
    for f in worklist:
        logger.debug("Registered: %s" % f.filename)
        f.rtime = time.time()
        state.update_file(f)
        registered += 1
    
    # Print final message unless '--quiet'
    if not args.quiet:
        # Print concluding message to stdout
        logger.info("Done. Found=%s Added=%s Skipped=%s Registered=%s" % \
                    (found, added, skipped, registered))
    
    try:
        client.close()
    except NetworkError as err:
        print >> sys.stderr, ('WARN: %s' % err)
    return __EXIT_SUCCESS
开发者ID:stain,项目名称:iobox,代码行数:104,代码来源:cmdline.py


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