fixed recurse for MART
This commit is contained in:
+9
-12
@@ -67,7 +67,6 @@ def initialize_ftp_servers(file_path: str) -> FTPServers:
|
||||
host="192.168.31.15",
|
||||
port=21,
|
||||
notify_filters=["FTR"],
|
||||
cwd='TRAILER',
|
||||
recurse=True
|
||||
))
|
||||
|
||||
@@ -101,7 +100,7 @@ def list_new_directories(ftp_server: FTPServer) -> DirDescriptors:
|
||||
with ftp_server.connect() as ftp_connection:
|
||||
if ftp_server.cwd:
|
||||
ftp_connection.cwd(ftp_server.cwd)
|
||||
new_dirs: DirDescriptors = {}
|
||||
curr_dirs: DirDescriptors = {}
|
||||
try:
|
||||
# main method, retrieve directories with details
|
||||
for d in ftp_connection.mlsd(): # List directory contents
|
||||
@@ -110,28 +109,26 @@ def list_new_directories(ftp_server: FTPServer) -> DirDescriptors:
|
||||
modified_time_str: str = dir_info.get('modify', '')
|
||||
modified_time: datetime = datetime.strptime(modified_time_str, '%Y%m%d%H%M%S') if modified_time_str else datetime.now()
|
||||
unique: str = dir_info.get('unique', str(datetime.now().timestamp()))
|
||||
new_dirs[unique] = FTPDirInfo(name=dir_name, modified_time=modified_time)
|
||||
curr_dirs[unique] = FTPDirInfo(name=dir_name, modified_time=modified_time)
|
||||
except error_perm:
|
||||
# revert to simple directory listing mode
|
||||
for d in ftp_connection.nlst():
|
||||
dir_name = d
|
||||
unique = uuid5(namespace=NAMESPACE_OID, name=dir_name).hex.upper()[:11]
|
||||
new_dirs[unique] = FTPDirInfo(name=dir_name)
|
||||
curr_dirs[unique] = FTPDirInfo(name=dir_name)
|
||||
|
||||
diff_dirs: DirDescriptors = { k:v for k,v in new_dirs.items() if k not in ftp_server.dirs }
|
||||
|
||||
# recurse only in difference directory so it is faster
|
||||
if ftp_server.recurse:
|
||||
base_dir: str = ftp_connection.pwd()
|
||||
recurse_dirs: DirDescriptors = copy.deepcopy(diff_dirs)
|
||||
recurse_dirs: DirDescriptors = copy.deepcopy(curr_dirs)
|
||||
for u, d in recurse_dirs.items():
|
||||
ftp_connection.cwd(base_dir)
|
||||
ftp_connection.cwd(d.name)
|
||||
explore_dir(ftp_connection=ftp_connection, dir_descriptors=diff_dirs)
|
||||
del diff_dirs[u]
|
||||
new_dirs |= diff_dirs
|
||||
explore_dir(ftp_connection=ftp_connection, dir_descriptors=curr_dirs)
|
||||
del curr_dirs[u]
|
||||
|
||||
ftp_server.dirs = new_dirs # Update the server's directory list with the new directories
|
||||
diff_dirs: DirDescriptors = { k:v for k,v in curr_dirs.items() if k not in ftp_server.dirs }
|
||||
ftp_server.dirs = curr_dirs # Update the server's directory list with the new directories
|
||||
return diff_dirs # Return the difference
|
||||
|
||||
def check_new_titles(mqtt: mqtt_client.Client, topic: str, file_path: str, logger: Logger) -> None:
|
||||
@@ -182,4 +179,4 @@ if __name__ == "__main__":
|
||||
this_dirs: DirDescriptors = {}
|
||||
explore_dir(ftp_connection, this_dirs)
|
||||
print(this_dirs)
|
||||
|
||||
|
||||
|
||||
@@ -367,6 +367,8 @@ def main() -> int:
|
||||
last_cls = sens.request
|
||||
except (Timeout, ConnectionError) as ce:
|
||||
LOGGER.debug("Projector is probably shutdown: [%s]", ce)
|
||||
except KeyError as ke:
|
||||
LOGGER.error("Key not found in dictionary: [%s]", ke)
|
||||
except Exception as e:
|
||||
LOGGER.error("Unexpected exception: [%s]", e)
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user