still working on pkgsearch.php::do_Details

This commit is contained in:
eric 2004-07-01 22:20:09 +00:00
parent ab6afc990c
commit 993fcb7811
5 changed files with 174 additions and 3 deletions

View file

@ -108,7 +108,6 @@ CREATE TABLE Packages (
CategoryID TINYINT UNSIGNED NOT NULL, CategoryID TINYINT UNSIGNED NOT NULL,
Description CHAR(128) NOT NULL DEFAULT "An Arch Package", Description CHAR(128) NOT NULL DEFAULT "An Arch Package",
URL CHAR(255) NOT NULL DEFAULT "http://www.archlinux.org", URL CHAR(255) NOT NULL DEFAULT "http://www.archlinux.org",
Source CHAR(255) NOT NULL DEFAULT "/dev/null",
LocationID TINYINT UNSIGNED NOT NULL, LocationID TINYINT UNSIGNED NOT NULL,
NumVotes INTEGER UNSIGNED NOT NULL DEFAULT 0, NumVotes INTEGER UNSIGNED NOT NULL DEFAULT 0,
OutOfDate TINYINT UNSIGNED DEFAULT 0, OutOfDate TINYINT UNSIGNED DEFAULT 0,
@ -133,6 +132,24 @@ CREATE TABLE Packages (
); );
-- Track which dependencies a package has
--
CREATE TABLE PackageDepends (
PackageID INTEGER UNSIGNED NOT NULL,
DepPkgID INTEGER UNSIGNED NOT NULL,
INDEX (PackageID)
);
-- Track which sources a package has
--
CREATE TABLE PackageSources (
PackageID INTEGER UNSIGNED NOT NULL,
Source CHAR(255) NOT NULL DEFAULT "/dev/null",
INDEX (PackageID)
);
-- Track votes for packages -- Track votes for packages
-- --
CREATE TABLE PackageVotes ( CREATE TABLE PackageVotes (

Binary file not shown.

View file

@ -20,6 +20,8 @@ MAX_DEVS = .1 # what percentage of MAX_USERS are Developers
MAX_TUS = .2 # what percentage of MAX_USERS are Trusted Users MAX_TUS = .2 # what percentage of MAX_USERS are Trusted Users
MAX_PKGS = 2500 # how many packages to load MAX_PKGS = 2500 # how many packages to load
PKG_FILES = (8, 30) # min/max number of files in a package PKG_FILES = (8, 30) # min/max number of files in a package
PKG_DEPS = (1, 5) # min/max depends a package has
PKG_SRC = (1, 3) # min/max sources a package has
VOTING = (0, .30) # percentage range for package voting VOTING = (0, .30) # percentage range for package voting
RANDOM_PATHS = [ # random path locations for package files RANDOM_PATHS = [ # random path locations for package files
"/usr/bin", "/usr/lib", "/etc", "/etc/rc.d", "/usr/share", "/lib", "/usr/bin", "/usr/lib", "/etc", "/etc/rc.d", "/usr/share", "/lib",
@ -27,6 +29,10 @@ RANDOM_PATHS = [ # random path locations for package files
"/usr/X11R6/lib", "/usr/libexec", "/usr/man/man1", "/usr/man/man3", "/usr/X11R6/lib", "/usr/libexec", "/usr/man/man1", "/usr/man/man3",
"/usr/man/man5", "/usr/X11R6/man/man1", "/etc/profile.d" "/usr/man/man5", "/usr/X11R6/man/man1", "/etc/profile.d"
] ]
RANDOM_TLDS = ["edu", "com", "org", "net", "tw", "ru", "pl", "de", "es"]
RANDOM_URL = ["http://www.", "ftp://ftp.", "http://", "ftp://"]
RANDOM_LOCS = ["pub", "release", "files", "downloads", "src"]
import random import random
import time import time
@ -327,6 +333,38 @@ for p in track_votes.keys():
s = "UPDATE Packages SET NumVotes = %d WHERE ID = %d;\n" % (track_votes[p], p) s = "UPDATE Packages SET NumVotes = %d WHERE ID = %d;\n" % (track_votes[p], p)
out.write(s) out.write(s)
# Create package dependencies and sources
#
if DBUG: print "."; print "Creating statements for package depends/sources.",
count = 0
for p in seen_pkgs.keys():
num_deps = random.randrange(PKG_DEPS[0], PKG_DEPS[1])
this_deps = {}
i = 0
while i != num_deps:
dep = random.randrange(0, len(seen_pkgs))
if not this_deps.has_key(dep):
s = "INSERT INTO PackageDepends VALUES (%d, %d);\n" % (seen_pkgs[p], dep)
out.write(s)
i += 1
num_sources = random.randrange(PKG_SRC[0], PKG_SRC[1])
for i in range(num_sources):
src_file = user_keys[random.randrange(0, len(user_keys))]
src = "%s%s.%s/%s/%s-%s.tar.gz" % (
RANDOM_URL[random.randrange(0,len(RANDOM_URL))],
p, RANDOM_TLDS[random.randrange(0,len(RANDOM_TLDS))],
RANDOM_LOCS[random.randrange(0,len(RANDOM_LOCS))],
src_file, genVersion())
s = "INSERT INTO PackageSources VALUES (%d, '%s');\n" % (
seen_pkgs[p], src)
out.write(s)
if count % 100 == 0:
if DBUG: print ".",
count += 1
# close output file # close output file
# #
out.write("\n") out.write("\n")

View file

@ -140,6 +140,24 @@ function new_sid() {
} }
# obtain the username if given their Users.ID
#
function username_from_id($id="") {
if (!$id) {
return "";
}
$dbh = db_connect();
$q = "SELECT Username FROM Users WHERE ID = " . mysql_escape_string($id);
$result = db_query($q, $dbh);
if (!$result) {
return "None";
}
$row = mysql_fetch_row($result);
return $row[0];
}
# obtain the username if given their current SID # obtain the username if given their current SID
# #
function username_from_sid($sid="") { function username_from_sid($sid="") {

View file

@ -33,10 +33,51 @@ function pkgLocations() {
return $locs; return $locs;
} }
# grab package dependencies
#
function package_dependencies($pkgid=0) {
$deps = array();
if ($pkgid) {
$dbh = db_connect();
$q = "SELECT DepPkgID, Name FROM PackageDepends, Packages ";
$q.= "WHERE PackageDepends.DepPkgID = Packages.ID ";
$q.= "AND PackageDepends.PackageID = ".mysql_escape_string($pkgid);
$q.= " ORDER BY Name";
$result = db_query($q, $dbh);
if (!$result) {return array();}
while ($row = mysql_fetch_row($result)) {
$deps[] = $row;
}
}
return $deps;
}
# grab package sources
#
function package_sources($pkgid=0) {
$sources = array();
if ($pkgid) {
$dbh = db_connect();
$q = "SELECT Source FROM PackageSources ";
$q.= "WHERE PackageID = ".mysql_escape_string($pkgid);
$q.= " ORDER BY Source";
$result = db_query($q, $dbh);
if (!$result) {return array();}
while ($row = mysql_fetch_row($result)) {
$sources[] = $row[0];
}
}
return $sources;
}
# display package details # display package details
# #
function package_details($id=0) { function package_details($id=0) {
$q = "SELECT * FROM Packages WHERE ID = ".intval($_REQUEST["ID"]); $q = "SELECT *,Location,Category ";
$q.= "FROM Packages,PackageLocations,PackageCategories ";
$q.= "WHERE Packages.LocationID = PackageLocations.ID ";
$q.= "AND Packages.CategoryID = PackageCategories.ID ";
$q.= "ANd Packages.ID = ".intval($_REQUEST["ID"]);
$dbh = db_connect(); $dbh = db_connect();
$results = db_query($q, $dbh); $results = db_query($q, $dbh);
if (!$results) { if (!$results) {
@ -63,7 +104,64 @@ function package_details($id=0) {
print "<center>\n"; print "<center>\n";
print "<table>\n"; print "<table>\n";
print "<tr>\n"; print "<tr>\n";
print " <td colspan='2'><span class='f2'>NAME</span></td>\n"; print " <td colspan='2'><span class='f2'>";
print $row["Name"] . "-" . $row["Version"]."</span></td>\n";
print "</tr>\n";
print "<tr>\n";
print " <td colspan='2'><span class='f3'>";
print "<a href='".$row["URL"]."'>".$row["URL"]."</a></span></td>\n";
print "</tr>\n";
print "<tr>\n";
print " <td colspan='2'><span class='f3'>".$row["Description"];
print "</a></span></td>\n";
print "</tr>\n";
print "<tr>\n";
print " <td colspan='2'><img src='/images/pad.gif' height='30'></td>";
print "</tr>\n";
print "<tr>\n";
print " <td colspan='2'><span class='f3'>";
print $row["Location"]." :: ".$row["Category"]."</span></td>";
print "</tr>\n";
print "<tr>\n";
print " <td colspan='2'><span class='f3'>".__("Maintainer").": ";
if (isset($row["AURMaintainerUID"])) {
$maintainer = username_from_id($row["AURMaintainerUID"]);
} elseif (isset($row["MaintainerUID"])) {
$maintainer = username_from_id($row["MaintainerUID"]);
} else {
$maintainer = "None";
}
print $maintainer . "</span></td>";
print "</tr>\n";
print "<tr>\n";
print " <td colspan='2'><img src='/images/pad.gif' height='30'></td>";
print "</tr>\n";
print "<tr>\n";
print " <td valign='top' style='padding-right: 10'>";
print "<table class='boxSoft' style='width: 200px'>";
print "<tr><td class='boxSoftTitle'><span class='f3'>";
print "Dependencies</span></td></tr>\n";
print "<tr><td class='boxSoft'>";
$deps = package_dependencies($row["ID"]); # $deps[0] = array('id','name');
while (list($k, $darr) = each($deps)) {
print $darr[0]." - ".$darr[1]."<br />\n";
}
print "</td></tr>\n";
print "</table></td>";
print " <td valign='top'>";
print "<table class='boxSoft' style='width: 200px'>";
print "<tr><td class='boxSoftTitle'><span class='f3'>";
print "Sources</span></td></tr>\n";
print "<tr><td class='boxSoft'>";
$sources = package_sources($row["ID"]); # $sources[0] = 'src';
while (list($k, $src) = each($sources)) {
# TODO left off here... URLify
print $src."<br />\n";
}
print "</td></tr>\n";
print "</table></td>";
print "</tr>\n"; print "</tr>\n";
print "</table>\n"; print "</table>\n";