def cleanScratch():
""" Clean scratch directory.
It checks whether any other gcMapExplorer process is running. In case,
when only one process (i.e. current) is running, all files with "gcx"
prefix will be deleted from default scratch directory.
"""
config = getConfig()
count = 0
for pid in psutil.pids():
p = None
try:
p = psutil.Process(pid)
except psutil.NoSuchProcess:
pass
if p is not None:
if 'gcMapExplorer' in p.name():
count += 1
# If only one gcMapExplorer is running, it is the current one
if count == 1:
for f in os.listdir(config['Dirs']['WorkingDirectory']):
if not os.path.isfile(f):
continue
basename = os.path.basename(f)
base = os.path.splitext(basename)[0]
if "gcx" in base:
try:
print(' Removing File: {0}'.format(f))
os.remove(f)
except IOError:
pass
print(' ... Finished Cleaning')
评论列表
文章目录