imgtools/buildrom/tools/checkepocroot.pl
author jjkang
Fri, 25 Jun 2010 18:11:34 +0800
changeset 600 6d08f4a05d93
child 626 ac03b93ca9c4
permissions -rw-r--r--
add deprecated files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
#!/usr/bin/perl
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
use Getopt::Long;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
use constant TOOL_VERSION=>"0.1";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
my $help;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
my $dir;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
my $convert;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
my $logfile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
&processcmdline();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
open (LOG, ">$logfile") or die "cannot open log file $logfile\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
&checkdir($dir);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
close LOG;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
sub processcmdline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
	GetOptions("h" => \$help, "l=s" => \$logfile, "c" => \$convert);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
	if ($help)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
		print_usage();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
		exit 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
	$logfile = "checkepocroot.log" if (!defined $logfile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
	$dir = shift @ARGV;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
	if (!defined $dir || !-d $dir)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
		print_usage();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
		die "\nERROR: directory missing!!\n" if (!defined $dir);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
		die "\nERROR: directory $dir does not exist!!\n" if (!-d $dir);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
sub checkdir 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
  my $path = shift;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
  return if (!-d $path);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
  opendir(DIR,$path);   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
  my @entries = readdir(DIR);   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
  closedir(DIR);   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
  my $entry;   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
  foreach $entry (@entries) {   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	  next if (($entry eq ".") || ($entry eq ".."));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
	  my $item = "$path/$entry";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
  	if (-d $item) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
 	 		&checkdir($item);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	  }else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	  	next if ($entry !~ /.*\.[a-z]by$/i);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
	  	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
		  &convobyfile($item, "$item.bak");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
  	}   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
  } 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
}   
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
sub convobyfile
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
	my $src = shift;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
	my $dst = shift;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
	open (SRC, "<$src");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
	open (DST, ">$dst") if($convert);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
	my $line;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	while($line = <SRC>)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
		if ($line =~ /[\\\/]epoc32/)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
	  	print "Found content in file $src\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
	  	print LOG "Found content in file $src\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
	  	print "current line is $line";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
	  	print LOG "current line is $line";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
			if ($line =~ /EPOCROOT##[\\\/]?epoc32/)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
				print "Error: this line already contain EPOCROOT\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
				next;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
	  	if($convert)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
	  	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
		  	$line =~ s-[\\\/]epoc32-EPOCROOT##epoc32-g;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
		  	print "converted line is $line";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
		  	print LOG "converted line is  $line";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
		  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
	  	print "\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
	  	print LOG "\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
		print DST $line  if($convert);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
	close SRC;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
	if($convert)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
		close DST;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
	  unlink "$src";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
  	rename ("$dst", "$src");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
sub print_usage
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
	print "\nCheckepocroot - Check epocroot tool V".TOOL_VERSION."\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
	print "Copyright (c) 2010 Nokia Corporation.\n\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
	print <<USAGE_EOF;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
Usage:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
  checkepocroot.pl [-h] [-c] [-l <logfile>] <directory>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
Check oby/iby files cursively in the <directory>. 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
When it find epoc32 without EPOCROOT## in the files, it will report the line in log file. If with -c option it will add EPOCROOT## to the epoc32.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
The <directory> is the directory contain all the oby/iby files. Usually it should be /epoc32/rom/ and it will be checked cursively.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
Options:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
   -l <logfile>       - the log file to record the log, 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
                        if not specfied it is \"checkepocroot.log\"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
   -h                 - displays this help
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
   -c                 - convert the back slash to forward slash.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
USAGE_EOF
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
}