jl165 merging heads
[LibreOffice.git] / testgraphical / source / fill_documents_loop.pl
blobc1b8174fefe5fc7de98e34896963a819f0c29065
1 eval 'exec perl -wS $0 ${1+\"$@\"}'
2 if 0;
4 # This program has to start for the new convwatch,
5 # once on Windows environment and once on Linux environment
6 # Solaris is handled by the linux also.
8 # This program polls the database (documentcompare) every 60s for new jobs
9 # it runs over the given directory from documentpoolpath and pool, and create for every file
10 # a new database entry in documents.
13 BEGIN
15 # Adding the path of this script file to the include path in the hope
16 # that all used modules can be found in it.
17 $0 =~ /^(.*)[\/\\]/;
18 push @INC, $1;
21 use ConvwatchHelper;
22 use CallExternals;
23 use stringhelper;
24 use filehelper;
25 use oshelper;
26 use timehelper;
27 use cwstestresulthelper;
29 use strict;
30 use Cwd;
31 use File::Basename;
32 use English; # $OSNAME, ...
33 use Getopt::Long;
34 use File::Path;
35 use Cwd 'chdir';
37 my $cwd = getcwd();
39 our $help; # Help option flag
40 our $version; # Version option flag
41 our $test;
43 our $version_info = 'convwatch.pl $Revision: 1.24 $ ';
45 our $SOLARENV;
46 our $COMMON_ENV_TOOLS;
49 our $documentpoolname;
50 our $documentpoolpath;
51 our $dbdistinct;
52 our $sParentDistinct;
53 our $sCurrentDocumentPool;
55 our $fs;
56 our @aEntries;
58 # Prototypes
59 # sub getJavaFileDirSeparator();
60 sub readdirectory($$$);
61 sub putDocumentInDB($$$);
63 # flush STDOUT
64 my $old_handle = select (STDOUT); # "select" STDOUT and save # previously selected handle
65 $| = 1; # perform flush after each write to STDOUT
66 select ($old_handle); # restore previously selected handle
68 setPrefix("gfxcmp");
70 if (!GetOptions(
71 "test" => \$test,
72 "help" => \$help,
73 "version" => \$version
76 print_usage(*STDERR);
77 exit(1);
79 if ($help)
81 print_usage(*STDOUT);
82 exit(0);
84 # Check for version option
85 if ($version)
87 print STDERR "$version_info\n";
88 exit(0);
91 # ------------------------------------------------------------------------------
92 # within mysql it is better to use only '/'
93 $fs = "/"; # getJavaFileDirSeparator();
94 # ------------------------------------------------------------------------------
95 sub readdirectory($$$)
97 my $startdir = shift;
98 my $sValues = shift;
99 my $hook = shift;
101 my $myfile;
103 local *DIR;
104 chdir $startdir;
105 cwd();
106 if (! endswith($startdir, $fs))
108 $startdir .= $fs;
111 my $nCountFiles = 0;
112 if (opendir (DIR, $startdir)) # Directory oeffnen
114 while ($myfile = readdir(DIR))
115 { # ein filename holen
116 #if (! -l $myfile) # not a link
118 if (-d $myfile ) # is a directory
120 if ( -l $myfile)
122 next;
124 if ($myfile ne "." && $myfile ne "..")
126 my $sNewStartDir = $startdir . $myfile ."/"; # neuen Directorystring erstellen
127 if ($sNewStartDir =~ "^\/proc" ||
128 $sNewStartDir =~ "^\/dev" ||
129 $sNewStartDir =~ "^\/udev" ||
130 $sNewStartDir =~ "lost+found" )
132 next;
134 # my $sNewDestDir = $destdir . $myfile ."/";
135 # do a recursive call
136 # $nCountFiles++;
137 my $nFileCount = readdirectory($sNewStartDir, $sValues, $hook);
138 # workOnDir($sNewDir, $nFileCount);
139 $nCountFiles += $nFileCount;
141 chdir ($startdir); # zurueckwechseln.
142 cwd();
145 else
147 # File must exist, be a regular file and must not be the $onlyOnFile
148 if (-f $myfile)
150 # print " $startdir" . "$myfile\n";
151 $nCountFiles++;
152 # workOnFile($startdir, $myfile, $destdir);
153 $hook->($startdir, $myfile, $sValues);
157 #else
159 # print "linked file: $dir/$myfile\n";
162 closedir(DIR);
164 else
166 print "could not open $startdir\n";
168 return $nCountFiles;
170 # ------------------------------------------------------------------------------
171 sub putDocumentInDB($$$)
173 my $currentDir = shift;
174 my $currentFile = shift;
175 my $sValues = shift;
177 my $sSourceFilename = $currentDir . $currentFile;
178 # we cut down all the previous names like documentpoolpath and the documentpoolname
179 $sSourceFilename = substr($sSourceFilename, length($sCurrentDocumentPool . $fs));
181 my $sSQL = "INSERT INTO documents (dbdistinct2, name, pagecount, priority, parentdistinct) VALUES";
182 $sSQL .= "('" . $dbdistinct . "', '" . $sSourceFilename . "', 0, 1, '". $sParentDistinct . "')";
183 # print $sSQL . "\n";
185 push(@aEntries, $sSQL);
186 # ExecSQL($sSQL);
189 # ------------------------------------------------------------------------------
190 sub createDBEntriesForEveryDocument($)
192 my $sStr = shift;
193 if ($sStr =~ /^MySQL-Error/ )
195 # we don't do anything if an error occured
196 return;
199 # interpret the follows string
200 # documentpoolpath='//so-gfxcmp-documents/doc-pool', documentpool='demo_lla', dbdistinct=62,
202 # my $sDocumentPoolDir;
203 if ( $sStr =~ /documentpoolpath='(.*?)',/ )
205 $documentpoolpath = $1;
207 if (! $documentpoolpath)
209 print "Error: no value for documentpoolpath found.\n";
210 return;
213 # my $sDocumentPool;
214 if ( $sStr =~ /documentpool='(.*?)',/ )
216 $documentpoolname = $1;
218 if (! $documentpoolname)
220 print "Error: no value for documentpool found.\n";
221 return;
223 # my $dbdistinct;
224 if ( $sStr =~ /dbdistinct2='(\S*?)',/ )
226 $dbdistinct = $1;
228 if (! $dbdistinct)
230 print "Error: no dbdistinct given.\n";
231 return;
234 if (! -d $documentpoolpath )
236 my $sEnv = getEnvironment();
237 if ( isUnixEnvironment() )
239 $documentpoolpath = "/net/so-gfxcmp-documents" . $documentpoolpath;
241 if ( -d $documentpoolpath )
243 print "Warning: given documentpoolpath seems to be local, fix to '$documentpoolpath'\n";
244 my $sSQL = "UPDATE documentcompare SET documentpoolpath='$documentpoolpath' WHERE dbdistinct2='$dbdistinct'";
245 print "$sSQL\n";
246 ExecSQL($sSQL);
248 else
250 print "Error: documentpoolpath '$documentpoolpath' not found. Don't insert anything.\n";
251 my $sSQL = "UPDATE documentcompare SET state='failed',info='documentpoolpath not found.' WHERE dbdistinct2='$dbdistinct'";
252 print "$sSQL\n";
253 ExecSQL($sSQL);
254 return;
257 # create the documentpool directory, to run through
258 $sCurrentDocumentPool = $documentpoolpath;
259 if (! endswith($sCurrentDocumentPool, $fs))
261 $sCurrentDocumentPool .= $fs;
263 $sCurrentDocumentPool .= $documentpoolname;
265 if ( -d $sCurrentDocumentPool )
267 if ( $sStr =~ /parentdistinct='(.*?)',/ )
269 $sParentDistinct = $1;
271 else
273 $sParentDistinct = "";
276 # remove any doubles, if any
277 my $sSQL = "DELETE FROM documents WHERE dbdistinct2='$dbdistinct'";
278 print "$sSQL\n";
279 ExecSQL($sSQL);
281 # run over the whole given document pool and store every found document name in the database
282 readdirectory($sCurrentDocumentPool, "", \&putDocumentInDB);
284 chdir $cwd;
285 cwd();
287 foreach $sSQL (@aEntries)
289 # print "# $sSQL\n";
290 print "$sSQL\n";
291 ExecSQL($sSQL);
294 my $sSQL = "UPDATE documentcompare SET state='inprogress' WHERE dbdistinct2='$dbdistinct'";
295 print "$sSQL\n";
296 ExecSQL($sSQL);
297 print "----------------------------------------------------------------------\n";
298 $sParentDistinct = "";
299 @aEntries = ();
301 else
303 print "Error: Given document pool '$sCurrentDocumentPool' doesn't exists.\n";
304 my $sSQL = "UPDATE documentcompare SET state='cancelled' WHERE dbdistinct2='$dbdistinct'";
305 ExecSQL($sSQL);
306 return;
308 # Send Mail, due to startconvwatch now
309 sendMail($sStr, $documentpoolname, $dbdistinct);
312 # ------------------------------------------------------------------------------
313 sub sendMail($$$)
315 my $sStr = shift;
316 my $documentpool = shift;
317 my $dbdistinct = shift;
318 my $sourceversion;
319 if ( $sStr =~ /sourceversion='(.*?)',/ )
321 $sourceversion = $1;
323 if (! $sourceversion)
325 print "Warning: no value for sourceversion found.\n";
326 return;
328 my $destinationversion;
329 if ( $sStr =~ /destinationversion='(.*?)',/ )
331 $destinationversion = $1;
333 if (! $destinationversion)
335 print "Warning: no value for destinationversion found.\n";
336 return;
338 my $mailaddress;
339 if ( $sStr =~ /mailfeedback='(.*?)',/ )
341 $mailaddress = $1;
343 if (! $mailaddress)
345 print "Warning: no value for mailfeedback found.\n";
346 return;
349 # state is 'inprogress', so send a mail
350 # my $sMailAddress = getMailAddress($sDoneStr);
351 my $sParams = "$sourceversion";
352 $sParams .= " $destinationversion";
353 $sParams .= " $documentpool";
354 $sParams .= " $dbdistinct";
355 $sParams .= " $mailaddress";
356 $sParams .= " starts"; # run through state of convwatch
358 my $sMailProgram = appendPath(getQADEVToolsPath(), "mailsend.php");
360 my $err;
361 my @lines;
362 my $sLine;
363 ($err, @lines) = callphp(getPHPExecutable(), $sMailProgram, $sParams);
364 foreach $sLine (@lines)
366 log_print( "Mail: $sLine\n");
369 if ($documentpool eq "EIS-tests")
371 cwstestresult("running", $dbdistinct, $sourceversion, $destinationversion, $SOLARENV, $COMMON_ENV_TOOLS);
374 # ------------------------------------------------------------------------------
375 # ------------------------------------------------------------------------------
377 my $sEnvironmentCondition;
378 if (isWindowsEnvironment())
380 $sEnvironmentCondition = "environment='" . getEnvironment() . "'";
382 elsif (isUnixEnvironment())
384 # $sEnvironmentCondition = " ( environment='unxlngi' OR environment='unxsoli' ) ";
385 $sEnvironmentCondition = " environment='" . getEnvironment() . "'";
387 else
389 print "Error: wrong environment.\n";
390 exit(1);
392 my $sWhereClause = "WHERE ";
393 if ($sEnvironmentCondition)
395 $sWhereClause .= $sEnvironmentCondition . " AND ";
397 $sWhereClause .= " state='new'";
399 setToolsPath(getQADEVToolsPath());
401 # ---------------------------------- main loop ----------------------------------
402 while (1)
404 my @aResult;
405 my $sSQL = "SELECT documentpoolpath,documentpool,dbdistinct2,sourceversion,destinationversion,mailfeedback,parentdistinct FROM documentcompare $sWhereClause";
406 @aResult = ExecSQL($sSQL);
408 my $aValue;
409 foreach $aValue (@aResult)
411 # print "# $nValue\n";
412 createDBEntriesForEveryDocument($aValue);
414 if ($test)
416 last;
419 # wait 30sec.
420 # wait30seconds();
421 waitAMinute();
422 checkForStop("stop_fill_documents_loop");