def clean_tmp():
 import config
 def file_in_use(fname):
  in_use = False
  for proc in psutil.process_iter():
   try:
    open_files = proc.open_files()
    in_use = (in_use or any([(open_file.path == fname) for open_file in open_files]))
    if in_use:
     break
   except psutil.NoSuchProcess:
    pass
  return in_use
 def listdir_fullpath(d):
  return [os.path.join(d, f) for f in os.listdir(d)]
 for path in listdir_fullpath(config.TEMP_DIR):
  if (not file_in_use(path)):
   os.remove(path)

def clean_tmp ( ) : import config def file_in_use ( fname ) : in_use = False for proc in psutil . process_iter ( ) : try : open_files = proc . open_files ( ) in_use = ( in_use or any ( [ ( open_file . path == fname ) for open_file in open_files ] ) ) if in_use : break except psutil . NoSuchProcess : pass return in_use def listdir_fullpath ( d ) : return [ os . path . join ( d , f ) for f in os . listdir ( d ) ] for path in listdir_fullpath ( config . TEMP_DIR ) : if ( not file_in_use ( path ) ) : os . remove ( path )
cleanup the securedrop temp directory .