~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/tools/rom_diff.pl

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2012-02-05 08:09:05 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120205080905-9ej05rmkibowsm7j
Tags: 3.5.5-1
* New upstream version.
* Rewrite debian/copyright, using DEP-5 and updating for 2012.
* Update manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use File::Basename;
 
4
 
 
5
usage() if @ARGV != 2;
 
6
 
 
7
# Generate md5sums for source and destination directories
 
8
my @src_files = `md5sum $ARGV[0]/*`;
 
9
my @dest_files = `md5sum $ARGV[1]/*`;
 
10
 
 
11
# Build hash for source ROMs
 
12
my %src_md5 = ();
 
13
foreach $file (@src_files) {
 
14
  chomp $file;
 
15
  ($md5, $name) = split("  ", $file);
 
16
  $src_md5{ $md5 } = $name;
 
17
}
 
18
print "Found " . keys( %src_md5 ) . " ROMs in " . $ARGV[0] . "\n";
 
19
 
 
20
# Build hash for destination ROMs
 
21
my %dest_md5 = ();
 
22
foreach $file (@dest_files) {
 
23
  chomp $file;
 
24
  ($md5, $name) = split("  ", $file);
 
25
  $dest_md5{ $md5 } = $name;
 
26
}
 
27
print "Found " . keys( %dest_md5 ) . " ROMs in " . $ARGV[1] . "\n";
 
28
 
 
29
my @added = (), @removed = (), @changed = ();
 
30
 
 
31
# Check for added ROMs
 
32
for my $key ( keys %dest_md5 ) {
 
33
  if (defined $src_md5{$key}) {
 
34
    ($src_rom,$path,$type) = fileparse($src_md5{$key});
 
35
    ($dest_rom,$path,$type) = fileparse($dest_md5{$key});
 
36
    if($src_rom ne $dest_rom) {
 
37
      push(@changed, $dest_md5{$key});
 
38
    }
 
39
  }
 
40
  else {
 
41
    push(@added, $dest_md5{$key});
 
42
  }
 
43
}
 
44
 
 
45
# Check for removed ROMs
 
46
for my $key ( keys %src_md5 ) {
 
47
  if (!defined $dest_md5{$key}) {
 
48
    push(@removed, $src_md5{$key});
 
49
  }
 
50
}
 
51
 
 
52
# Report our findings, create directories and copy files
 
53
print "\n";
 
54
my $numAdded = @added;
 
55
print "Added ROMs: $numAdded\n";
 
56
if ($numAdded > 0) {
 
57
  system("mkdir -p ADDED");
 
58
  foreach $rom (@added) {
 
59
    system("cp \"$rom\" ADDED/");
 
60
  }
 
61
}
 
62
my $numRemoved = @removed;
 
63
print "Removed ROMs: $numRemoved\n";
 
64
if ($numRemoved > 0) {
 
65
  system("mkdir -p REMOVED");
 
66
  foreach $rom (@removed) {
 
67
    system("cp \"$rom\" REMOVED/");
 
68
  }
 
69
}
 
70
my $numChanged = @changed;
 
71
print "Changed ROMs: $numChanged\n";
 
72
if ($numChanged > 0) {
 
73
  system("mkdir -p CHANGED");
 
74
  foreach $rom (@changed) {
 
75
    system("cp \"$rom\" CHANGED/");
 
76
  }
 
77
}
 
78
 
 
79
 
 
80
sub usage {
 
81
  print "rom_diff.pl <source directory> <destination directory>\n";
 
82
  print "\n";
 
83
  print "Analyze the ROMs in both directories by md5sum and name.\n";
 
84
  print "Three directories are created named 'ADDED', 'REMOVED' and 'CHANGED',\n";
 
85
  print "indicating the differences in ROMs from the source and destination\n";
 
86
  print "directories.  ROMs are then copied into these new directories as specified.\n";
 
87
  exit(0);
 
88
}