Subversion Repositories HomeAutomation

Rev

Rev 1522 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1522 Rev 1523
1
#!/usr/bin/perl
1
#!/usr/bin/perl
-
 
2
###########################################################
-
 
3
# Eagle diff script
-
 
4
# Author: Anders Runeson, 2010-07-18, arune @ EFnet
-
 
5
###########################################################
-
 
6
 
2
 
7
 
3
use File::Basename;
8
use File::Basename;
4
use File::Copy;
9
use File::Copy;
5
 
10
 
6
#setup
11
#setup
7
#location of imagemagick compare binary
12
#location of imagemagick compare binary
8
my $compare = "/usr/bin/compare";
13
my $compare = "/usr/bin/compare";
9
#location of eagle binary
14
#location of eagle binary
10
my $eagle = "/usr/bin/eagle";
15
my $eagle = "/usr/bin/eagle";
11
#where to store temporary files
16
#where to store temporary files
12
my $tmpdir = "/tmp";
17
my $tmpdir = "/tmp";
13
#the dpi parameter to send to eagle for generating images
18
#the dpi parameter to send to eagle for generating images
14
my $brdresolution = 1000;
19
my $brdresolution = 1000;
15
my $schresolution = 200;
20
my $schresolution = 200;
16
#store the resulting images at the path of argument 1 or 2
21
#store the resulting images at the path of argument 1 or 2
17
my $storeresult=2;
22
my $storeresult=2;
18
 
23
 
19
#name of eagle script file, will be created
24
#name of eagle script file, will be created
20
my $eaglecommands=$tmpdir."/eaglecmd";
25
my $eaglecommands=$tmpdir."/eaglecmd";
21
 
26
 
22
#check number of arguments, must be 2
27
#check number of arguments, must be 2
23
my $argcount = @ARGV;
28
my $argcount = @ARGV;
24
unless ($argcount eq "2") {
29
unless ($argcount eq "2") {
25
        print "Syntax: perl eagle-compare <file1> <file2>\n";
30
        print "Syntax: perl eagle-compare <file1> <file2>\n";
26
        exit;
31
        exit;
27
}
32
}
28
 
33
 
29
#read arguments and find file suffix
34
#read arguments and find file suffix
30
my $file1 = $ARGV[0];
35
my $file1 = $ARGV[0];
31
my $file2 = $ARGV[1];
36
my $file2 = $ARGV[1];
32
my(undef, undef, $suffix1) = fileparse($file1,qr"\..*");
37
my(undef, undef, $suffix1) = fileparse($file1,qr"\..*");
33
my(undef, undef, $suffix2) = fileparse($file2,qr"\..*");
38
my(undef, undef, $suffix2) = fileparse($file2,qr"\..*");
34
 
39
 
35
#check that files exists
40
#check that files exists
36
unless (-e $file1)
41
unless (-e $file1)
37
  {
42
  {
38
    print "File '$file1' does not exist.\n";
43
    print "File '$file1' does not exist.\n";
39
    exit;
44
    exit;
40
  }
45
  }
41
unless (-e $file2)
46
unless (-e $file2)
42
  {
47
  {
43
    print "File '$file2' does not exist.\n";
48
    print "File '$file2' does not exist.\n";
44
    exit;
49
    exit;
45
  }
50
  }
46
#check that both files have the same suffix
51
#check that both files have the same suffix
47
unless ($suffix1 eq $suffix2)
52
unless ($suffix1 eq $suffix2)
48
  {
53
  {
49
    print "File '$file1' does not have the same file type as '$file2'.\n";
54
    print "File '$file1' does not have the same file type as '$file2'.\n";
50
    exit;
55
    exit;
51
  }
56
  }
52
#check that suffix is a supported one
57
#check that suffix is a supported one
53
unless (($suffix1 eq ".brd") || ($suffix1 eq ".sch"))
58
unless (($suffix1 eq ".brd") || ($suffix1 eq ".sch"))
54
  {
59
  {
55
    print "Only .brd and .sch are supported.\n";
60
    print "Only .brd and .sch are supported.\n";
56
    exit;
61
    exit;
57
  }
62
  }
58
 
63
 
59
my $storedir=$tmpdir;
64
my $storedir=$tmpdir;
60
if ($storeresult == 1)
65
if ($storeresult == 1)
61
{
66
{
62
    $storedir = dirname($file1);
67
    $storedir = dirname($file1);
63
}
68
}
64
if ($storeresult == 2)
69
if ($storeresult == 2)
65
{
70
{
66
    $storedir = dirname($file2);
71
    $storedir = dirname($file2);
67
}
72
}
68
 
73
 
69
#create a file name random, the file names will be too long if they are created with the path
74
#create a file name random, the file names will be too long if they are created with the path
70
$file1unique = $tmpdir."/".generate_random_string(8).$suffix1;
75
$file1unique = $tmpdir."/".generate_random_string(8).$suffix1;
71
$file2unique = $tmpdir."/".generate_random_string(8).$suffix1;
76
$file2unique = $tmpdir."/".generate_random_string(8).$suffix1;
72
 
77
 
73
#copy files to temp area
78
#copy files to temp area
74
copy($file1, $file1unique);
79
copy($file1, $file1unique);
75
copy($file2, $file2unique);
80
copy($file2, $file2unique);
76
 
81
 
77
#if suffix is a layout file
82
#if suffix is a layout file
78
if ($suffix1 eq ".brd")
83
if ($suffix1 eq ".brd")
79
{
84
{
80
    #create eagle script file for first file argument
85
    #create eagle script file for first file argument
81
    open (MYFILE,">".$eaglecommands);
86
    open (MYFILE,">".$eaglecommands);
82
    print MYFILE "SET VECTOR_FONT ON\n";
87
    print MYFILE "SET VECTOR_FONT ON\n";
83
    print MYFILE "DISPLAY ALL\n";
88
    print MYFILE "DISPLAY ALL\n";
84
    print MYFILE "RIPUP @\n";
89
    print MYFILE "RIPUP @\n";
85
    print MYFILE "DISPLAY NONE 17 18 ?? 1\n";
90
    print MYFILE "DISPLAY NONE 17 18 ?? 1\n";
86
    print MYFILE "EXPORT IMAGE ".$file1unique.".1.png ".$brdresolution."\n";
91
    print MYFILE "EXPORT IMAGE ".$file1unique.".1.png ".$brdresolution."\n";
87
    print MYFILE "DISPLAY NONE 17 18 ?? 2\n";
92
    print MYFILE "DISPLAY NONE 17 18 ?? 2\n";
88
    print MYFILE "EXPORT IMAGE ".$file1unique.".2.png ".$brdresolution."\n";
93
    print MYFILE "EXPORT IMAGE ".$file1unique.".2.png ".$brdresolution."\n";
89
    print MYFILE "DISPLAY NONE 17 18 ?? 15\n";
94
    print MYFILE "DISPLAY NONE 17 18 ?? 15\n";
90
    print MYFILE "EXPORT IMAGE ".$file1unique.".15.png ".$brdresolution."\n";
95
    print MYFILE "EXPORT IMAGE ".$file1unique.".15.png ".$brdresolution."\n";
91
    print MYFILE "DISPLAY NONE 17 18 ?? 16\n";
96
    print MYFILE "DISPLAY NONE 17 18 ?? 16\n";
92
    print MYFILE "EXPORT IMAGE ".$file1unique.".16.png ".$brdresolution."\n";
97
    print MYFILE "EXPORT IMAGE ".$file1unique.".16.png ".$brdresolution."\n";
93
    print MYFILE "QUIT\n";
98
    print MYFILE "QUIT\n";
94
    close (MYFILE);
99
    close (MYFILE);
95
   
100
   
96
    #run eagle with the first layout file and the created script file as arguments
101
    #run eagle with the first layout file and the created script file as arguments
97
    #this will create 4 png files in the temp dir
102
    #this will create 4 png files in the temp dir
98
    system ($eagle, $file1unique, "-S", $eaglecommands);
103
    system ($eagle, $file1unique, "-S", $eaglecommands);
99
 
104
 
100
    #create eagle script file for second file argument
105
    #create eagle script file for second file argument
101
    open (MYFILE,">".$eaglecommands);
106
    open (MYFILE,">".$eaglecommands);
102
    print MYFILE "SET VECTOR_FONT ON\n";
107
    print MYFILE "SET VECTOR_FONT ON\n";
103
    print MYFILE "DISPLAY ALL\n";
108
    print MYFILE "DISPLAY ALL\n";
104
    print MYFILE "RIPUP @\n";
109
    print MYFILE "RIPUP @\n";
105
    print MYFILE "DISPLAY NONE 17 18 ?? 1\n";
110
    print MYFILE "DISPLAY NONE 17 18 ?? 1\n";
106
    print MYFILE "EXPORT IMAGE ".$file2unique.".1.png ".$brdresolution."\n";
111
    print MYFILE "EXPORT IMAGE ".$file2unique.".1.png ".$brdresolution."\n";
107
    print MYFILE "DISPLAY NONE 17 18 ?? 2\n";
112
    print MYFILE "DISPLAY NONE 17 18 ?? 2\n";
108
    print MYFILE "EXPORT IMAGE ".$file2unique.".2.png ".$brdresolution."\n";
113
    print MYFILE "EXPORT IMAGE ".$file2unique.".2.png ".$brdresolution."\n";
109
    print MYFILE "DISPLAY NONE 17 18 ?? 15\n";
114
    print MYFILE "DISPLAY NONE 17 18 ?? 15\n";
110
    print MYFILE "EXPORT IMAGE ".$file2unique.".15.png ".$brdresolution."\n";
115
    print MYFILE "EXPORT IMAGE ".$file2unique.".15.png ".$brdresolution."\n";
111
    print MYFILE "DISPLAY NONE 17 18 ?? 16\n";
116
    print MYFILE "DISPLAY NONE 17 18 ?? 16\n";
112
    print MYFILE "EXPORT IMAGE ".$file2unique.".16.png ".$brdresolution."\n";
117
    print MYFILE "EXPORT IMAGE ".$file2unique.".16.png ".$brdresolution."\n";
113
    print MYFILE "QUIT\n";
118
    print MYFILE "QUIT\n";
114
    close (MYFILE);
119
    close (MYFILE);
115
 
120
 
116
    #run eagle with the second layout file and the created script file as arguments
121
    #run eagle with the second layout file and the created script file as arguments
117
    #this will create 4 png files in the temp dir
122
    #this will create 4 png files in the temp dir
118
    system ($eagle, $file2unique, "-S", $eaglecommands);
123
    system ($eagle, $file2unique, "-S", $eaglecommands);
119
   
124
   
120
    #compare each png file for the first file argument and the second file argument
125
    #compare each png file for the first file argument and the second file argument
121
    #the resulting compared images will be stored from where the script is run
126
    #the resulting compared images will be stored from where the script is run
122
    system ($compare, $file1unique.".1.png", $file2unique.".1.png", $storedir."/eagle-diff-brd-layer1.png");
127
    system ($compare, $file1unique.".1.png", $file2unique.".1.png", $storedir."/eagle-diff-brd-layer1.png");
123
    system ($compare, $file1unique.".2.png", $file2unique.".2.png", $storedir."/eagle-diff-brd-layer2.png");
128
    system ($compare, $file1unique.".2.png", $file2unique.".2.png", $storedir."/eagle-diff-brd-layer2.png");
124
    system ($compare, $file1unique.".15.png", $file2unique.".15.png", $storedir."/eagle-diff-brd-layer15.png");
129
    system ($compare, $file1unique.".15.png", $file2unique.".15.png", $storedir."/eagle-diff-brd-layer15.png");
125
    system ($compare, $file1unique.".16.png", $file2unique.".16.png", $storedir."/eagle-diff-brd-layer16.png");
130
    system ($compare, $file1unique.".16.png", $file2unique.".16.png", $storedir."/eagle-diff-brd-layer16.png");
126
   
131
   
127
    #remove all intermediate files
132
    #remove all intermediate files
128
    unlink($file1unique.".1.png");
133
    unlink($file1unique.".1.png");
129
    unlink($file1unique.".2.png");
134
    unlink($file1unique.".2.png");
130
    unlink($file1unique.".15.png");
135
    unlink($file1unique.".15.png");
131
    unlink($file1unique.".16.png");
136
    unlink($file1unique.".16.png");
132
    unlink($file2unique.".1.png");
137
    unlink($file2unique.".1.png");
133
    unlink($file2unique.".2.png");
138
    unlink($file2unique.".2.png");
134
    unlink($file2unique.".15.png");
139
    unlink($file2unique.".15.png");
135
    unlink($file2unique.".16.png");
140
    unlink($file2unique.".16.png");
136
    unlink($eaglecommands);
141
    unlink($eaglecommands);
137
}
142
}
138
 
143
 
139
 
144
 
140
if ($suffix1 eq ".sch")
145
if ($suffix1 eq ".sch")
141
{
146
{
142
    #create eagle script file for first file argument
147
    #create eagle script file for first file argument
143
    open (MYFILE,">".$eaglecommands);
148
    open (MYFILE,">".$eaglecommands);
144
    #print MYFILE "SET VECTOR_FONT ON\n";   # causes a save-dialog-box if not already persistent in this drawing
149
    #print MYFILE "SET VECTOR_FONT ON\n";   # causes a save-dialog-box if not already persistent in this drawing
145
    print MYFILE "DISPLAY NONE 91 92 94 95 96 97 98\n";
150
    print MYFILE "DISPLAY NONE 91 92 94 95 96 97 98\n";
146
    print MYFILE "EXPORT IMAGE ".$file1unique.".png ".$schresolution."\n";
151
    print MYFILE "EXPORT IMAGE ".$file1unique.".png ".$schresolution."\n";
147
    print MYFILE "QUIT\n";
152
    print MYFILE "QUIT\n";
148
    close (MYFILE);
153
    close (MYFILE);
149
 
154
 
150
    #run eagle with the first schematic file and the created script file as arguments
155
    #run eagle with the first schematic file and the created script file as arguments
151
    #this will create one png file in the temp dir
156
    #this will create one png file in the temp dir
152
    system ($eagle, $file1unique, "-S", $eaglecommands);
157
    system ($eagle, $file1unique, "-S", $eaglecommands);
153
 
158
 
154
    #create eagle script file for second file argument
159
    #create eagle script file for second file argument
155
    open (MYFILE,">".$eaglecommands);
160
    open (MYFILE,">".$eaglecommands);
156
    #print MYFILE "SET VECTOR_FONT ON\n";   # causes a save-dialog-box if not already persistent in this drawing
161
    #print MYFILE "SET VECTOR_FONT ON\n";   # causes a save-dialog-box if not already persistent in this drawing
157
    print MYFILE "DISPLAY NONE 91 92 94 95 96 97 98\n";
162
    print MYFILE "DISPLAY NONE 91 92 94 95 96 97 98\n";
158
    print MYFILE "EXPORT IMAGE ".$file2unique.".png ".$schresolution."\n";
163
    print MYFILE "EXPORT IMAGE ".$file2unique.".png ".$schresolution."\n";
159
    print MYFILE "QUIT\n";
164
    print MYFILE "QUIT\n";
160
    close (MYFILE);
165
    close (MYFILE);
161
 
166
 
162
    #run eagle with the second schematic file and the created script file as arguments
167
    #run eagle with the second schematic file and the created script file as arguments
163
    #this will create one png file in the temp dir
168
    #this will create one png file in the temp dir
164
    system ($eagle, $file2unique, "-S", $eaglecommands);
169
    system ($eagle, $file2unique, "-S", $eaglecommands);
165
   
170
   
166
    #compare png file for the first file argument and the second file argument
171
    #compare png file for the first file argument and the second file argument
167
    #the resulting compared image will be stored from where the script is run
172
    #the resulting compared image will be stored from where the script is run
168
    system ($compare, $file1unique.".png", $file2unique.".png", $storedir."/eagle-diff-sch.png");
173
    system ($compare, $file1unique.".png", $file2unique.".png", $storedir."/eagle-diff-sch.png");
169
   
174
   
170
    #remove all intermediate files
175
    #remove all intermediate files
171
    unlink($file1unique.".png");
176
    unlink($file1unique.".png");
172
    unlink($file2unique.".png");
177
    unlink($file2unique.".png");
173
    unlink($eaglecommands);
178
    unlink($eaglecommands);
174
 
179
 
175
}
180
}
176
 
181
 
177
unlink($file1unique);
182
unlink($file1unique);
178
unlink($file2unique);
183
unlink($file2unique);
179
 
184
 
180
 
185
 
181
 
186
 
182
# This function generates random strings of a given length
187
# This function generates random strings of a given length
183
sub generate_random_string
188
sub generate_random_string
184
{
189
{
185
    my $length_of_randomstring=shift;# the length of 
190
    my $length_of_randomstring=shift;# the length of 
186
             # the random string to generate
191
             # the random string to generate
187
 
192
 
188
    my @chars=('a'..'z','A'..'Z','0'..'9','_');
193
    my @chars=('a'..'z','A'..'Z','0'..'9','_');
189
    my $random_string;
194
    my $random_string;
190
    foreach (1..$length_of_randomstring)
195
    foreach (1..$length_of_randomstring)
191
    {
196
    {
192
        # rand @chars will generate a random 
197
        # rand @chars will generate a random 
193
        # number between 0 and scalar @chars
198
        # number between 0 and scalar @chars
194
        $random_string.=$chars[rand @chars];
199
        $random_string.=$chars[rand @chars];
195
    }
200
    }
196
    return $random_string;
201
    return $random_string;
197
}
202
}
198
 
203
 
199
 
204