config-bundle-to-config.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }
  11. use Getopt::Long qw(:config no_auto_abbrev);
  12. use Slic3r;
  13. use Slic3r::Test;
  14. $|++;
  15. my %opt = ();
  16. {
  17. my %options = (
  18. 'help' => sub { usage() },
  19. 'output=s' => \$opt{output},
  20. );
  21. GetOptions(%options) or usage(1);
  22. $ARGV[0] or usage(1);
  23. }
  24. ($ARGV[0] && $opt{output}) or usage(1);
  25. {
  26. my $bundle_ini = Slic3r::Config->read_ini($ARGV[0])
  27. or die "Failed to read $ARGV[0]\n";
  28. my $config_ini = { _ => {} };
  29. foreach my $section (qw(print filament printer)) {
  30. my $preset_name = $bundle_ini->{presets}{$section};
  31. $preset_name =~ s/\.ini$//;
  32. my $preset = $bundle_ini->{"$section:$preset_name"}
  33. or die "Failed to find preset $preset_name in bundle\n";
  34. $config_ini->{_}{$_} = $preset->{$_} for keys %$preset;
  35. }
  36. Slic3r::Config->write_ini($opt{output}, $config_ini);
  37. }
  38. sub usage {
  39. my ($exit_code) = @_;
  40. print <<"EOF";
  41. Usage: config-bundle-to-config.pl --output config.ini bundle.ini
  42. EOF
  43. exit ($exit_code || 0);
  44. }
  45. __END__