本文整理汇总了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)
示例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