mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Set encoding correctly when opening files everywhere
Otherwise the encoding is interpreted differently on Windows and Mac.
This commit is contained in:
parent
c779795618
commit
54a03723ab
8 changed files with 13 additions and 13 deletions
|
@ -55,7 +55,7 @@ class ChangeLog(Extension, QObject,):
|
||||||
|
|
||||||
def loadChangeLogs(self):
|
def loadChangeLogs(self):
|
||||||
self._change_logs = collections.OrderedDict()
|
self._change_logs = collections.OrderedDict()
|
||||||
with open(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.txt"), "r",-1, "utf-8") as f:
|
with open(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.txt"), "r", encoding = "utf-8") as f:
|
||||||
open_version = None
|
open_version = None
|
||||||
open_header = "" # Initialise to an empty header in case there is no "*" in the first line of the changelog
|
open_header = "" # Initialise to an empty header in case there is no "*" in the first line of the changelog
|
||||||
for line in f:
|
for line in f:
|
||||||
|
|
|
@ -57,7 +57,7 @@ class GCodeProfileReader(ProfileReader):
|
||||||
# TODO: Consider moving settings to the start?
|
# TODO: Consider moving settings to the start?
|
||||||
serialized = "" # Will be filled with the serialized profile.
|
serialized = "" # Will be filled with the serialized profile.
|
||||||
try:
|
try:
|
||||||
with open(file_name, "r") as f:
|
with open(file_name, "r", encoding = "utf-8") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if line.startswith(prefix):
|
if line.startswith(prefix):
|
||||||
# Remove the prefix and the newline from the line and add it to the rest.
|
# Remove the prefix and the newline from the line and add it to the rest.
|
||||||
|
|
|
@ -100,7 +100,7 @@ class LegacyProfileReader(ProfileReader):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(PluginRegistry.getInstance().getPluginPath("LegacyProfileReader"), "DictionaryOfDoom.json"), "r", -1, "utf-8") as f:
|
with open(os.path.join(PluginRegistry.getInstance().getPluginPath("LegacyProfileReader"), "DictionaryOfDoom.json"), "r", encoding = "utf-8") as f:
|
||||||
dict_of_doom = json.load(f) # Parse the Dictionary of Doom.
|
dict_of_doom = json.load(f) # Parse the Dictionary of Doom.
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
Logger.log("e", "Could not open DictionaryOfDoom.json for reading: %s", str(e))
|
Logger.log("e", "Could not open DictionaryOfDoom.json for reading: %s", str(e))
|
||||||
|
|
|
@ -13,7 +13,7 @@ def readHex(filename):
|
||||||
"""
|
"""
|
||||||
data = []
|
data = []
|
||||||
extra_addr = 0
|
extra_addr = 0
|
||||||
f = io.open(filename, "r")
|
f = io.open(filename, "r", encoding = "utf-8")
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if len(line) < 1:
|
if len(line) < 1:
|
||||||
|
|
|
@ -94,7 +94,7 @@ class VersionUpgrade22to24(VersionUpgrade):
|
||||||
if variant_path.endswith("_variant.inst.cfg"):
|
if variant_path.endswith("_variant.inst.cfg"):
|
||||||
variant_path = variant_path[:-len("_variant.inst.cfg")] + "_settings.inst.cfg"
|
variant_path = variant_path[:-len("_variant.inst.cfg")] + "_settings.inst.cfg"
|
||||||
|
|
||||||
with open(os.path.join(machine_instances_dir, os.path.basename(variant_path)), "w") as fp:
|
with open(os.path.join(machine_instances_dir, os.path.basename(variant_path)), "w", encoding = "utf-8") as fp:
|
||||||
variant_config.write(fp)
|
variant_config.write(fp)
|
||||||
|
|
||||||
return config_name
|
return config_name
|
||||||
|
@ -105,9 +105,9 @@ class VersionUpgrade22to24(VersionUpgrade):
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for entry in os.scandir(variants_dir):
|
for entry in os.scandir(variants_dir):
|
||||||
if entry.name.endswith('.inst.cfg') and entry.is_file():
|
if entry.name.endswith(".inst.cfg") and entry.is_file():
|
||||||
config = configparser.ConfigParser(interpolation = None)
|
config = configparser.ConfigParser(interpolation = None)
|
||||||
with open(entry.path, "r") as fhandle:
|
with open(entry.path, "r", encoding = "utf-8") as fhandle:
|
||||||
config.read_file(fhandle)
|
config.read_file(fhandle)
|
||||||
if config.has_section("general") and config.has_option("general", "name"):
|
if config.has_section("general") and config.has_option("general", "name"):
|
||||||
result.append( { "path": entry.path, "name": config.get("general", "name") } )
|
result.append( { "path": entry.path, "name": config.get("general", "name") } )
|
||||||
|
|
|
@ -249,11 +249,11 @@ class VersionUpgrade25to26(VersionUpgrade):
|
||||||
definition_changes_dir = Resources.getPath(CuraApplication.ResourceTypes.DefinitionChangesContainer)
|
definition_changes_dir = Resources.getPath(CuraApplication.ResourceTypes.DefinitionChangesContainer)
|
||||||
user_settings_dir = Resources.getPath(CuraApplication.ResourceTypes.UserInstanceContainer)
|
user_settings_dir = Resources.getPath(CuraApplication.ResourceTypes.UserInstanceContainer)
|
||||||
|
|
||||||
with open(os.path.join(definition_changes_dir, definition_changes_filename), "w") as f:
|
with open(os.path.join(definition_changes_dir, definition_changes_filename), "w", encoding = "utf-8") as f:
|
||||||
f.write(definition_changes_output.getvalue())
|
f.write(definition_changes_output.getvalue())
|
||||||
with open(os.path.join(user_settings_dir, user_settings_filename), "w") as f:
|
with open(os.path.join(user_settings_dir, user_settings_filename), "w", encoding = "utf-8") as f:
|
||||||
f.write(user_settings_output.getvalue())
|
f.write(user_settings_output.getvalue())
|
||||||
with open(os.path.join(extruder_stack_dir, extruder_filename), "w") as f:
|
with open(os.path.join(extruder_stack_dir, extruder_filename), "w", encoding = "utf-8") as f:
|
||||||
f.write(extruder_output.getvalue())
|
f.write(extruder_output.getvalue())
|
||||||
|
|
||||||
## Creates a definition changes container which doesn't contain anything for the Custom FDM Printers.
|
## Creates a definition changes container which doesn't contain anything for the Custom FDM Printers.
|
||||||
|
|
|
@ -1018,7 +1018,7 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
@classmethod
|
@classmethod
|
||||||
def getProductIdMap(cls) -> Dict[str, List[str]]:
|
def getProductIdMap(cls) -> Dict[str, List[str]]:
|
||||||
product_to_id_file = os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "product_to_id.json")
|
product_to_id_file = os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "product_to_id.json")
|
||||||
with open(product_to_id_file) as f:
|
with open(product_to_id_file, encoding = "utf-8") as f:
|
||||||
product_to_id_map = json.load(f)
|
product_to_id_map = json.load(f)
|
||||||
product_to_id_map = {key: [value] for key, value in product_to_id_map.items()}
|
product_to_id_map = {key: [value] for key, value in product_to_id_map.items()}
|
||||||
return product_to_id_map
|
return product_to_id_map
|
||||||
|
|
|
@ -19,7 +19,7 @@ import pytest
|
||||||
def test_ultimaker3extended_variants(um3_file, um3e_file):
|
def test_ultimaker3extended_variants(um3_file, um3e_file):
|
||||||
directory = os.path.join(os.path.dirname(__file__), "..", "resources", "variants") #TODO: Hardcoded path relative to this test file.
|
directory = os.path.join(os.path.dirname(__file__), "..", "resources", "variants") #TODO: Hardcoded path relative to this test file.
|
||||||
um3 = configparser.ConfigParser()
|
um3 = configparser.ConfigParser()
|
||||||
um3.read_file(open(os.path.join(directory, um3_file)))
|
um3.read_file(open(os.path.join(directory, um3_file), encoding = "utf-8"))
|
||||||
um3e = configparser.ConfigParser()
|
um3e = configparser.ConfigParser()
|
||||||
um3e.read_file(open(os.path.join(directory, um3e_file)))
|
um3e.read_file(open(os.path.join(directory, um3e_file), encoding = "utf-8"))
|
||||||
assert um3["values"] == um3e["values"]
|
assert um3["values"] == um3e["values"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue