FreeCalypso > hg > tcs211-fcmodem
comparison g23m/system/busyb/tools/verify_target_folder.pl @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 # | |
2 # verify_target_folder.pl | |
3 # | |
4 # tool to check for make-like dependency | |
5 # | |
6 # format: verify_target_folder.pl temp-folder other-command other-parameters | |
7 # | |
8 # the intention of this command is to modify conditionally a group of files, | |
9 # as would it have done by make. since there is no date information, the tool | |
10 # uses the contents of the files. | |
11 # | |
12 # the behaviour of this script is somehow specific: | |
13 # - it expects that the first parameter of other-parameters is a folder, where | |
14 # files will be generated. other-command is a perl script and will be invoked | |
15 # with "do". | |
16 # - it generates temp-folder | |
17 # - it invokes other-command, but replaces the first parameter with temp-folder | |
18 # - it then verifies temp-folder against the expected result folder (the first | |
19 # parameter). therefor it compares all existing files in temp-folder with | |
20 # equally named files in the other folder. differnt or not existing files | |
21 # in the other folder are replaced by the temp-folder variants. | |
22 # - since the file is already so special, it brings its own comparison tool, | |
23 # that way there is no need to install anything else, that tool compares | |
24 # text files | |
25 # | |
26 # IMPORTANT: | |
27 # since the used rename does not rename over file system boundaries (at least | |
28 # it is not promised), choose your temp-folder accordingly | |
29 # | |
30 | |
31 use strict; | |
32 #use warnings; | |
33 | |
34 my $temp_folder = shift; | |
35 my $other_command = shift; | |
36 my $other_dest_folder = $ARGV[0]; | |
37 | |
38 # normalize $temp_folder | |
39 $temp_folder =~ s|\\|/|g; # only slashes, please | |
40 $temp_folder =~ s|/$||; # no slash at end of path | |
41 | |
42 # modify command_line | |
43 $ARGV[0] = $temp_folder; | |
44 | |
45 die "$temp_folder exists" if -e $temp_folder; | |
46 | |
47 mkdir $temp_folder; | |
48 | |
49 # to be sure, check the contents | |
50 die "unexpected files" if <$temp_folder/*>; | |
51 | |
52 # perform the command, generate the files in the temp folder | |
53 my $result = do $other_command; | |
54 | |
55 if ((! defined $result) && ($! || $@)) | |
56 { | |
57 die "system $other_command failed: $!\n$@"; | |
58 } | |
59 | |
60 # | |
61 # check now the files | |
62 # | |
63 | |
64 my @temp_files = <$temp_folder/*>; | |
65 | |
66 foreach my $temp_file (@temp_files) | |
67 { | |
68 if ($temp_file =~ m|(.*)/(.*)|) | |
69 { | |
70 my $other_file = "$other_dest_folder/$2"; | |
71 | |
72 if ((! -e $other_file) || compare_files($other_file, $temp_file) == 0) | |
73 { | |
74 unlink $other_file; | |
75 rename $temp_file, $other_file; | |
76 } | |
77 } | |
78 } | |
79 | |
80 unlink @temp_files; | |
81 rmdir $temp_folder; | |
82 | |
83 sub get_contents_of_file | |
84 { | |
85 my ($filename) = @_; | |
86 | |
87 open(FILE, "<$filename") or die "open failed: $filename"; | |
88 my @lines = <FILE>; | |
89 my $text = join '', @lines; | |
90 close FILE; | |
91 | |
92 $text | |
93 } | |
94 | |
95 sub compare_files | |
96 { | |
97 my ($file1, $file2) = @_; | |
98 | |
99 get_contents_of_file($file1) eq get_contents_of_file($file2) | |
100 } | |
101 |