-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] mc-apply script doesn't function #27612
Comments
in older marlin CONFIG_EXPORT 1 the file marlin_config.json used to start with and the script got Configuration.h from here. now CONFIG_EXPORT 1 marlin_config.json starts with CONFIG_EXPORT 101 adds the filenames back in |
Potential fix/rewrite Has a lot better error detection (doesn't say "No marlin_config.json found." on every single error) and is actually human readable. options Can others please re-test, my brain has shutdown for the week. #!/usr/bin/env python
#
# mc-apply.py
# Create a Configuration from marlin_config.json
#
import json
import sys
import shutil
import os
def load_config(file_path):
try:
with open(file_path, 'r') as file:
return json.load(file)
except FileNotFoundError:
print(f'Error: {file_path} not found.')
sys.exit(1)
except json.JSONDecodeError:
print(f'Error: Failed to decode JSON from {file_path}.')
sys.exit(1)
def write_output_file(file_path, content):
try:
with open(file_path, 'w') as outfile:
outfile.write(content)
except IOError as e:
print(f'Error: Failed to write to {file_path}. {e}')
sys.exit(1)
def move_file(src, dst):
try:
shutil.move(src, dst)
except IOError as e:
print(f'Error: Failed to move {src} to {dst}. {e}')
sys.exit(1)
def process_configuration(conf, opt_output, output_suffix):
for _, values in conf.items():
for key in conf:
if key == '__INITIAL_HASH':
continue
if key == 'VERSION':
for k, v in sorted(values.items()):
print(f'{k}: {v}')
continue
output_file_path = os.path.join('Marlin', key + output_suffix)
content = ''
for k, v in sorted(values.items()):
if opt_output:
if v:
if '"' in v:
v = f"'{v}'"
elif ' ' in v:
v = f'"{v}"'
define = f'opt_set {k} {v}\n'
else:
define = f'opt_enable {k}\n'
else:
define = f'#define {k} {v}\n'
content += define
write_output_file(output_file_path, content)
if output_suffix:
original_file_path = os.path.join('Marlin', key)
backup_file_path = original_file_path + '.orig'
move_file(original_file_path, backup_file_path)
try:
with open(backup_file_path, 'r') as file:
file_lines = file.read().split('\n')
except IOError as e:
print(f'Error: Failed to read from {backup_file_path}. {e}')
sys.exit(1)
content = ''
for line in file_lines:
sline = line.strip(" \t\n\r")
if sline.startswith("#define"):
kv = sline[8:].strip().split(' ')
if kv[0] in values:
content += f'#define {kv[0]} {values[kv[0]]}\n'
del values[kv[0]]
else:
content += line + '\n'
else:
content += line + '\n'
for k, v in sorted(values.items()):
content += f'#define {k} {v}\n'
write_output_file(original_file_path, content)
print(f'Output configuration written to: {output_file_path}')
def main():
opt_output = '--opt' in sys.argv
output_suffix = '.sh' if opt_output else '' if '--bare-output' in sys.argv else '.gen'
config_file_path = 'marlin_config.json'
conf = load_config(config_file_path)
found_configuration_h = 'Configuration.h' in conf
if not found_configuration_h:
conf = {'Configuration.h': conf}
process_configuration(conf, opt_output, output_suffix)
if __name__ == '__main__':
main() need to look into what is it meant to do with Configuration_adv.h ? |
Yeah, there's still a few cases that this doesn't cover (did it ever?)
Or am I misunderstanding and no values from
There are a bunch of |
--opt creates Configuration.h.sh which contains eg |
I see a light at the end of the tunnel... In Configuration_adv.h is
but the value is > 5 The answer is
101 processes both Configuration.h and Configuration_adv.h and puts the file name in as expected |
I tried the new scrip above but it still outputs not found.
|
it expects marlin_config.json in the directory you invoke the script from ie in this case But its not complete yet... |
Ok, Ive tried it in there (the root folder with configs h, and /src. I'll wait for an update. Thanks for all your hard work. |
Did you test the latest
bugfix-2.1.x
code?Yes, and the problem still exists.
Bug Description
If
CONFIGURATION_EMBEDDING
is enabled, theM503 C
command will writeMC.ZIP
to the printers SD card with the compile time settings used.According to
docs/ConfigEmbedding.md
, the following should be used to then apply that config template back to the .h files:When attempting this, the script always returns:
Removing the main
try
/except
block, I get:When adding a debug to see what
key
contains, I see:As a result, no configuration files are modified and the
marlin_config.json
file cannot be folded back into the configuration.Bug Timeline
Likely a while.
Expected behavior
The script should restore config settings from
marlin_config.json
to the related .h files.Actual behavior
Error in output.
Steps to Reproduce
See main description.
Version of Marlin Firmware
bugfix-2.1.x
Printer model
No response
Electronics
No response
LCD/Controller
No response
Other add-ons
No response
Bed Leveling
None
Your Slicer
None
Host Software
None
Don't forget to include
Configuration.h
andConfiguration_adv.h
.Additional information & file uploads
Added example
marlin_config.json
as per output ofM503 C
.marlin_config.json
The text was updated successfully, but these errors were encountered: