~ubuntu-branches/ubuntu/utopic/slic3r/utopic-proposed

« back to all changes in this revision

Viewing changes to utils/config-bundle-to-config.pl

  • Committer: Package Import Robot
  • Author(s): Alessandro Ranellucci
  • Date: 2014-08-06 11:18:02 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140806111802-8v6iez93cj6skz5l
Tags: 1.1.7+dfsg-1
New upstream release

Show diffs side-by-side

added added

removed removed

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