本文整理汇总了Python中spacewalk.common.fileutils.createPath函数的典型用法代码示例。如果您正苦于以下问题:Python createPath函数的具体用法?Python createPath怎么用?Python createPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createPath函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _getFile
def _getFile(self, create=0):
path = os.path.join(self._getDir(create), self.id,
self.relative_path)
dirname = os.path.dirname(path)
if create and not os.path.isdir(dirname):
createPath(dirname)
return path
开发者ID:TJM,项目名称:spacewalk,代码行数:7,代码来源:xmlDiskSource.py
示例2: move_package
def move_package(filename, basedir, relpath, checksum_type, checksum, force=None):
"""
Copies the information from the file descriptor to a file
Checks the file's checksum, raising FileConflictErrror if it's different
The force flag prevents the exception from being raised, and copies the
file even if the checksum has changed
"""
packagePath = basedir + "/" + relpath
# Is the file there already?
if os.path.isfile(packagePath):
if force:
os.unlink(packagePath)
else:
# Get its checksum
localsum = getFileChecksum(checksum_type, packagePath)
if checksum == localsum:
# Same file, so get outa here
return
raise FileConflictError(os.path.basename(packagePath))
dir = os.path.dirname(packagePath)
# Create the directory where the file will reside
if not os.path.exists(dir):
createPath(dir)
# Check if the RPM has been downloaded from a remote repository
# If so, it is stored in CFG.MOUNT_POINT and we have to move it
# If not, the repository is local to the server, so the rpm should be copied
if filename.startswith(CFG.MOUNT_POINT):
shutil.move(filename, packagePath)
else:
shutil.copy(filename, packagePath)
# set the path perms readable by all users
os.chmod(packagePath, int('0644', 8))
开发者ID:jdobes,项目名称:spacewalk,代码行数:35,代码来源:importLib.py
示例3: copy_package
def copy_package(fd, basedir, relpath, checksum_type, checksum, force=None):
"""
Copies the information from the file descriptor to a file
Checks the file's checksum, raising FileConflictErrror if it's different
The force flag prevents the exception from being raised, and copies the
file even if the checksum has changed
"""
packagePath = basedir + "/" + relpath
# Is the file there already?
if os.path.isfile(packagePath) and not force:
# Get its checksum
localsum = getFileChecksum(checksum_type, packagePath)
if checksum == localsum:
# Same file, so get outa here
return
raise FileConflictError(os.path.basename(packagePath))
dir = os.path.dirname(packagePath)
# Create the directory where the file will reside
if not os.path.exists(dir):
createPath(dir)
pkgfd = os.open(packagePath, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
os.lseek(fd, 0, 0)
while 1:
buffer = os.read(fd, 65536)
if not buffer:
break
n = os.write(pkgfd, buffer)
if n != len(buffer):
# Error writing to the file
raise IOError, "Wrote %s out of %s bytes in file %s" % (
n, len(buffer), packagePath)
os.close(pkgfd)
# set the path perms readable by all users
setPermsPath(packagePath, chmod=0644)
开发者ID:bjmingyang,项目名称:spacewalk,代码行数:35,代码来源:importLib.py
示例4: _getDir
def _getDir(self, create=0):
dirname = "%s/%s" % (self.mountPoint, self.subdir)
if not create:
return dirname
if not os.path.exists(dirname):
createPath(dirname)
if not os.path.isdir(dirname):
raise MissingXmlDiskSourceDirError("%s is not a directory" % dirname)
return dirname
开发者ID:TJM,项目名称:spacewalk,代码行数:9,代码来源:xmlDiskSource.py
示例5: write_file
def write_file(self, stream_in):
"""Writes the contents of stream_in to the filesystem
Returns the file size(success) or raises FileCreationError"""
dirname = os.path.dirname(self.full_path)
createPath(dirname)
stat = os.statvfs(dirname)
f_bsize = stat[0] # file system block size
# misa: it's kind of icky whether to use f_bfree (free blocks) or
# f_bavail (free blocks for non-root). f_bavail is more correct, since
# you don't want to have the system out of disk space because of
# satsync; but people would get confused when looking at the output of
# df
f_bavail = stat[4] # free blocks
freespace = f_bsize * float(f_bavail)
if self.file_size is not None and self.file_size > freespace:
msg = messages.not_enough_diskspace % (freespace / 1024)
log(-1, msg, stream=sys.stderr)
# pkilambi: As the metadata download does'nt check for unfetched rpms
# abort the sync when it runs out of disc space
sys.exit(-1)
#raise FileCreationError(msg)
if freespace < 5000 * 1024: # arbitrary
msg = messages.not_enough_diskspace % (freespace / 1024)
log(-1, msg, stream=sys.stderr)
# pkilambi: As the metadata download does'nt check for unfetched rpms
# abort the sync when it runs out of disc space
sys.exit(-1)
#raise FileCreationError(msg)
fout = open(self.full_path, 'wb')
# setting file permissions; NOTE: rhnpush uses apache to write to disk,
# hence the 6 setting.
setPermsPath(self.full_path, user='apache', group='apache', chmod=0644)
size = 0
try:
while 1:
buf = stream_in.read(self.buffer_size)
if not buf:
break
buf_len = len(buf)
fout.write(buf)
size = size + buf_len
except IOError, e:
msg = "IOError: %s" % e
log(-1, msg, stream=sys.stderr)
# Try not to leave garbage around
try:
os.unlink(self.full_path)
except (OSError, IOError):
pass
raise FileCreationError(msg), None, sys.exc_info()[2]
开发者ID:Bearlock,项目名称:spacewalk,代码行数:52,代码来源:syncLib.py
示例6: _getFile
def _getFile(self, create=0):
dirname = self._getDir(create)
if create and not os.path.isdir(dirname):
createPath(dirname, logging=0)
return os.path.join(dirname, self.id) + '.xml'
开发者ID:bjmingyang,项目名称:spacewalk,代码行数:5,代码来源:xmlDiskSource.py
示例7: _getFile
def _getFile(self, create=0):
dirname = self._getDir(create)
if create and not os.path.isdir(dirname):
createPath(dirname)
return "%s/suse_subscriptions.xml" % dirname
开发者ID:m47ik,项目名称:uyuni,代码行数:5,代码来源:xmlDiskSource.py
注:本文中的spacewalk.common.fileutils.createPath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论