Merge branch 'maintenance' into devel

This commit is contained in:
GitHub Nightly Merge Action committed 2023-12-07 00:12:22 +00:00
commit fc5d2cb5d9
4 files changed
+190 -136

No files matched your search

+142 -129
View File
@@ -660,21 +660,21 @@ class FileManager:
def list_files(
self,
destinations=None,
locations=None,
path=None,
filter=None,
recursive=None,
level=0,
force_refresh=False,
):
if not destinations:
destinations = list(self._storage_managers.keys())
if isinstance(destinations, str):
destinations = [destinations]
if not locations:
locations = list(self._storage_managers.keys())
if isinstance(locations, str):
locations = [locations]
result = {}
for dst in destinations:
result[dst] = self._storage_managers[dst].list_files(
for loc in locations:
result[loc] = self._storage_managers[loc].list_files(
path=path,
filter=filter,
recursive=recursive,
@@ -685,7 +685,7 @@ class FileManager:
def add_file(
self,
destination,
location,
path,
file_object,
links=None,
@@ -697,10 +697,12 @@ class FileManager:
if printer_profile is None:
printer_profile = self._printer_profile_manager.get_current_or_default()
path_in_storage = self._storage(location).path_in_storage(path)
for name, hook in self._preprocessor_hooks.items():
try:
hook_file_object = hook(
path,
path_in_storage,
file_object,
links=links,
printer_profile=printer_profile,
@@ -718,13 +720,12 @@ class FileManager:
if hook_file_object is not None:
file_object = hook_file_object
queue_entry = self._analysis_queue_entry(destination, path)
queue_entry = self._analysis_queue_entry(location, path_in_storage)
if queue_entry is not None:
self._analysis_queue.dequeue(queue_entry)
path_in_storage = self._storage(destination).add_file(
path,
path_in_storage = self._storage(location).add_file(
path_in_storage,
file_object,
links=links,
printer_profile=printer_profile,
@@ -733,7 +734,7 @@ class FileManager:
)
queue_entry = self._analysis_queue_entry(
destination,
location,
path_in_storage,
printer_profile=printer_profile,
analysis=analysis,
@@ -741,11 +742,11 @@ class FileManager:
if queue_entry:
self._analysis_queue.enqueue(queue_entry, high_priority=True)
_, name = self._storage(destination).split_path(path_in_storage)
_, name = self._storage(location).split_path(path_in_storage)
eventManager().fire(
Events.FILE_ADDED,
{
"storage": destination,
"storage": location,
"path": path_in_storage,
"name": name,
"type": get_file_type(name),
@@ -755,16 +756,17 @@ class FileManager:
eventManager().fire(Events.UPDATED_FILES, {"type": "printables"})
return path_in_storage
def remove_file(self, destination, path):
queue_entry = self._analysis_queue_entry(destination, path)
def remove_file(self, location, path):
path_in_storage = self._storage(location).path_in_storage(path)
queue_entry = self._analysis_queue_entry(location, path_in_storage)
self._analysis_queue.dequeue(queue_entry)
self._storage(destination).remove_file(path)
self._storage(location).remove_file(path_in_storage)
_, name = self._storage(destination).split_path(path)
_, name = self._storage(location).split_path(path_in_storage)
eventManager().fire(
Events.FILE_REMOVED,
{
"storage": destination,
"storage": location,
"path": path,
"name": name,
"type": get_file_type(name),
@@ -773,18 +775,18 @@ class FileManager:
)
eventManager().fire(Events.UPDATED_FILES, {"type": "printables"})
def copy_file(self, destination, source, dst):
path_in_storage = self._storage(destination).copy_file(source, dst)
if not self.has_analysis(destination, path_in_storage):
queue_entry = self._analysis_queue_entry(destination, path_in_storage)
def copy_file(self, location, source, destination):
path_in_storage = self._storage(location).copy_file(source, destination)
if not self.has_analysis(location, path_in_storage):
queue_entry = self._analysis_queue_entry(location, path_in_storage)
if queue_entry:
self._analysis_queue.enqueue(queue_entry)
_, name = self._storage(destination).split_path(path_in_storage)
_, name = self._storage(location).split_path(path_in_storage)
eventManager().fire(
Events.FILE_ADDED,
{
"storage": destination,
"storage": location,
"path": path_in_storage,
"name": name,
"type": get_file_type(name),
@@ -793,25 +795,28 @@ class FileManager:
)
eventManager().fire(Events.UPDATED_FILES, {"type": "printables"})
def move_file(self, destination, source, dst):
queue_entry = self._analysis_queue_entry(destination, source)
def move_file(self, location, source, destination):
source_in_storage = self._storage(location).path_in_storage(source)
destination_in_storage = self._storage(location).path_in_storage(destination)
queue_entry = self._analysis_queue_entry(location, source_in_storage)
self._analysis_queue.dequeue(queue_entry)
path = self._storage(destination).move_file(source, dst)
if not self.has_analysis(destination, path):
queue_entry = self._analysis_queue_entry(destination, path)
path = self._storage(location).move_file(
source_in_storage, destination_in_storage
)
if not self.has_analysis(location, path):
queue_entry = self._analysis_queue_entry(location, path)
if queue_entry:
self._analysis_queue.enqueue(queue_entry)
source_path_in_storage = self._storage(destination).path_in_storage(source)
_, source_name = self._storage(destination).split_path(source_path_in_storage)
dst_path_in_storage = self._storage(destination).path_in_storage(dst)
_, dst_name = self._storage(destination).split_path(dst_path_in_storage)
_, source_name = self._storage(location).split_path(source_in_storage)
_, destination_name = self._storage(location).split_path(destination_in_storage)
eventManager().fire(
Events.FILE_REMOVED,
{
"storage": destination,
"path": source_path_in_storage,
"storage": location,
"path": source_in_storage,
"name": source_name,
"type": get_file_type(source_name),
"operation": "move",
@@ -820,118 +825,127 @@ class FileManager:
eventManager().fire(
Events.FILE_ADDED,
{
"storage": destination,
"path": dst_path_in_storage,
"name": dst_name,
"type": get_file_type(dst_name),
"storage": location,
"path": destination_in_storage,
"name": destination_name,
"type": get_file_type(destination_name),
"operation": "move",
},
)
eventManager().fire(
Events.FILE_MOVED,
{
"storage": destination,
"source_path": source_path_in_storage,
"storage": location,
"source_path": source_in_storage,
"source_name": source_name,
"source_type": get_file_type(source_name),
"destination_path": dst_path_in_storage,
"destination_name": dst_name,
"destination_type": get_file_type(dst_name),
"destination_path": destination_in_storage,
"destination_name": destination_name,
"destination_type": get_file_type(destination_name),
},
)
eventManager().fire(Events.UPDATED_FILES, {"type": "printables"})
def add_folder(self, destination, path, ignore_existing=True, display=None):
path_in_storage = self._storage(destination).add_folder(
def add_folder(self, location, path, ignore_existing=True, display=None):
path_in_storage = self._storage(location).add_folder(
path, ignore_existing=ignore_existing, display=display
)
_, name = self._storage(destination).split_path(path_in_storage)
_, name = self._storage(location).split_path(path_in_storage)
eventManager().fire(
Events.FOLDER_ADDED,
{"storage": destination, "path": path_in_storage, "name": name},
{"storage": location, "path": path_in_storage, "name": name},
)
eventManager().fire(Events.UPDATED_FILES, {"type": "printables"})
return path_in_storage
def remove_folder(self, destination, path, recursive=True):
self._analysis_queue.dequeue_folder(destination, path)
def remove_folder(self, location, path, recursive=True):
path_in_storage = self._storage(location).path_in_storage(path)
self._analysis_queue.dequeue_folder(location, path_in_storage)
self._analysis_queue.pause()
self._storage(destination).remove_folder(path, recursive=recursive)
self._storage(location).remove_folder(path_in_storage, recursive=recursive)
self._analysis_queue.resume()
_, name = self._storage(destination).split_path(path)
_, name = self._storage(location).split_path(path_in_storage)
eventManager().fire(
Events.FOLDER_REMOVED, {"storage": destination, "path": path, "name": name}
Events.FOLDER_REMOVED,
{"storage": location, "path": path_in_storage, "name": name},
)
eventManager().fire(Events.UPDATED_FILES, {"type": "printables"})
def copy_folder(self, destination, source, dst):
path_in_storage = self._storage(destination).copy_folder(source, dst)
def copy_folder(self, location, source, destination):
path_in_storage = self._storage(location).copy_folder(source, destination)
self._determine_analysis_backlog(
destination, self._storage(destination), root=path_in_storage
location, self._storage(location), root=path_in_storage
)
_, name = self._storage(destination).split_path(path_in_storage)
_, name = self._storage(location).split_path(path_in_storage)
eventManager().fire(
Events.FOLDER_ADDED,
{"storage": destination, "path": path_in_storage, "name": name},
{"storage": location, "path": path_in_storage, "name": name},
)
eventManager().fire(Events.UPDATED_FILES, {"type": "printables"})
def move_folder(self, destination, source, dst):
self._analysis_queue.dequeue_folder(destination, source)
def move_folder(self, location, source, destination):
source_in_storage = self._storage(location).path_in_storage(source)
destination_in_storage = self._storage(location).path_in_storage(destination)
self._analysis_queue.dequeue_folder(location, source_in_storage)
self._analysis_queue.pause()
dst_path_in_storage = self._storage(destination).move_folder(source, dst)
destination_in_storage = self._storage(location).move_folder(
source_in_storage, destination_in_storage
)
self._determine_analysis_backlog(
destination, self._storage(destination), root=dst_path_in_storage
location, self._storage(location), root=destination_in_storage
)
self._analysis_queue.resume()
source_path_in_storage = self._storage(destination).path_in_storage(source)
_, source_name = self._storage(destination).split_path(source_path_in_storage)
_, dst_name = self._storage(destination).split_path(dst_path_in_storage)
_, source_name = self._storage(location).split_path(source_in_storage)
_, destination_name = self._storage(location).split_path(destination_in_storage)
eventManager().fire(
Events.FOLDER_REMOVED,
{"storage": destination, "path": source_path_in_storage, "name": source_name},
{"storage": location, "path": source_in_storage, "name": source_name},
)
eventManager().fire(
Events.FOLDER_ADDED,
{"storage": destination, "path": dst_path_in_storage, "name": dst_name},
{
"storage": location,
"path": destination_in_storage,
"name": destination_name,
},
)
eventManager().fire(
Events.FOLDER_MOVED,
{
"storage": destination,
"source_path": source_path_in_storage,
"storage": location,
"source_path": source_in_storage,
"source_name": source_name,
"destination_path": dst_path_in_storage,
"destination_name": dst_name,
"destination_path": destination_in_storage,
"destination_name": destination_name,
},
)
eventManager().fire(Events.UPDATED_FILES, {"type": "printables"})
def has_analysis(self, destination, path):
return self._storage(destination).has_analysis(path)
def has_analysis(self, location, path):
return self._storage(location).has_analysis(path)
def get_metadata(self, destination, path):
return self._storage(destination).get_metadata(path)
def get_metadata(self, location, path):
return self._storage(location).get_metadata(path)
def add_link(self, destination, path, rel, data):
self._storage(destination).add_link(path, rel, data)
def add_link(self, location, path, rel, data):
self._storage(location).add_link(path, rel, data)
def remove_link(self, destination, path, rel, data):
self._storage(destination).remove_link(path, rel, data)
def remove_link(self, location, path, rel, data):
self._storage(location).remove_link(path, rel, data)
def log_print(
self, destination, path, timestamp, print_time, success, printer_profile
):
def log_print(self, location, path, timestamp, print_time, success, printer_profile):
try:
if success:
self._storage(destination).add_history(
self._storage(location).add_history(
path,
{
"timestamp": timestamp,
@@ -941,7 +955,7 @@ class FileManager:
},
)
else:
self._storage(destination).add_history(
self._storage(location).add_history(
path,
{
"timestamp": timestamp,
@@ -950,20 +964,20 @@ class FileManager:
},
)
eventManager().fire(
Events.METADATA_STATISTICS_UPDATED, {"storage": destination, "path": path}
Events.METADATA_STATISTICS_UPDATED, {"storage": location, "path": path}
)
except NoSuchStorage:
# if there's no storage configured where to log the print, we'll just not log it
pass
def save_recovery_data(self, origin, path, pos):
def save_recovery_data(self, location, path, pos):
import time
from octoprint.util import atomic_write
data = {
"origin": origin,
"path": self.path_in_storage(origin, path),
"origin": location,
"path": self.path_in_storage(location, path),
"pos": pos,
"date": time.time(),
}
@@ -1004,79 +1018,78 @@ class FileManager:
)
self.delete_recovery_data()
def get_additional_metadata(self, destination, path, key):
self._storage(destination).get_additional_metadata(path, key)
def get_additional_metadata(self, location, path, key):
self._storage(location).get_additional_metadata(path, key)
def set_additional_metadata(
self, destination, path, key, data, overwrite=False, merge=False
self, location, path, key, data, overwrite=False, merge=False
):
self._storage(destination).set_additional_metadata(
self._storage(location).set_additional_metadata(
path, key, data, overwrite=overwrite, merge=merge
)
def remove_additional_metadata(self, destination, path, key):
self._storage(destination).remove_additional_metadata(path, key)
def remove_additional_metadata(self, location, path, key):
self._storage(location).remove_additional_metadata(path, key)
def path_on_disk(self, destination, path):
return self._storage(destination).path_on_disk(path)
def path_on_disk(self, location, path):
return self._storage(location).path_on_disk(path)
def canonicalize(self, destination, path):
return self._storage(destination).canonicalize(path)
def canonicalize(self, location, path):
return self._storage(location).canonicalize(path)
def sanitize(self, destination, path):
return self._storage(destination).sanitize(path)
def sanitize(self, location, path):
return self._storage(location).sanitize(path)
def sanitize_name(self, destination, name):
return self._storage(destination).sanitize_name(name)
def sanitize_name(self, location, name):
return self._storage(location).sanitize_name(name)
def sanitize_path(self, destination, path):
return self._storage(destination).sanitize_path(path)
def sanitize_path(self, location, path):
return self._storage(location).sanitize_path(path)
def split_path(self, destination, path):
return self._storage(destination).split_path(path)
def split_path(self, location, path):
return self._storage(location).split_path(path)
def join_path(self, destination, *path):
return self._storage(destination).join_path(*path)
def join_path(self, location, *path):
return self._storage(location).join_path(*path)
def path_in_storage(self, destination, path):
return self._storage(destination).path_in_storage(path)
def path_in_storage(self, location, path):
return self._storage(location).path_in_storage(path)
def last_modified(self, destination, path=None, recursive=False):
return self._storage(destination).last_modified(path=path, recursive=recursive)
def last_modified(self, location, path=None, recursive=False):
return self._storage(location).last_modified(path=path, recursive=recursive)
def _storage(self, destination):
if destination not in self._storage_managers:
raise NoSuchStorage(f"No storage configured for destination {destination}")
return self._storage_managers[destination]
def _storage(self, location):
if location not in self._storage_managers:
raise NoSuchStorage(f"No storage configured for destination {location}")
return self._storage_managers[location]
def _add_analysis_result(self, destination, path, result):
if destination not in self._storage_managers:
def _add_analysis_result(self, location, path, result):
if location not in self._storage_managers:
return
if not result:
return
storage_manager = self._storage_managers[destination]
storage_manager = self._storage_managers[location]
storage_manager.set_additional_metadata(path, "analysis", result, overwrite=True)
def _on_analysis_finished(self, entry, result):
self._add_analysis_result(entry.location, entry.path, result)
def _analysis_queue_entry(
self, destination, path, printer_profile=None, analysis=None
):
def _analysis_queue_entry(self, location, path, printer_profile=None, analysis=None):
if printer_profile is None:
printer_profile = self._printer_profile_manager.get_current_or_default()
absolute_path = self._storage(destination).path_on_disk(path)
_, file_name = self._storage(destination).split_path(path)
path_in_storage = self._storage(location).path_in_storage(path)
absolute_path = self._storage(location).path_on_disk(path)
_, file_name = self._storage(location).split_path(path)
file_type = get_file_type(absolute_path)
if file_type:
return QueueEntry(
file_name,
path,
path_in_storage,
file_type[-1],
destination,
location,
absolute_path,
printer_profile,
analysis,
+5 -4
View File
@@ -1111,13 +1111,14 @@ class LocalFileStorage(StorageInterface):
def split_path(self, path):
path = to_unicode(path)
split = path.split("/")
if len(split) == 1:
return "", split[0]
else:
return self.join_path(*split[:-1]), split[-1]
return self.path_in_storage(self.join_path(*split[:-1])), split[-1]
def join_path(self, *path):
return "/".join(map(to_unicode, path))
return self.path_in_storage("/".join(map(to_unicode, path)))
def sanitize(self, path):
"""
@@ -1233,7 +1234,7 @@ class LocalFileStorage(StorageInterface):
if path.startswith(self.basefolder):
path = path[len(self.basefolder) :]
path = path.replace(os.path.sep, "/")
if path.startswith("/"):
while path.startswith("/"):
path = path[1:]
return path