Skip to content

Commit a6078d9

Browse files
committed
Added error message that occurs when trying to open binary gcode. #13 (minor adjustments)
1 parent df35af3 commit a6078d9

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

bricklayers.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,14 +1838,6 @@ def process_gcode(self, gcode_stream):
18381838
#logger.debug("Finished.")
18391839

18401840

1841-
def gcode_opener(path, flags):
1842-
file=os.open(path, flags)
1843-
header=os.pread(file,4,0)
1844-
if header==bytes("GCDE","ascii"):
1845-
os.close(file) #do not leak the file descriptor
1846-
print(f"{error_marker}The specified output folder '{input_file}' is a binary gcode file, which is not supported. Disable binary gcode in your slicer settings", file=sys.stderr)
1847-
sys.exit(1) # Exit immediately
1848-
return file
18491841

18501842
# Main execution
18511843
if __name__ == "__main__":
@@ -2042,6 +2034,17 @@ def expand_ranges(ranges):
20422034

20432035
error_marker = "❌ Error: " if sys.stderr.encoding.lower() == "utf-8" else "[ERROR] "
20442036

2037+
2038+
def gcode_opener(path, flags):
2039+
file=os.open(path, flags)
2040+
header=os.pread(file,4,0)
2041+
if header==bytes("GCDE","ascii"):
2042+
os.close(file) #do not leak the file descriptor
2043+
print(f"{error_marker}The file '{input_file}' is a binary gcode file, which is not supported. Disable Binary G-code in your slicer settings", file=sys.stderr)
2044+
sys.exit(1) # Exit immediately
2045+
return file
2046+
2047+
20452048
# Only process the file if Brick Layers if enabled
20462049
if args_dict["enabled"] > 0:
20472050

@@ -2177,7 +2180,7 @@ def expand_ranges(ranges):
21772180
# print(final_output_file)
21782181

21792182
# Open the input and output files using Generators:
2180-
with open(input_file, 'r', encoding="utf8", newline="",opener=gcode_opener) as infile, open(final_output_file, 'w') as outfile:
2183+
with open(input_file, 'r', encoding="utf8", newline="",opener=gcode_opener) as infile, open(final_output_file, 'w', encoding="utf-8", newline="\n") as outfile:
21812184
# Pass the file generator (line-by-line) to process_gcode
21822185
gcode_stream = (line for line in infile) # Efficient generator
21832186

0 commit comments

Comments
 (0)