ignore files having a handle
This commit is contained in:
parent
8af68a58ad
commit
faae45b030
15
file2mail.py
15
file2mail.py
@ -6,6 +6,7 @@ import json
|
||||
import logging
|
||||
import mail
|
||||
import os
|
||||
import psutil
|
||||
import report
|
||||
import time
|
||||
|
||||
@ -16,6 +17,18 @@ logger = logging.getLogger('root')
|
||||
report.stdoutLoggingConfigure(log_name_lvl=[('root', config.LOG_LEVEL), ])
|
||||
|
||||
|
||||
def has_handle(fpath):
|
||||
for proc in psutil.process_iter():
|
||||
try:
|
||||
for item in proc.open_files():
|
||||
if fpath == item.path:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
while True:
|
||||
# Check if LOCK_FILE EXISTS
|
||||
@ -32,7 +45,7 @@ if __name__ == "__main__":
|
||||
# Scan for files to send
|
||||
for filename in fstools.filelist(config.TARGET_FOLDER):
|
||||
# Exclude LOCK_FILE
|
||||
if filename != LOCK_FILE:
|
||||
if filename != LOCK_FILE and not has_handle(filename):
|
||||
logger.info("Found %s to send via E-Mail to %s.", filename, config.SEND_TO)
|
||||
# Send File as E-Mail
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user