2021-02-02 22:29:17 +01:00
|
|
|
from pathlib import Path
|
|
|
|
import contextlib
|
|
|
|
import os
|
|
|
|
|
|
|
|
class local_dir_remote:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.config = config
|
|
|
|
self.path = config["path"]
|
|
|
|
|
|
|
|
def list_dir(self):
|
|
|
|
path = Path(self.path)
|
2021-02-12 13:27:57 +01:00
|
|
|
file_list = []
|
|
|
|
delta = timedelta(minutes=5)
|
|
|
|
for file_demo in list(path.glob('*')):
|
|
|
|
mtime = datetime.fromtimestamp(os.stat(file_demo).st_mtime)
|
|
|
|
if mtime < datetime.now() - delta:
|
|
|
|
file_list.append(file_demo)
|
|
|
|
return file_list
|
2021-02-02 22:29:17 +01:00
|
|
|
|
|
|
|
def delete_local(self, pathfile):
|
|
|
|
with contextlib.suppress(FileNotFoundError):
|
2021-02-02 22:53:02 +01:00
|
|
|
if str(pathfile).endswith('.dem'):
|
|
|
|
os.remove(pathfile)
|
|
|
|
print('removed demo: ', pathfile)
|