Subversion Repositories computer_asset_manager_v1

Rev

Rev 114 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 114 Rev 115
Line 81... Line 81...
81
   $targetDirectory = "$DATADIR/$targetDirectory";
81
   $targetDirectory = "$DATADIR/$targetDirectory";
82
   `mkdir -p '$targetDirectory'` unless -d $targetDirectory;
82
   `mkdir -p '$targetDirectory'` unless -d $targetDirectory;
83
   `mv '$file' '$targetDirectory'`;
83
   `mv '$file' '$targetDirectory'`;
84
}
84
}
85
 
85
 
-
 
86
sub fixEncoding {
-
 
87
   use Encode qw(decode encode);
-
 
88
 
-
 
89
   my $dir = shift;
-
 
90
 
-
 
91
   opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
-
 
92
   my @files = map{ "$dir/$_" } grep { /\.yaml$/ && -f "$dir/$_" } readdir($dh);
-
 
93
   closedir $dh;
-
 
94
 
-
 
95
   my $count = 0;
-
 
96
 
-
 
97
   foreach my $filename ( @files ) {
-
 
98
      if (  `file -b "$filename"` !~ m/^(ASCII|UTF-8)/ ) {
-
 
99
         $count++;
-
 
100
         open DATA, "<$filename" or die "Could not read $filename: $!\n";
-
 
101
         my $data = join( '', <DATA> );
-
 
102
         close DATA;
-
 
103
         $data = encode( 'UTF-8', $data );
-
 
104
         open DATA, ">$filename" or die "Could not overwrite $filename: $!\n";
-
 
105
         print DATA $data;
-
 
106
         close DATA;
-
 
107
      }
-
 
108
   }
-
 
109
 
-
 
110
return "convertFile found " . scalar( @files ) . " files and processed $count\n";
-
 
111
 
-
 
112
}
-
 
113
 
86
sub validateFileType {
114
sub validateFileType {
87
   my %fileTypeConversions = (
115
   my %fileTypeConversions = (
88
      'ISO-8859' => 'iconv -f ISO-8859-1 -t UTF-8'
116
      'ISO-8859' => 'iconv -f ISO-8859-1 -t UTF-8'
89
      );
117
      );
90
#   use File::Type;
118
#   use File::Type;
Line 126... Line 154...
126
 
154
 
127
#die "$getMailScript\n$processMailScript\n$reportScript\n";
155
#die "$getMailScript\n$processMailScript\n$reportScript\n";
128
# fetch all messages pending from e-mail accounts
156
# fetch all messages pending from e-mail accounts
129
`php $getMailScript` if $CHECKMAIL;
157
`php $getMailScript` if $CHECKMAIL;
130
 
158
 
-
 
159
my $count = 0;
-
 
160
my $results = '';
-
 
161
 
-
 
162
$results .= &fixEncoding( $UNPROCESSED );
-
 
163
 
131
# get a list of all messages waiting to be processed
164
# get a list of all messages waiting to be processed
132
opendir ( my $dh, $UNPROCESSED ) or die "Could not open $UNPROCESSED for read: $!";
165
opendir ( my $dh, $UNPROCESSED ) or die "Could not open $UNPROCESSED for read: $!";
133
my @files = map{ "$UNPROCESSED\/$_" } sort grep { ! /^\./ && -f "$UNPROCESSED/$_" } readdir( $dh );
166
my @files = map{ "$UNPROCESSED\/$_" } sort grep { ! /^\./ && -f "$UNPROCESSED/$_" } readdir( $dh );
134
closedir $dh;
167
closedir $dh;
135
 
168
 
136
#print join( "\n", @files ) . "\n"; die;
169
#print join( "\n", @files ) . "\n"; die;
137
 
170
 
138
my $count = 0;
-
 
139
my $results = '';
-
 
140
 
-
 
141
foreach my $thisFile ( sort @files ) {
171
foreach my $thisFile ( sort @files ) {
142
   my $exitCode;
172
   my $exitCode;
143
   my $tempResults;
173
   my $tempResults;
144
   
174
   
145
#   next unless &validateFileType( $thisFile );
175
#   next unless &validateFileType( $thisFile );