Merge "Move the last_bytes util method to libvirt"
This commit is contained in:
commit
4e30bf6ca5
@ -20,7 +20,6 @@
|
||||
import contextlib
|
||||
import copy
|
||||
import datetime
|
||||
import errno
|
||||
import functools
|
||||
import hashlib
|
||||
import inspect
|
||||
@ -837,30 +836,6 @@ def mkfs(fs, path, label=None, run_as_root=False):
|
||||
execute(*args, run_as_root=run_as_root)
|
||||
|
||||
|
||||
def last_bytes(file_like_object, num):
|
||||
"""Return num bytes from the end of the file, and remaining byte count.
|
||||
|
||||
:param file_like_object: The file to read
|
||||
:param num: The number of bytes to return
|
||||
|
||||
:returns: (data, remaining)
|
||||
"""
|
||||
|
||||
try:
|
||||
file_like_object.seek(-num, os.SEEK_END)
|
||||
except IOError as e:
|
||||
# seek() fails with EINVAL when trying to go before the start of the
|
||||
# file. It means that num is larger than the file size, so just
|
||||
# go to the start.
|
||||
if e.errno == errno.EINVAL:
|
||||
file_like_object.seek(0, os.SEEK_SET)
|
||||
else:
|
||||
raise
|
||||
|
||||
remaining = file_like_object.tell()
|
||||
return (file_like_object.read(), remaining)
|
||||
|
||||
|
||||
def metadata_to_dict(metadata, include_deleted=False):
|
||||
result = {}
|
||||
for item in metadata:
|
||||
|
Loading…
x
Reference in New Issue
Block a user