All Samples(8064) | Call(7565) | Derive(0) | Import(499)
Recursively delete a directory tree. If ignore_errors is set, errors are ignored; otherwise, if onerror is set, it is called to handle the error with arguments (func, path, exc_info) where func is os.listdir, os.remove, or os.rmdir; path is the argument to that function that caused it to fail; and exc_info is a tuple returned by sys.exc_info(). If ignore_errors is false and onerror is None, an exception is raised.
def rmtree(path, ignore_errors=False, onerror=None):
"""Recursively delete a directory tree.
If ignore_errors is set, errors are ignored; otherwise, if onerror
is set, it is called to handle the error with arguments (func,
path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
path is the argument to that function that caused it to fail; and
exc_info is a tuple returned by sys.exc_info(). If ignore_errors
is false and onerror is None, an exception is raised.
"""
if ignore_errors:
def onerror(*args):
pass
elif onerror is None:
def onerror(*args):
raise
try:
if os.path.islink(path):
# symlinks to directories are forbidden, see bug #1669
raise OSError("Cannot call rmtree on a symbolic link")
except OSError:
onerror(os.path.islink, path, sys.exc_info())
# can't continue even if onerror hook returns
return
names = []
try:
names = os.listdir(path)
except os.error, err:
onerror(os.listdir, path, sys.exc_info())
for name in names:
fullname = os.path.join(path, name)
try:
mode = os.lstat(fullname).st_mode
except os.error:
mode = 0
if stat.S_ISDIR(mode):
rmtree(fullname, ignore_errors, onerror)
else:
try:
os.remove(fullname)
except os.error, err:
onerror(os.remove, fullname, sys.exc_info())
try:
os.rmdir(path)
except os.error:
onerror(os.rmdir, path, sys.exc_info())
def setUpDataDir(self, userManager): """Make a folder for UserManager data.""" self._userDataDir = os.path.join(TEST_CODE_DIR, 'Users') if os.path.exists(self._userDataDir): shutil.rmtree(self._userDataDir, ignore_errors=1)
def tearDown(self): # Remove our test folder for UserManager data if os.path.exists(self._userDataDir): shutil.rmtree(self._userDataDir, ignore_errors=1) self._mgr = None
src/p/y/pyaeso-0.5/test/test_examples.py pyaeso(Download)
os.chdir(self._old_cwd)
# Delete temp directory
shutil.rmtree(self._tempdir, onerror = errorhander)
class TestMarketGraphs(ScriptSandbox):
src/p/y/pybctc-0.1.2/test/test_examples.py pybctc(Download)
os.chdir(self._old_cwd)
# Delete temp directory
shutil.rmtree(self._tempdir, onerror = errorhander)
class TestLoad2010(ScriptSandbox):
src/n/o/notmm-0.4.1/examples/lib/satchmo_store/shop/management/commands/satchmo_copy_static.py notmm(Download)
shutil.copytree(static_src, static_dest)
for root, dirs, files in os.walk(static_dest):
if '.svn' in dirs:
shutil.rmtree(os.path.join(root,'.svn'), True)
print "Copied %s to %s" % (static_src, static_dest)
src/g/i/git_http_backend.py-HEAD/examples/windows_service/git_http_backend_winservice.py git_http_backend.py(Download)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
if self._server_instance:
self._server_instance.stop()
if self._using_temporary_folder:
shutil.rmtree(self._content_path, True)
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
src/e/c/ecell-HEAD/ecell4/trunk/doc/sample/ga/ga.py ecell(Download)
aDir = "%s%s%s" %(self.theSetting['ELITE DIR'], os.sep, aDir) shutil.rmtree(aDir) # --------------------- # copy the directories related to elite individual
anOldDir = aDir + ".old" try: if os.path.isdir(aDir) == True and os.path.isdir(anOldDir) == True: shutil.rmtree(anOldDir) except: aMessage = "%s: %s is set as \"%s\". tried to the directory to backup directory, but it could not be removed \"%s.old\". \n" \ %(SETUP_ERROR,aKey,self.__get(aKey),self.__get(aKey) )
try: if os.path.isdir(aDir) == True: shutil.copytree(aDir,anOldDir) # Note:(1) shutil.rmtree(aDir) # Note:(2) # Those two lines (1) and (2) should be changed shutil.move() # using Python 2.3 or later except:
src/e/c/ecell-HEAD/ecell3/trunk/doc/samples/ga/ga.py ecell(Download)
aDir = "%s%s%s" %(self.theSetting['ELITE DIR'],
os.sep,
aDir)
shutil.rmtree(aDir)
# ---------------------
# copy the directories related to elite individual
anOldDir = aDir + ".old"
try:
if os.path.isdir(aDir) == True and os.path.isdir(anOldDir) == True:
shutil.rmtree(anOldDir)
except:
aMessage = "%s: %s is set as \"%s\". tried to the directory to backup directory, but it could not be removed \"%s.old\". \n" \
%(SETUP_ERROR,aKey,self.__get(aKey),self.__get(aKey) )
try:
if os.path.isdir(aDir) == True:
shutil.copytree(aDir,anOldDir) # Note:(1)
shutil.rmtree(aDir) # Note:(2)
# Those two lines (1) and (2) should be changed shutil.move()
# using Python 2.3 or later
except:
src/l/a/Langtangen-HEAD/src/py/examples/q4w/q4w-generate.py Langtangen(Download)
# create a subdirectory filenamebase and place all necessary files there:
import shutil
if os.path.isdir(filenamebase):
shutil.rmtree(filenamebase)
os.mkdir(filenamebase, 0755)
os.chdir(filenamebase)
src/p/y/pycopia-HEAD/QA/pycopia/remote/PosixServer.py pycopia(Download)
def rmtree(self, path):
self._rmtree_errors = []
shutil.rmtree(path, ignore_errors=True, onerror=self._rmtree_error_cb)
return self._rmtree_errors
def _rmtree_error_cb(self, func, arg, exc):
self._rmtree_errors.append((str(arg), str(exc[1])))
src/p/y/pymacadmin-HEAD/utilities/diskimage_unittesting/tests/example_plist_test.py pymacadmin(Download)
def tearDown(self):
"""clean up the temporary location."""
if self.tempdir:
if os.path.isdir(self.tempdir):
shutil.rmtree(self.tempdir)
def testFile(self):
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next