My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mc-apply.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python
  2. #
  3. # Create a Configuration from marlin_config.json
  4. #
  5. import json
  6. import sys
  7. import shutil
  8. import re
  9. opt_output = '--opt' in sys.argv
  10. output_suffix = '.sh' if opt_output else '' if '--bare-output' in sys.argv else '.gen'
  11. try:
  12. with open('marlin_config.json', 'r') as infile:
  13. conf = json.load(infile)
  14. for key in conf:
  15. # We don't care about the hash when restoring here
  16. if key == '__INITIAL_HASH':
  17. continue
  18. if key == 'VERSION':
  19. for k, v in sorted(conf[key].items()):
  20. print(k + ': ' + v)
  21. continue
  22. # The key is the file name, so let's build it now
  23. outfile = open('Marlin/' + key + output_suffix, 'w')
  24. for k, v in sorted(conf[key].items()):
  25. # Make define line now
  26. if opt_output:
  27. if v != '':
  28. if '"' in v:
  29. v = "'%s'" % v
  30. elif ' ' in v:
  31. v = '"%s"' % v
  32. define = 'opt_set ' + k + ' ' + v + '\n'
  33. else:
  34. define = 'opt_enable ' + k + '\n'
  35. else:
  36. define = '#define ' + k + ' ' + v + '\n'
  37. outfile.write(define)
  38. outfile.close()
  39. # Try to apply changes to the actual configuration file (in order to keep useful comments)
  40. if output_suffix != '':
  41. # Move the existing configuration so it doesn't interfere
  42. shutil.move('Marlin/' + key, 'Marlin/' + key + '.orig')
  43. infile_lines = open('Marlin/' + key + '.orig', 'r').read().split('\n')
  44. outfile = open('Marlin/' + key, 'w')
  45. for line in infile_lines:
  46. sline = line.strip(" \t\n\r")
  47. if sline[:7] == "#define":
  48. # Extract the key here (we don't care about the value)
  49. kv = sline[8:].strip().split(' ')
  50. if kv[0] in conf[key]:
  51. outfile.write('#define ' + kv[0] + ' ' + conf[key][kv[0]] + '\n')
  52. # Remove the key from the dict, so we can still write all missing keys at the end of the file
  53. del conf[key][kv[0]]
  54. else:
  55. outfile.write(line + '\n')
  56. else:
  57. outfile.write(line + '\n')
  58. # Process any remaining defines here
  59. for k, v in sorted(conf[key].items()):
  60. define = '#define ' + k + ' ' + v + '\n'
  61. outfile.write(define)
  62. outfile.close()
  63. print('Output configuration written to: ' + 'Marlin/' + key + output_suffix)
  64. except:
  65. print('No marlin_config.json found.')