本文整理汇总了Python中tarfile.TarInfo类的典型用法代码示例。如果您正苦于以下问题:Python TarInfo类的具体用法?Python TarInfo怎么用?Python TarInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TarInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _addToArchive
def _addToArchive(output, filename, archive):
output.seek(0)
xmlInfo = TarInfo(filename)
xmlInfo.size = len(output.getbuffer())
xmlInfo.mtime = time.time()
archive.addfile(xmlInfo,output)
output.close()
开发者ID:plison,项目名称:OpenSubtitles2015,代码行数:7,代码来源:tar2xml.py
示例2: _dump_files
def _dump_files(self, tar):
"""
Dump all uploaded media to the archive.
"""
# Loop through all models and find FileFields
for model in apps.get_models():
# Get the name of all file fields in the model
field_names = []
for field in model._meta.fields:
if isinstance(field, models.FileField):
field_names.append(field.name)
# If any were found, loop through each row
if len(field_names):
for row in model.objects.all():
for field_name in field_names:
field = getattr(row, field_name)
if field:
field.open()
info = TarInfo(field.name)
info.size = field.size
tar.addfile(info, field)
field.close()
开发者ID:davinirjr,项目名称:django-archive,代码行数:25,代码来源:archive.py
示例3: put
def put(self, content, filename="", file_hash=""):
""" Store file information in hashed tree """
if not filename and not file_hash:
raise ValueError('Filename or FileHash is mandatory')
if filename:
# File accesibility
if not os.path.exists(filename):
raise IOError('Unaccesible file %s', filename)
# Calc hash
file_hash = self._get_hash(filename)
if not file_hash:
raise ValueError('Hash of file is mandatory')
# Get file path for hash
path, tarfile, hashed_filename = self._get_path(file_hash)
# Create file path
try:
os.makedirs(path)
except WindowsError:
pass
except OSError:
pass
# Open tarfile
if self.external_compressor:
# External compressor is not suited for adding files.
raise ValueError('You cannot use external compressor for write files')
with TarFile.open(name=os.path.join(path, tarfile), mode='a') as tar:
with FileLock(os.path.join(path, tarfile)) as lock:
# Test if file already exists into tarfile
try:
tar.getmember(hashed_filename)
raise ValueError('Member already exists')
except KeyError:
pass
except:
raise
data = self.encoder.encode(content)
if self.internal_compressor:
data = self.internal_compressor.compress(data)
data_file = StringIO(data)
mtime = time.time()
ti = TarInfo(hashed_filename)
ti.size = data_file.len
ti.mtime = mtime
tar.addfile(tarinfo=ti, fileobj=data_file)
tar.close()
return file_hash
开发者ID:nilp0inter,项目名称:oniontree,代码行数:60,代码来源:__init__.py
示例4: GetTarInfo
def GetTarInfo(filename, filetype=DIRTYPE, mode=0755):
"""Create information for tar files"""
tarinfo = TarInfo(path.basename(filename))
tarinfo.type = filetype
tarinfo.mode = mode
tarinfo.mtime = time()
return tarinfo
开发者ID:quanganh2627,项目名称:vendor_intel_common,代码行数:7,代码来源:generate_factory_images.py
示例5: move_certs
def move_certs(self, paths):
self.log.info("Staging internal ssl certs for %s", self._log_name)
yield self.pull_image(self.move_certs_image)
# create the volume
volume_name = self.format_volume_name(self.certs_volume_name, self)
# create volume passes even if it already exists
self.log.info("Creating ssl volume %s for %s", volume_name, self._log_name)
yield self.docker('create_volume', volume_name)
# create a tar archive of the internal cert files
# docker.put_archive takes a tarfile and a running container
# and unpacks the archive into the container
nb_paths = {}
tar_buf = BytesIO()
archive = TarFile(fileobj=tar_buf, mode='w')
for key, hub_path in paths.items():
fname = os.path.basename(hub_path)
nb_paths[key] = '/certs/' + fname
with open(hub_path, 'rb') as f:
content = f.read()
tarinfo = TarInfo(name=fname)
tarinfo.size = len(content)
tarinfo.mtime = os.stat(hub_path).st_mtime
tarinfo.mode = 0o644
archive.addfile(tarinfo, BytesIO(content))
archive.close()
tar_buf.seek(0)
# run a container to stage the certs,
# mounting the volume at /certs/
host_config = self.client.create_host_config(
binds={
volume_name: {"bind": "/certs", "mode": "rw"},
},
)
container = yield self.docker('create_container',
self.move_certs_image,
volumes=["/certs"],
host_config=host_config,
)
container_id = container['Id']
self.log.debug(
"Container %s is creating ssl certs for %s",
container_id[:12], self._log_name,
)
# start the container
yield self.docker('start', container_id)
# stage the archive to the container
try:
yield self.docker(
'put_archive',
container=container_id,
path='/certs',
data=tar_buf,
)
finally:
yield self.docker('remove_container', container_id)
return nb_paths
开发者ID:jupyterhub,项目名称:dockerspawner,代码行数:59,代码来源:dockerspawner.py
示例6: generate_tar
def generate_tar(entries):
tar_buf = BytesIO()
tar_file = TarFile(mode="w", fileobj=tar_buf)
for path, contents in entries.items():
tar_info = TarInfo(name=path)
tar_info.size = len(contents)
tar_file.addfile(tar_info, fileobj=BytesIO(contents))
return BytesIO(tar_buf.getvalue())
开发者ID:thepwagner,项目名称:flotilla,代码行数:8,代码来源:test_revision.py
示例7: addFile
def addFile(tar, dest, file, file_size):
if dest not in written_files:
info = TarInfo(dest)
info.size = file_size
info.mtime = now
info.mode = 0777
tar.addfile(info, fileobj=file)
written_files.add(dest)
开发者ID:K-OpenNet,项目名称:ONOS-SSM,代码行数:8,代码来源:onos_stage.py
示例8: _dump_meta
def _dump_meta(self, tar):
"""
Dump metadata to the archive.
"""
data = MixedIO()
dump({'version': __version__}, data)
info = TarInfo('meta.json')
info.size = data.rewind()
tar.addfile(info, data)
开发者ID:davinirjr,项目名称:django-archive,代码行数:9,代码来源:archive.py
示例9: create_dir
def create_dir(self, path):
"""Create a directory within the tarfile.
:param path: the path to put the directory at.
"""
tarinfo = TarInfo(name=path)
tarinfo.type = DIRTYPE
tarinfo.mode = 0755
self._set_defaults(tarinfo)
self.addfile(tarinfo)
开发者ID:pombreda,项目名称:linaro-image-tools-1,代码行数:10,代码来源:better_tarfile.py
示例10: writeDataFile
def writeDataFile( self, filename, text, content_type, subdir=None ):
""" See IExportContext.
"""
mod_time = time.time()
if subdir is not None:
elements = subdir.split('/')
parents = filter(None, elements)
while parents:
dirname = os.path.join(*parents)
try:
self._archive.getmember(dirname+'/')
except KeyError:
info = TarInfo(dirname)
info.size = 0
info.mode = 509
info.mtime = mod_time
info.type = DIRTYPE
self._archive.addfile(info, StringIO())
parents = parents[:-1]
filename = '/'.join( ( subdir, filename ) )
stream = StringIO( text )
info = TarInfo( filename )
info.size = len( text )
info.mode = 436
info.mtime = mod_time
self._archive.addfile( info, stream )
开发者ID:kroman0,项目名称:products,代码行数:29,代码来源:patches.py
示例11: given_download
def given_download(self, payload: Dict[str, bytes], compression: str):
resource_id = '{}.tar.{}'.format(uuid4(), compression)
download_filename = join(self._content_root, resource_id)
with self.sync._open(download_filename, 'w') as archive:
for filename, content in payload.items():
tarinfo = TarInfo(filename)
tarinfo.size = len(content)
archive.addfile(tarinfo, BytesIO(content))
self.email_server_client_mock.download.return_value = resource_id
开发者ID:OPWEN,项目名称:opwen-webapp,代码行数:11,代码来源:test_sync.py
示例12: addString
def addString(tar, dest, string):
if dest not in written_files:
print dest, string
info = TarInfo(dest)
info.size = len(string)
info.mtime = now
info.mode = 0777
file = StringIO(string)
tar.addfile(info, fileobj=file)
file.close()
written_files.add(dest)
开发者ID:K-OpenNet,项目名称:ONOS-SSM,代码行数:11,代码来源:onos_stage.py
示例13: create_article
def create_article(self, data, info=None):
if not self._mode: raise TarCMS.TarCMSError('not open: %r' % self)
if info is None:
info = TarInfo()
assert isinstance(info, TarInfo)
aid = '%08x' % self._artdb.nextrecno()
info.name = aid+info.name
tid = self._add_corpus(info, data)
assert aid == tid
self._artdb.add_record(tid)
return aid
开发者ID:yasusii,项目名称:fooling,代码行数:11,代码来源:tarcms.py
示例14: _addMember
def _addMember(path, data, modtime):
from tarfile import DIRTYPE
elements = path.split('/')
parents = filter(None, [elements[x] for x in range(len(elements))])
for parent in parents:
info = TarInfo()
info.name = parent
info.size = 0
info.mtime = mod_time
info.type = DIRTYPE
archive.addfile(info, StringIO())
_addOneMember(path, data, modtime)
开发者ID:goschtl,项目名称:zope,代码行数:12,代码来源:test_context.py
示例15: _dump_db
def _dump_db(self, tar):
"""
Dump the rows in each model to the archive.
"""
# Dump the tables to a MixedIO
data = MixedIO()
call_command('dumpdata', all=True, format='json', indent=self.attr.get('ARCHIVE_DB_INDENT'),
exclude=self.attr.get('ARCHIVE_EXCLUDE'), stdout=data)
info = TarInfo(DB_DUMP)
info.size = data.rewind()
tar.addfile(info, data)
开发者ID:Adnn,项目名称:django-archive,代码行数:12,代码来源:archive.py
示例16: create_file_from_string
def create_file_from_string(self, filename, content):
"""Create a file with the contents passed as a string.
:param filename: the path to put the file at inside the
tarfile.
:param content: the content to put in the created file.
"""
tarinfo = TarInfo(name=filename)
tarinfo.size = len(content)
self._set_defaults(tarinfo)
fileobj = StringIO(content)
self.addfile(tarinfo, fileobj=fileobj)
开发者ID:pombreda,项目名称:linaro-image-tools-1,代码行数:12,代码来源:better_tarfile.py
示例17: _addMember
def _addMember(filename, data, modtime):
from tarfile import DIRTYPE
parents = filename.split('/')[:-1]
while parents:
path = '/'.join(parents) + '/'
if path not in archive.getnames():
info = TarInfo(path)
info.type = DIRTYPE
info.mtime = modtime
archive.addfile(info)
parents.pop()
_addOneMember(filename, data, modtime)
开发者ID:jakke,项目名称:Products.GenericSetup,代码行数:12,代码来源:test_context.py
示例18: write_package
def write_package():
tbs = ForgeClient.UPLOAD_TAR_BUFFER_SIZE
with TarFile.open(mode="w|gz", fileobj=body, bufsize=tbs,
dereference=True) as tar:
for file in files:
self.debug("Sending %s", file)
ti = TarInfo(file)
fp = os.path.join(self.path, file)
ti.size = os.path.getsize(fp)
ti.mode = 0o666
with open(fp, "rb") as fd:
tar.addfile(ti, fileobj=fd)
body.close()
开发者ID:2php,项目名称:veles,代码行数:13,代码来源:forge_client.py
示例19: writeDataFile
def writeDataFile( self, filename, text, content_type, subdir=None ):
""" See IExportContext.
"""
if subdir is not None:
filename = '/'.join( ( subdir, filename ) )
parents = filename.split('/')[:-1]
while parents:
path = '/'.join(parents) + '/'
if path not in self._archive.getnames():
info = TarInfo(path)
info.type = DIRTYPE
# tarfile.filemode(0755) == '-rwxr-xr-x'
info.mode = 0755
info.mtime = time.time()
self._archive.addfile(info)
parents.pop()
info = TarInfo(filename)
if isinstance(text, str):
stream = StringIO(text)
info.size = len(text)
elif isinstance(text, unicode):
raise ValueError("Unicode text is not supported, even if it only "
"contains ascii. Please encode your data. See "
"GS 1.7.0 changes for more")
else:
# Assume text is a an instance of a class like
# Products.Archetypes.WebDAVSupport.PdataStreamIterator,
# as in the case of ATFile
stream = text.file
info.size = text.size
info.mtime = time.time()
self._archive.addfile( info, stream )
开发者ID:pigaov10,项目名称:plone4.3,代码行数:35,代码来源:context.py
示例20: writeDataFile
def writeDataFile( self, filename, text, content_type, subdir=None ):
""" See IExportContext.
"""
if subdir is not None:
filename = '/'.join( ( subdir, filename ) )
parents = filename.split('/')[:-1]
while parents:
path = '/'.join(parents) + '/'
if path not in self._archive.getnames():
info = TarInfo(path)
info.type = DIRTYPE
# tarfile.filemode(0755) == '-rwxr-xr-x'
info.mode = 0755
info.mtime = time.time()
self._archive.addfile(info)
parents.pop()
info = TarInfo(filename)
if isinstance(text, basestring):
stream = StringIO(text)
info.size = len(text)
else:
# Assume text is a an instance of a class like
# Products.Archetypes.WebDAVSupport.PdataStreamIterator,
# as in the case of ATFile
stream = text.file
info.size = text.size
info.mtime = time.time()
self._archive.addfile( info, stream )
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:31,代码来源:context.py
注:本文中的tarfile.TarInfo类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论