config-bundle-to-config.pl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/perl
  2. # This script extracts a full active config from a config bundle.
  3. # (Often users reporting issues don't attach plain configs, but
  4. # bundles...)
  5. use strict;
  6. use warnings;
  7. BEGIN {
  8. use FindBin;
  9. use lib "$FindBin::Bin/../lib";
  10. use local::lib "$FindBin::Bin/../local-lib";
  11. }
  12. use Getopt::Long qw(:config no_auto_abbrev);
  13. use Slic3r;
  14. use Slic3r::Test;
  15. $|++;
  16. my %opt = ();
  17. {
  18. my %options = (
  19. 'help' => sub { usage() },
  20. 'output=s' => \$opt{output},
  21. );
  22. GetOptions(%options) or usage(1);
  23. $ARGV[0] or usage(1);
  24. }
  25. ($ARGV[0] && $opt{output}) or usage(1);
  26. {
  27. my $bundle_ini = Slic3r::Config->read_ini($ARGV[0])
  28. or die "Failed to read $ARGV[0]\n";
  29. my $config_ini = { _ => {} };
  30. foreach my $section (qw(print filament printer)) {
  31. my $preset_name = $bundle_ini->{presets}{$section};
  32. $preset_name =~ s/\.ini$//;
  33. my $preset = $bundle_ini->{"$section:$preset_name"}
  34. or die "Failed to find preset $preset_name in bundle\n";
  35. $config_ini->{_}{$_} = $preset->{$_} for keys %$preset;
  36. }
  37. Slic3r::Config->write_ini($opt{output}, $config_ini);
  38. }
  39. sub usage {
  40. my ($exit_code) = @_;
  41. print <<"EOF";
  42. Usage: config-bundle-to-config.pl --output config.ini bundle.ini
  43. EOF
  44. exit ($exit_code || 0);
  45. }
  46. __END__