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


Python File.id方法代码示例

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


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

示例1: save_file

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import id [as 别名]
 def save_file(self, path, _hash):
     f = File()
     f.id = str(uuid())
     f.name = os.path.basename(path)
     f.hash = _hash
     f.filesize = os.path.getsize(path)
     f.isdir = os.path.isdir(path)
     f.date = datetime.datetime.now()
     dirname = os.path.dirname(path)
     os.renames(path, os.path.join(dirname, f.id))
     self.session.add(f)
开发者ID:yann2192,项目名称:kinakuta_storage,代码行数:13,代码来源:kina_storage.py

示例2: main

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

#.........这里部分代码省略.........
        client = TagfilerClient(outbox_model.url, outbox_model.username, 
                            outbox_model.password, outbox_model.goauthtoken)
        client.connect()
        client.login()
    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
    tagged = 0
    registered = 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)
            elif f.mtime > exists.mtime:
                # Case: File has changed since last seen
                logger.debug("Modified: %s" % filename)
                f.checksum = sha256sum(filename)
                if f.checksum != exists.checksum:
                    f.id = exists.id
                    state.update_file(f)
                    worklist.append(f)
                else:
                    exists.mtime = f.mtime # update mod time
                    state.update_file(f)
                    skipped += 1
            elif f.size and not exists.checksum:
                # Case: Missing checksum, on regular file
                logger.debug("Missing checksum: %s" % filename)
                f.checksum = sha256sum(filename)
                f.id = exists.id
                state.update_file(f)
                worklist.append(f)
            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
    
    # Tag files in worklist
    tag_director = TagDirector()
    for f in worklist:
        logger.debug("Tagging: %s" % f)
        tag_director.tag_registered_file(outbox_model.path_rules, f)
        tag_director.tag_registered_file(outbox_model.dicom_rules, f)
        tag_director.tag_registered_file(outbox_model.nifti_rules, f)
        tag_director.tag_file_contents(outbox_model.line_rules, f)
        tagged += 1
    
    # Register files in worklist
    if len(worklist):
        client.add_subjects(worklist)
    for f in worklist:
        logger.debug("Registered: %s" % f)
        f.rtime = time.time()
        state.update_file(f)
        registered += 1
    
    # Print final message unless '--quiet'
    if not args.quiet:
        # Print concluding message to stdout
        print "Done. Found=%s Skipped=%s Tagged=%s Registered=%s" % \
                    (found, skipped, tagged, registered)
    
    try:
        client.close()
    except NetworkError as err:
        print >> sys.stderr, ('WARN: %s' % err)
    return __EXIT_SUCCESS
开发者ID:informatics-isi-edu,项目名称:tagfiler-iobox,代码行数:104,代码来源:cmdline.py


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