def _unusedTestDirectory(base):
 counter = 0
 while True:
  if counter:
   testdir = base.sibling(('%s-%d' % (base.basename(), counter)))
  else:
   testdir = base
  testDirLock = FilesystemLock((testdir.path + '.lock'))
  if testDirLock.lock():
   if testdir.exists():
    _removeSafely(testdir)
   testdir.makedirs()
   testdir.child('_trial_marker').setContent('')
   return (testdir, testDirLock)
  elif (base.basename() == '_trial_temp'):
   counter += 1
  else:
   raise _WorkingDirectoryBusy()

def _unusedTestDirectory ( base ) : counter = 0 while True : if counter : testdir = base . sibling ( ( '%s-%d' % ( base . basename ( ) , counter ) ) ) else : testdir = base testDirLock = FilesystemLock ( ( testdir . path + '.lock' ) ) if testDirLock . lock ( ) : if testdir . exists ( ) : _removeSafely ( testdir ) testdir . makedirs ( ) testdir . child ( '_trial_marker' ) . setContent ( '' ) return ( testdir , testDirLock ) elif ( base . basename ( ) == '_trial_temp' ) : counter += 1 else : raise _WorkingDirectoryBusy ( )
find an unused directory named similarly to c{base} .