def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
python类removedirs()的实例源码
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
test_linchpin_module_schema_check.py 文件源码
项目:linchpin
作者: CentOS-PaaS-SIG
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def test_module_dir_params(self):
"""
tests module with dir params
"""
dir_name = tempfile.mkdtemp()
invalid_params = {"data": dir_name, "schema": dir_name}
self.options["module_args"] = json.dumps(invalid_params)
results = run_module(self.options)
msg = "Recursive directory not supported"
output = results['failed'] and msg in results["msg"]
os.removedirs(dir_name)
assert_equal(output, True)
test_linchpin_module_output_parser.py 文件源码
项目:linchpin
作者: CentOS-PaaS-SIG
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def test_module_dir_params(self):
"""
tests module with dir params
"""
dir_name = tempfile.mkdtemp()
invalid_params = {"output_file": dir_name}
self.options["module_args"] = json.dumps(invalid_params)
results = run_module(self.options)
msg = "Recursive directory not supported"
output = results['failed'] and msg in results["msg"]
os.removedirs(dir_name)
assert_equal(output, True)
test_linchpin_module_os_hot_stack.py 文件源码
项目:linchpin
作者: CentOS-PaaS-SIG
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def test_module_dir_params(self):
"""
tests module with dir params
"""
dir_name = tempfile.mkdtemp()
invalid_params = {"stack_name": "testname",
"state": "present",
"template": dir_name}
self.options["module_args"] = json.dumps(invalid_params)
results = run_module(self.options)
msg = "Recursive directory not supported"
output = results['failed'] and msg in results["msg"]
assert_equal(output, True)
os.removedirs(dir_name)
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def clean_path(path):
if not path:
logging.info("Directory clean up - empty dir passed")
return
logging.info("Directory clean up - removing %s", path)
try:
# TODO: need to use osfs-rmdir on VSAN. For now jus yell if it failed
os.removedirs(path)
except Exception as e:
logging.warning("Directory clean up failed - %s, err: %s", path, e)
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def tearDown(self):
"""
Clear all PV,VG, LV and snapshots created by the test.
"""
# Remove created VG and unmount from base directory
errs = []
for ramdisk in self.ramdisks:
try:
lv_utils.vg_ramdisk_cleanup(*ramdisk)
except Exception as exc:
errs.append("Fail to cleanup ramdisk %s: %s" % (ramdisk, exc))
if errs:
self.error("\n".join(errs))
os.removedirs(self.mount_loc)
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def clean():
absolute_path = os.path.abspath(__file__)
mypath = os.path.dirname(absolute_path)
for root, dirs, files in os.walk(mypath,topdown=False):
for name in dirs:
fname = join(root,name)
if not os.listdir(fname): #to check wither the dir is empty
os.removedirs(fname)
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def cleanup(dir='test'):
for path, dirs, files in os.walk(dir):
for fn in files:
os.remove(os.path.join(path, fn))
for dir in dirs:
os.removedirs(os.path.join(path, dir))
# basic test
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass