mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 07:03:56 -06:00
Simplified upgrade funtion, typos, check extruder count
CURA-4708
This commit is contained in:
parent
7a3d05ae8a
commit
fd6d3e76a3
1 changed files with 59 additions and 64 deletions
|
@ -129,12 +129,17 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|||
if parser.has_option("values", "machine_nozzle_size"):
|
||||
machine_nozzle_size = parser["values"]["machine_nozzle_size"]
|
||||
|
||||
definition_name = parser["general"]["name"]
|
||||
machine_extruders = self._getSingleExtrusionMachineExtruders(definition_name)
|
||||
machine_extruder_count = '1' # by default it is 1 and the value cannot be stored in the global stack
|
||||
if parser.has_option("values", "machine_extruder_count"):
|
||||
machine_extruder_count = parser["values"]["machine_extruder_count"]
|
||||
|
||||
#For single extuder machine we nee only first extruder
|
||||
if len(machine_extruders) !=0:
|
||||
if self._updateSingleExtuderDefinitionFile(machine_extruders, machine_nozzle_size):
|
||||
if machine_extruder_count == '1':
|
||||
definition_name = parser["general"]["name"]
|
||||
machine_extruders = self._getSingleExtrusionMachineExtruders(definition_name)
|
||||
|
||||
# For single extruder machine we need only first extruder
|
||||
if len(machine_extruders) !=0:
|
||||
self._updateSingleExtruderDefinitionFile(machine_extruders, machine_nozzle_size)
|
||||
parser.remove_option("values", "machine_nozzle_size")
|
||||
|
||||
# Update version numbers
|
||||
|
@ -219,9 +224,9 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|||
|
||||
machine_instances_dir = Resources.getPath(CuraApplication.ResourceTypes.MachineStack)
|
||||
|
||||
machine_instances = []
|
||||
machine_instance_id = None
|
||||
|
||||
#Find all machine instances
|
||||
# Find machine instances
|
||||
for item in os.listdir(machine_instances_dir):
|
||||
file_path = os.path.join(machine_instances_dir, item)
|
||||
if not os.path.isfile(file_path):
|
||||
|
@ -242,57 +247,51 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|||
if not parser.has_option("general", "id"):
|
||||
continue
|
||||
|
||||
machine_instances.append(parser)
|
||||
|
||||
#Find for extruders
|
||||
extruders_instances_dir = Resources.getPath(CuraApplication.ResourceTypes.ExtruderStack)
|
||||
#"machine",[extruders]
|
||||
extruder_instances_per_machine = {}
|
||||
|
||||
#Find all custom extruders for founded machines
|
||||
for item in os.listdir(extruders_instances_dir):
|
||||
file_path = os.path.join(extruders_instances_dir, item)
|
||||
if not os.path.isfile(file_path):
|
||||
id = parser["general"]["id"]
|
||||
if id + "_settings" != definition_name:
|
||||
continue
|
||||
|
||||
parser = configparser.ConfigParser(interpolation=None)
|
||||
try:
|
||||
parser.read([file_path])
|
||||
except:
|
||||
# skip, it is not a valid stack file
|
||||
continue
|
||||
|
||||
if not parser.has_option("metadata", "type"):
|
||||
continue
|
||||
if "extruder_train" != parser["metadata"]["type"]:
|
||||
continue
|
||||
|
||||
if not parser.has_option("metadata", "machine"):
|
||||
continue
|
||||
if not parser.has_option("metadata", "position"):
|
||||
continue
|
||||
|
||||
|
||||
for machine_instace in machine_instances:
|
||||
|
||||
machine_id = machine_instace["general"]["id"]
|
||||
if machine_id != parser["metadata"]["machine"]:
|
||||
continue
|
||||
|
||||
if machine_id + "_settings" != definition_name:
|
||||
continue
|
||||
|
||||
if extruder_instances_per_machine.get(machine_id) is None:
|
||||
extruder_instances_per_machine.update({machine_id:[]})
|
||||
|
||||
extruder_instances_per_machine.get(machine_id).append(parser)
|
||||
#the extruder can be related only to one machine
|
||||
else:
|
||||
machine_instance_id = id
|
||||
break
|
||||
|
||||
return extruder_instances_per_machine
|
||||
if machine_instance_id is not None:
|
||||
|
||||
#Find extruder defition at index 0 and update its values
|
||||
def _updateSingleExtuderDefinitionFile(self, extruder_instances_per_machine, machine_nozzle_size):
|
||||
extruders_instances_dir = Resources.getPath(CuraApplication.ResourceTypes.ExtruderStack)
|
||||
#"machine",[extruders]
|
||||
extruder_instances = []
|
||||
|
||||
# Find all custom extruders for found machines
|
||||
for item in os.listdir(extruders_instances_dir):
|
||||
file_path = os.path.join(extruders_instances_dir, item)
|
||||
if not os.path.isfile(file_path):
|
||||
continue
|
||||
|
||||
parser = configparser.ConfigParser(interpolation=None)
|
||||
try:
|
||||
parser.read([file_path])
|
||||
except:
|
||||
# skip, it is not a valid stack file
|
||||
continue
|
||||
|
||||
if not parser.has_option("metadata", "type"):
|
||||
continue
|
||||
if "extruder_train" != parser["metadata"]["type"]:
|
||||
continue
|
||||
|
||||
if not parser.has_option("metadata", "machine"):
|
||||
continue
|
||||
if not parser.has_option("metadata", "position"):
|
||||
continue
|
||||
|
||||
if machine_instance_id != parser["metadata"]["machine"]:
|
||||
continue
|
||||
|
||||
extruder_instances.append(parser)
|
||||
|
||||
return extruder_instances
|
||||
|
||||
# Find extruder definition at index 0 and update its values
|
||||
def _updateSingleExtruderDefinitionFile(self, extruder_instances_per_machine, machine_nozzle_size):
|
||||
|
||||
defintion_instances_dir = Resources.getPath(CuraApplication.ResourceTypes.DefinitionChangesContainer)
|
||||
|
||||
|
@ -312,19 +311,15 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|||
continue
|
||||
name = parser["general"]["name"]
|
||||
custom_extruder_at_0_position = None
|
||||
for machine_extruders in extruder_instances_per_machine:
|
||||
for extruder_instance in extruder_instances_per_machine[machine_extruders]:
|
||||
for extruder_instance in extruder_instances_per_machine:
|
||||
|
||||
if extruder_instance["general"]["id"] + "_settings" == name:
|
||||
defition_position = extruder_instance["metadata"]["position"]
|
||||
definition_position = extruder_instance["metadata"]["position"]
|
||||
|
||||
if defition_position == "0":
|
||||
custom_extruder_at_0_position = extruder_instance
|
||||
break
|
||||
if custom_extruder_at_0_position is not None:
|
||||
if definition_position == "0":
|
||||
custom_extruder_at_0_position = extruder_instance
|
||||
break
|
||||
|
||||
#If not null, then parsed file is for first extuder and then can be updated. I need to update only
|
||||
# If not null, then parsed file is for first extuder and then can be updated. I need to update only
|
||||
# first, because this update for single extuder machine
|
||||
if custom_extruder_at_0_position is not None:
|
||||
|
||||
|
@ -374,4 +369,4 @@ class VersionUpgrade30to31(VersionUpgrade):
|
|||
quality_changes_dir = Resources.getPath(CuraApplication.ResourceTypes.QualityInstanceContainer)
|
||||
|
||||
with open(os.path.join(quality_changes_dir, extruder_quality_changes_filename), "w") as f:
|
||||
f.write(extruder_quality_changes_output.getvalue())
|
||||
f.write(extruder_quality_changes_output.getvalue())
|
Loading…
Add table
Add a link
Reference in a new issue