]> git.pld-linux.org Git - projects/buildlogs.git/blob - pld-buildlogs/scripts/migration.php
- new versions of buildlogs scripts, not tested at all
[projects/buildlogs.git] / pld-buildlogs / scripts / migration.php
1 #!/usr/bin/php.cli
2 <?php
3 // $Revision: 1.6 $, $Date: 2007/12/02 15:49:42 $
4 /*
5 $root_directory = '/home/services/ftp/pub/pld-buildlogs';
6 $database = 'sqlite:/home/services/httpd/html/pld-buildlogs/db/buildlogs.db';
7 // $root_directory and $database are taken from buildlogs.inc
8 $reverse_addr = array(
9         "th/SRPMS" => 1,
10         "th/i486" => 2,
11         "th/i686" => 3,
12         "th/athlon" => 4,
13         "th/x86_64" => 5,
14         "th/ia64" => 6,
15         "th/alpha" => 7,
16         "th/ppc" => 8,
17         "th/sparc" => 9,
18         "ac/SRPMS" => 10,
19         "ac/i386" => 11,
20         "ac/i586" => 12,
21         "ac/i686" => 13,
22         "ac/athlon" => 14,
23         "ac/amd64" => 15,
24         "ac/alpha" => 16,
25         "ac/ppc" => 17,
26         "ac/sparc" => 18,
27         "ac/sparc64" => 19
28 );
29 */
30 include('buildlogs.inc');
31
32 if (file_exists($database_file)) {
33         unlink($database_file);
34 }
35
36 $query = " CREATE TABLE LOGS(log_id INTEGER PRIMARY KEY, dist TEXT, arch TEXT, ok INTEGER, name TEXT, "
37 . "size INTEGER, mtime INTEGER, id TEXT DEFAULT '');";
38 try {
39         $dbhandle = new PDO("$database");
40 } catch (PDOException $e) {
41         die("new PDO: ". $e->getMessage());
42 }
43
44 $result = array("FAIL", "OK");
45
46 $dh = opendir($root_directory);
47 if ($dh) {
48         die("opendir $root_directory");
49 }
50 while ($dist = readdir($dh)) {
51         if ($dist[0] == '.') continue;
52         if (!is_dir("$root_directory/$dist")) continue;
53         $ah = opendir("$root_directory/$dist");
54         if (!ah) die("opendir $dist");
55         while ($arch = readdir($ah)) {
56                 if ($arch[0] == '.') continue;
57                 if (!is_dir("$root_directory/$dist/$arch")) continue;
58                 for ($ok = 0; $ok < 2; $ok++) {
59                         $directory = "$root_directory/$dist/$arch/" . $result[$ok]
60                         $sh = opendir($directory);
61                         if (!$sh) continue;
62                         while ($file = readdir($sh)) {
63                                 if (preg_match("/^(.*),?(.*)?\.bz2$/", $file, $match)) {
64                                         $f = "$directory/" . $match[0];
65                                         $size = filesize($f);
66                                         $mtime = filemtime($f);
67                                         $name = $match[1];
68                                         if (isset($match[2])) {
69                                                 $id = $match[2];
70                                         } else {
71                                                 $id = "";
72                                         }
73 $query .= " INSERT INTO logs(dist, arch, ok, name, size, mtime, id) "
74 . "VALUES('$dist', '$arch', $ok, '$name', $size, $mtime, '$id');";
75                                 }
76                                 
77                         }
78                         closedir($sh);
79                 }
80         }
81         closedir($ah);
82 }
83 closedir($dh);
84
85 $dbhandle->beginTransaction();
86 $dbhandle->exec("$query");
87 $dbhandle->commit();
88 ?>
This page took 0.034727 seconds and 3 git commands to generate.