mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Clean pycache for scripts as well.
This commit is contained in:
parent
a6f60df2ed
commit
242e0d403e
1 changed files with 19 additions and 1 deletions
|
@ -16,7 +16,7 @@ from UM.Extension import Extension
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.PluginRegistry import PluginRegistry
|
from UM.PluginRegistry import PluginRegistry
|
||||||
from UM.Resources import Resources
|
from UM.Resources import Resources
|
||||||
from UM.Trust import Trust
|
from UM.Trust import Trust, TrustBasics
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
from cura import ApplicationMetadata
|
from cura import ApplicationMetadata
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
|
@ -156,6 +156,24 @@ class PostProcessingPlugin(QObject, Extension):
|
||||||
# This should probably only be done on init.
|
# This should probably only be done on init.
|
||||||
# \param path Path to check for scripts.
|
# \param path Path to check for scripts.
|
||||||
def loadScripts(self, path: str) -> None:
|
def loadScripts(self, path: str) -> None:
|
||||||
|
|
||||||
|
if ApplicationMetadata.IsEnterpriseVersion:
|
||||||
|
# Delete all __pycache__ not in installation folder, as it presents a security risk.
|
||||||
|
# Also it prevents this very strange scenario:
|
||||||
|
# - Copy an existing script from the postprocessing-script folder to the appdata scripts folder.
|
||||||
|
# - Also copy the entire __pycache__ folder from the first to the last location.
|
||||||
|
# - Leave the __pycache__ as is, but write maliscous code just before the class begins.
|
||||||
|
# It's important to edit the script _after_ the pycache folder has been copied!
|
||||||
|
# - It'll execute, despite that the script has not been signed.
|
||||||
|
# It's not known if these reproduction steps are minimal, but it does at least happen in this case.
|
||||||
|
install_prefix = os.path.abspath(CuraApplication.getInstance().getInstallPrefix())
|
||||||
|
try:
|
||||||
|
is_in_installation_path = os.path.commonpath([install_prefix, path]).startswith(install_prefix)
|
||||||
|
except ValueError:
|
||||||
|
is_in_installation_path = False
|
||||||
|
if not is_in_installation_path:
|
||||||
|
TrustBasics.removeCached(path)
|
||||||
|
|
||||||
## Load all scripts in the scripts folders
|
## Load all scripts in the scripts folders
|
||||||
scripts = pkgutil.iter_modules(path = [path])
|
scripts = pkgutil.iter_modules(path = [path])
|
||||||
for loader, script_name, ispkg in scripts:
|
for loader, script_name, ispkg in scripts:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue