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 logging
|
||||||
import mail
|
import mail
|
||||||
import os
|
import os
|
||||||
|
import psutil
|
||||||
import report
|
import report
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -16,6 +17,18 @@ logger = logging.getLogger('root')
|
|||||||
report.stdoutLoggingConfigure(log_name_lvl=[('root', config.LOG_LEVEL), ])
|
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__":
|
if __name__ == "__main__":
|
||||||
while True:
|
while True:
|
||||||
# Check if LOCK_FILE EXISTS
|
# Check if LOCK_FILE EXISTS
|
||||||
@ -32,7 +45,7 @@ if __name__ == "__main__":
|
|||||||
# Scan for files to send
|
# Scan for files to send
|
||||||
for filename in fstools.filelist(config.TARGET_FOLDER):
|
for filename in fstools.filelist(config.TARGET_FOLDER):
|
||||||
# Exclude LOCK_FILE
|
# 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)
|
logger.info("Found %s to send via E-Mail to %s.", filename, config.SEND_TO)
|
||||||
# Send File as E-Mail
|
# Send File as E-Mail
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user