[aur-dev] [PATCH 1/8] Style fixes: Capitalization of "true" and "false"
Use "true" instead of "TRUE" and "false" instead of "FALSE" or "False". Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/html/packages.php | 6 +++--- web/lib/Archive/Tar.php | 2 +- web/lib/gettext.php | 4 ++-- web/lib/pkgfuncs.inc.php | 18 +++++++++--------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/web/html/packages.php b/web/html/packages.php index a9f6263..f5ecf94 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -64,11 +64,11 @@ if (check_token()) { } elseif (current_action("do_Adopt")) { list($ret, $output) = pkg_adopt($atype, $ids, true); } elseif (current_action("do_Disown")) { - list($ret, $output) = pkg_adopt($atype, $ids, False); + list($ret, $output) = pkg_adopt($atype, $ids, false); } elseif (current_action("do_Vote")) { list($ret, $output) = pkg_vote($atype, $ids, true); } elseif (current_action("do_UnVote")) { - list($ret, $output) = pkg_vote($atype, $ids, False); + list($ret, $output) = pkg_vote($atype, $ids, false); } elseif (current_action("do_Delete")) { if (isset($_POST['confirm_Delete'])) { if (!isset($_POST['merge_Into']) || empty($_POST['merge_Into'])) { @@ -92,7 +92,7 @@ if (check_token()) { } elseif (current_action("do_Notify")) { list($ret, $output) = pkg_notify($atype, $ids); } elseif (current_action("do_UnNotify")) { - list($ret, $output) = pkg_notify($atype, $ids, False); + list($ret, $output) = pkg_notify($atype, $ids, false); } elseif (current_action("do_DeleteComment")) { list($ret, $output) = pkg_delete_comment($atype); } elseif (current_action("do_ChangeCategory")) { diff --git a/web/lib/Archive/Tar.php b/web/lib/Archive/Tar.php index 9249a06..32a2ccc 100644 --- a/web/lib/Archive/Tar.php +++ b/web/lib/Archive/Tar.php @@ -1566,7 +1566,7 @@ class Archive_Tar extends PEAR while (strlen($v_binary_data = $this->_readBlock()) != 0) { - $v_extract_file = FALSE; + $v_extract_file = false; $v_extraction_stopped = 0; if (!$this->_readHeader($v_binary_data, $v_header)) diff --git a/web/lib/gettext.php b/web/lib/gettext.php index 5064047..4ccd75d 100644 --- a/web/lib/gettext.php +++ b/web/lib/gettext.php @@ -410,7 +410,7 @@ class gettext_reader { function pgettext($context, $msgid) { $key = $context . chr(4) . $msgid; $ret = $this->translate($key); - if (strpos($ret, "\004") !== FALSE) { + if (strpos($ret, "\004") !== false) { return $msgid; } else { return $ret; @@ -420,7 +420,7 @@ class gettext_reader { function npgettext($context, $singular, $plural, $number) { $key = $context . chr(4) . $singular; $ret = $this->ngettext($key, $plural, $number); - if (strpos($ret, "\004") !== FALSE) { + if (strpos($ret, "\004") !== false) { return $singular; } else { return $ret; diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 72daaf4..72c64f6 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -20,7 +20,7 @@ function canDeleteComment($comment_id=0, $atype="", $uid=0) { } if ($atype == "Trusted User" || $atype == "Developer") { # A TU/Dev can delete any comment - return TRUE; + return true; } $dbh = DB::connect(); $q = "SELECT COUNT(ID) AS CNT "; @@ -31,10 +31,10 @@ function canDeleteComment($comment_id=0, $atype="", $uid=0) { if ($result != NULL) { $row = $result->fetch(PDO::FETCH_ASSOC); if ($row['CNT'] > 0) { - return TRUE; + return true; } } - return FALSE; + return false; } /** @@ -55,12 +55,12 @@ function canDeleteCommentArray($comment, $atype="", $uid=0) { return false; } elseif ($atype == "Trusted User" || $atype == "Developer") { # A TU/Dev can delete any comment - return TRUE; + return true; } else if ($comment['UsersID'] == $uid) { # User's own comment - return TRUE; + return true; } - return FALSE; + return false; } /** @@ -76,10 +76,10 @@ function canDeleteCommentArray($comment, $atype="", $uid=0) { function canSubmitBlacklisted($atype = "") { if ($atype == "Trusted User" || $atype == "Developer") { # Only TUs/Devs can submit blacklisted packages. - return TRUE; + return true; } else { - return FALSE; + return false; } } @@ -1194,7 +1194,7 @@ function pkg_notify ($atype, $ids, $action=true) { } if ($first) - $first = False; + $first = false; else $output .= ", "; -- 1.8.5.3
* Use C-style comments (/* */) instead of #. * Remove some superfluous comments and slightly reword others. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/acctfuncs.inc.php | 64 +++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index aee56e2..49d7d7c 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -65,7 +65,7 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="", include("account_edit_form.php"); return; -} # function display_account_form() +} /** * Process information given to new/edit account form @@ -91,8 +91,6 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="", */ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", $P="",$C="",$R="",$L="",$I="",$K="",$J="",$UID=0) { - - # error check and process request for a new/modified account global $SUPPORTED_LANGS, $AUR_LOCATION; $error = ''; @@ -151,9 +149,10 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", $error = __("Language is not currently supported."); } if (!$error) { - # check to see if this username is available - # NOTE: a race condition exists here if we care... - # + /* + * Check whether the user name is available. + * TODO: Fix race condition. + */ $q = "SELECT COUNT(*) AS CNT FROM Users "; $q.= "WHERE Username = " . $dbh->quote($U); if ($TYPE == "edit") { @@ -168,9 +167,10 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", } } if (!$error) { - # check to see if this email address is available - # NOTE: a race condition exists here if we care... - # + /* + * Check whether the e-mail address is available. + * TODO: Fix race condition. + */ $q = "SELECT COUNT(*) AS CNT FROM Users "; $q.= "WHERE Email = " . $dbh->quote($E); if ($TYPE == "edit") { @@ -190,7 +190,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", $R, $L, $I, $K, $J, $UID); } else { if ($TYPE == "new") { - # no errors, go ahead and create the unprivileged user + /* Create an unprivileged user. */ $salt = generate_salt(); if (empty($P)) { $send_resetkey = true; @@ -217,8 +217,6 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", print __("Error trying to create account, %s%s%s.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); } else { - # account created/modified, tell them so. - # print __("The account, %s%s%s, has been successfully created.", "<strong>", htmlspecialchars($U,ENT_QUOTES), "</strong>"); print "<p>\n"; @@ -241,8 +239,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="", } } else { - # no errors, go ahead and modify the user account - + /* Modify an existing account. */ $q = "SELECT InactivityTS FROM Users WHERE "; $q.= "ID = " . intval($UID); $result = $dbh->query($q); @@ -433,12 +430,13 @@ function try_login() { $logged_in = 0; $num_tries = 0; - # Account looks good. Generate a SID and store it. - + /* Generate a session ID and store it. */ while (!$logged_in && $num_tries < 5) { if ($MAX_SESSIONS_PER_USER) { - # Delete all user sessions except the - # last ($MAX_SESSIONS_PER_USER - 1). + /* + * Delete all user sessions except the + * last ($MAX_SESSIONS_PER_USER - 1). + */ $q = "DELETE s.* FROM Sessions s "; $q.= "LEFT JOIN (SELECT SessionID FROM Sessions "; $q.= "WHERE UsersId = " . $userID . " "; @@ -455,7 +453,7 @@ function try_login() { ." VALUES (" . $userID . ", '" . $new_sid . "', UNIX_TIMESTAMP())"; $result = $dbh->exec($q); - # Query will fail if $new_sid is not unique + /* Query will fail if $new_sid is not unique. */ if ($result) { $logged_in = 1; break; @@ -470,13 +468,13 @@ function try_login() { $q.= "WHERE ID = '$userID'"; $dbh->exec($q); - # set our SID cookie + /* Set the SID cookie. */ if (isset($_POST['remember_me']) && $_POST['remember_me'] == "on") { - # Set cookies for 30 days. + /* Set cookies for 30 days. */ $cookie_time = time() + $PERSISTENT_COOKIE_TIMEOUT; - # Set session for 30 days. + /* Set session for 30 days. */ $q = "UPDATE Sessions SET LastUpdateTS = $cookie_time "; $q.= "WHERE SessionID = '$new_sid'"; $dbh->exec($q); @@ -540,16 +538,9 @@ function is_ipbanned() { */ function valid_username($user) { if (!empty($user)) { - - #Is username at not too short or too long? if ( strlen($user) >= USERNAME_MIN_LEN && strlen($user) <= USERNAME_MAX_LEN ) { - $user = strtolower($user); - # Does username: - # start and end with a letter or number - # contain only letters and numbers, - # and at most has one dash, period, or underscore if ( preg_match("/^[a-z0-9]+[.\-_]?[a-z0-9]+$/", $user) ) { return true; } @@ -576,7 +567,6 @@ function valid_user($user) { $q.= "WHERE Username = " . $dbh->quote($user); $result = $dbh->query($q); - # Is the username in the database? if ($result) { $row = $result->fetch(PDO::FETCH_NUM); return $row[0]; @@ -661,10 +651,13 @@ function send_resetkey($email, $body) { $uid = uid_from_email($email); if ($uid != NULL && $uid != 'None') { - # We (ab)use new_sid() to get a random 32 characters long string + /* + * We (ab)use new_sid() to get a random 32 characters long + * string. + */ $resetkey = new_sid(); create_resetkey($resetkey, $uid); - # Send email with confirmation link + /* Send e-mail with confirmation link. */ $body = wordwrap($body, 70); $body .= "\n\n". "{$AUR_LOCATION}/" . get_uri('/passreset/') . "?". @@ -729,10 +722,9 @@ function good_passwd($passwd) { function valid_passwd($userID, $passwd) { $dbh = DB::connect(); if ( strlen($passwd) > 0 ) { - # get salt for this user + /* Get salt for this user. */ $salt = get_salt($userID); if ($salt) { - # use salt $q = "SELECT ID FROM Users "; $q.= "WHERE ID = " . $userID . " "; $q.= "AND Passwd = " . $dbh->quote(salted_hash($passwd, $salt)); @@ -744,7 +736,7 @@ function valid_passwd($userID, $passwd) { } } } else { - # check without salt + /* Check password without using salt. */ $q = "SELECT ID FROM Users "; $q.= "WHERE ID = " . $userID . " "; $q.= "AND Passwd = " . $dbh->quote(md5($passwd)); @@ -752,7 +744,7 @@ function valid_passwd($userID, $passwd) { if ($result) { $row = $result->fetch(PDO::FETCH_NUM); if ($row[0]) { - # password correct, but salt it first + /* Password correct, but salt it first! */ if (!save_salt($userID, $passwd)) { trigger_error("Unable to salt user's password;" . " ID " . $userID, E_USER_WARNING); -- 1.8.5.3
* Use C-style comments (/* */) instead of # or //. * Remove some superfluous comments and slightly reword others. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgfuncs.inc.php | 108 ++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 72c64f6..05be21c 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -19,7 +19,7 @@ function canDeleteComment($comment_id=0, $atype="", $uid=0) { return false; } if ($atype == "Trusted User" || $atype == "Developer") { - # A TU/Dev can delete any comment + /* TUs and developers can delete any comment. */ return true; } $dbh = DB::connect(); @@ -54,10 +54,10 @@ function canDeleteCommentArray($comment, $atype="", $uid=0) { /* Unauthenticated users cannot delete anything. */ return false; } elseif ($atype == "Trusted User" || $atype == "Developer") { - # A TU/Dev can delete any comment + /* TUs and developers can delete any comment. */ return true; } else if ($comment['UsersID'] == $uid) { - # User's own comment + /* Users can delete their own comments. */ return true; } return false; @@ -75,7 +75,7 @@ function canDeleteCommentArray($comment, $atype="", $uid=0) { */ function canSubmitBlacklisted($atype = "") { if ($atype == "Trusted User" || $atype == "Developer") { - # Only TUs/Devs can submit blacklisted packages. + /* Only TUs and developers can submit blacklisted packages. */ return true; } else { @@ -218,7 +218,7 @@ function package_comments($pkgid) { $q.= "FROM PackageComments LEFT JOIN Users "; $q.= "ON PackageComments.UsersID = Users.ID "; $q.= "WHERE PackageID = " . $pkgid . " "; - $q.= "AND DelUsersID IS NULL "; # only display non-deleted comments + $q.= "AND DelUsersID IS NULL "; $q.= "ORDER BY CommentTS DESC"; if (!isset($_GET['comments'])) { @@ -259,8 +259,10 @@ function add_package_comment($pkgid, $uid, $comment) { $q.= $dbh->quote($comment) . ", UNIX_TIMESTAMP())"; $dbh->exec($q); - # TODO: Move notification logic to separate function where it belongs - # Send email notifications + /* + * Send e-mail notifications. + * TODO: Move notification logic to separate function where it belongs. + */ $q = "SELECT CommentNotify.*, Users.Email "; $q.= "FROM CommentNotify, Users "; $q.= "WHERE Users.ID = CommentNotify.UserID "; @@ -280,9 +282,12 @@ function add_package_comment($pkgid, $uid, $comment) { $result = $dbh->query($q); $row = $result->fetch(PDO::FETCH_ASSOC); - # TODO: native language emails for users, based on their prefs - # Simply making these strings translatable won't work, users would be - # getting emails in the language that the user who posted the comment was in + /* + * TODO: Add native language emails for users, based on their + * preferences. Simply making these strings translatable won't + * work, users would be getting emails in the language that the + * user who posted the comment was in. + */ $body = 'from ' . $AUR_LOCATION . get_pkg_uri($row['Name']) . "\n" . username_from_sid($_COOKIE['AURSID']) . " wrote:\n\n" @@ -453,13 +458,11 @@ function display_package_details($id=0, $row, $SID="") { else { include('pkg_details.php'); - # Actions Bar if ($SID) { include('actions_form.php'); include('pkg_comment_form.php'); } - # Print Comments $comments = package_comments($id); if (!empty($comments)) { include('pkg_comments.php'); @@ -515,16 +518,15 @@ function display_package_details($id=0, $row, $SID="") { function pkg_search_page($SID="") { $dbh = DB::connect(); - // get commonly used variables... - // TODO: REDUCE DB HITS. - // grab info for user if they're logged in + /* + * Get commonly used variables. + * TODO: Reduce the number of database queries! + */ if ($SID) $myuid = uid_from_sid($SID); - // get a list of package categories - $cats = pkgCategories($dbh); //meow + $cats = pkgCategories($dbh); - // sanitize paging variables - // + /* Sanitize paging variables. */ if (isset($_GET['O'])) { $_GET['O'] = intval($_GET['O']); if ($_GET['O'] < 0) @@ -545,12 +547,12 @@ function pkg_search_page($SID="") { $_GET["PP"] = 50; } - // FIXME: pull out DB-related code. all of it. - // this one's worth a choco-chip cookie, - // one of those nice big soft ones + /* + * FIXME: Pull out DB-related code. All of it! This one's worth a + * choco-chip cookie, one of those nice big soft ones. + */ - // build the package search query - // + /* Build the package search query. */ $q_select = "SELECT "; if ($SID) { $q_select .= "CommentNotify.UserID AS Notify, @@ -566,7 +568,7 @@ function pkg_search_page($SID="") { LEFT JOIN PackageCategories ON (Packages.CategoryID = PackageCategories.ID) "; if ($SID) { - # this portion is not needed for the total row count query + /* This is not needed for the total row count query. */ $q_from_extra = "LEFT JOIN PackageVotes ON (Packages.ID = PackageVotes.PackageID AND PackageVotes.UsersID = $myuid) LEFT JOIN CommentNotify @@ -576,32 +578,34 @@ function pkg_search_page($SID="") { } $q_where = "WHERE 1 = 1 "; - // TODO: possibly do string matching on category - // to make request variable values more sensible + /* + * TODO: Possibly do string matching on category to make request + * variable values more sensible. + */ if (isset($_GET["C"]) && intval($_GET["C"])) { $q_where .= "AND Packages.CategoryID = ".intval($_GET["C"])." "; } if (isset($_GET['K'])) { - # Search by maintainer if (isset($_GET["SeB"]) && $_GET["SeB"] == "m") { + /* Search by maintainer. */ $q_where .= "AND Users.Username = " . $dbh->quote($_GET['K']) . " "; } - # Search by submitter elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") { + /* Search by submitter. */ $q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'])." "; } - # Search by name elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") { + /* Search by name. */ $K = "%" . addcslashes($_GET['K'], '%_') . "%"; $q_where .= "AND (Name LIKE " . $dbh->quote($K) . ") "; } - # Search by name (exact match) elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "x") { + /* Search by name (exact match). */ $q_where .= "AND (Name = " . $dbh->quote($_GET['K']) . ") "; } - # Search by name and description (Default) else { + /* Search by name and description (default). */ $K = "%" . addcslashes($_GET['K'], '%_') . "%"; $q_where .= "AND (Name LIKE " . $dbh->quote($K) . " OR "; $q_where .= "Description LIKE " . $dbh->quote($K) . ") "; @@ -676,10 +680,10 @@ function pkg_search_page($SID="") { } } - // figure out the results to use + /* Calculate the results to use. */ $first = $_GET['O'] + 1; - # calculation of pagination links + /* Calculation of pagination links. */ $per_page = ($_GET['PP'] > 0) ? $_GET['PP'] : 50; $current = ceil($first / $per_page); $pages = ceil($total / $per_page); @@ -779,7 +783,7 @@ function pkg_flag($atype, $ids) { $affected_pkgs = $dbh->exec($q); if ($affected_pkgs > 0) { - # Notify of flagging by email + /* Notify of flagging by e-mail. */ $f_name = username_from_sid($_COOKIE['AURSID']); $f_email = email_from_sid($_COOKIE['AURSID']); $f_uid = uid_from_sid($_COOKIE['AURSID']); @@ -791,7 +795,6 @@ function pkg_flag($atype, $ids) { $result = $dbh->query($q); if ($result) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - # construct email $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . " [1]. You may view your package at:\n" . $AUR_LOCATION . get_pkg_uri($row['Name']) . "\n\n[1] - " . $AUR_LOCATION . get_user_uri($f_name); $body = wordwrap($body, 70); $headers = "Reply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n"; @@ -852,7 +855,6 @@ function pkg_delete ($atype, $ids, $mergepkgid) { return array(false, __("You must be logged in before you can delete packages.")); } - # If they're a TU or dev, can delete if ($atype != "Trusted User" && $atype != "Developer") { return array(false, __("You do not have permission to delete packages.")); } @@ -868,7 +870,7 @@ function pkg_delete ($atype, $ids, $mergepkgid) { $mergepkgname = pkgname_from_id($mergepkgid); } - # Send email notifications + /* Send e-mail notifications. */ foreach ($ids as $pkgid) { $q = "SELECT CommentNotify.*, Users.Email "; $q.= "FROM CommentNotify, Users "; @@ -884,9 +886,13 @@ function pkg_delete ($atype, $ids, $mergepkgid) { if (!empty($bcc)) { $pkgname = pkgname_from_id($pkgid); - # TODO: native language emails for users, based on their prefs - # Simply making these strings translatable won't work, users would be - # getting emails in the language that the user who posted the comment was in + /* + * TODO: Add native language emails for users, based on + * their preferences. Simply making these strings + * translatable won't work, users would be getting + * emails in the language that the user who posted the + * comment was in. + */ $body = ""; if ($mergepkgid) { $body .= username_from_sid($_COOKIE['AURSID']) . " merged \"".$pkgname."\" into \"$mergepkgname\".\n\n"; @@ -977,7 +983,7 @@ function pkg_adopt ($atype, $ids, $action=true) { $q.= "WHERE ID IN (" . implode(",", $ids) . ") "; if ($action && $atype == "User") { - # Regular users may only adopt orphan packages from unsupported + /* Regular users may only adopt orphan packages. */ $q.= "AND $field IS NULL "; } else if ($atype == "User") { $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]); @@ -1048,8 +1054,7 @@ function pkg_vote ($atype, $ids, $action=true) { } } - # only vote for packages the user hasn't already voted for - # + /* Only add votes for packages the user hasn't already voted for. */ $op = $action ? "+" : "-"; $q = "UPDATE Packages SET NumVotes = NumVotes $op 1 "; $q.= "WHERE ID IN ($vote_ids)"; @@ -1164,7 +1169,6 @@ function user_notify($uid, $pkgid) { */ function pkg_notify ($atype, $ids, $action=true) { if (!$atype) { -# return __("You must be logged in before you can get notifications on comments."); return; } @@ -1180,8 +1184,10 @@ function pkg_notify ($atype, $ids, $action=true) { $first = true; - # There currently shouldn't be multiple requests here, but the - # format in which it's sent requires this. + /* + * There currently shouldn't be multiple requests here, but the format + * in which it's sent requires this. + */ foreach ($ids as $pid) { $q = "SELECT Name FROM Packages WHERE ID = $pid"; $result = $dbh->query($q); @@ -1203,7 +1209,7 @@ function pkg_notify ($atype, $ids, $action=true) { $q = "SELECT COUNT(*) FROM CommentNotify WHERE "; $q .= "UserID = $uid AND PkgID = $pid"; - # Notification already added. Don't add again. + /* Notification already added. Don't add again. */ $result = $dbh->query($q); if ($result->fetchColumn() == 0) { $q = "INSERT INTO CommentNotify (PkgID, UserID) VALUES ($pid, $uid)"; @@ -1243,7 +1249,6 @@ function pkg_delete_comment($atype) { return array(false, __("You must be logged in before you can edit package information.")); } - # Get ID of comment to be removed if (isset($_POST["comment_id"])) { $comment_id = $_POST["comment_id"]; } else { @@ -1275,7 +1280,6 @@ function pkg_change_category($pid, $atype) { return array(false, __("You must be logged in before you can edit package information.")); } - # Get ID of the new category if (isset($_POST["category_id"])) { $category_id = $_POST["category_id"]; } else { @@ -1288,7 +1292,7 @@ function pkg_change_category($pid, $atype) { return array(false, __("Invalid category ID.")); } - # Verify package ownership + /* Verify package ownership. */ $q = "SELECT Packages.MaintainerUID "; $q.= "FROM Packages "; $q.= "WHERE Packages.ID = ".$pid; @@ -1373,7 +1377,7 @@ function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pk */ function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid, $pkgid) { $dbh = DB::connect(); - # This is an overwrite of an existing package + /* This is an overwrite of an existing package! */ $q = sprintf("UPDATE Packages SET ModifiedTS = UNIX_TIMESTAMP(), Name = %s, Version = %s, License = %s, Description = %s, URL = %s, OutOfDateTS = NULL, MaintainerUID = %d WHERE ID = %d", $dbh->quote($pkgname), $dbh->quote($pkgver), -- 1.8.5.3
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/acctfuncs.inc.php | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 49d7d7c..f705574 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -537,17 +537,14 @@ function is_ipbanned() { * @return bool True if username meets criteria, otherwise false */ function valid_username($user) { - if (!empty($user)) { - if ( strlen($user) >= USERNAME_MIN_LEN && - strlen($user) <= USERNAME_MAX_LEN ) { - $user = strtolower($user); - if ( preg_match("/^[a-z0-9]+[.\-_]?[a-z0-9]+$/", $user) ) { - return true; - } - } + if (strlen($user) < USERNAME_MIN_LEN || + strlen($user) > USERNAME_MAX_LEN) { + return false; + } else if (!preg_match("/^[a-z0-9]+[.\-_]?[a-z0-9]+$/", $user)) { + return false; } - return false; + return true; } /** @@ -558,21 +555,17 @@ function valid_username($user) { * @return string|void Return user ID if in database, otherwise void */ function valid_user($user) { - /* if ( $user = valid_username($user) ) { */ - - $dbh = DB::connect(); - - if ( $user ) { - $q = "SELECT ID FROM Users "; - $q.= "WHERE Username = " . $dbh->quote($user); + if ($user) { + $dbh = DB::connect(); + $q = "SELECT ID FROM Users WHERE "; + $q.= "Username = " . $dbh->quote($user); $result = $dbh->query($q); if ($result) { $row = $result->fetch(PDO::FETCH_NUM); return $row[0]; } } - return; } /** -- 1.8.5.3
Use COUNT(*) instead of COUNT(ID) and PDO::FETCH_NUM instead of PDO::FETCH_ASSOC. This also includes some minor formatting fixes. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgfuncs.inc.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 05be21c..59cc975 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -22,19 +22,19 @@ function canDeleteComment($comment_id=0, $atype="", $uid=0) { /* TUs and developers can delete any comment. */ return true; } + $dbh = DB::connect(); - $q = "SELECT COUNT(ID) AS CNT "; - $q.= "FROM PackageComments "; - $q.= "WHERE ID = " . intval($comment_id); - $q.= " AND UsersID = " . $uid; + + $q = "SELECT COUNT(*) FROM PackageComments "; + $q.= "WHERE ID = " . intval($comment_id) . " AND UsersID = " . $uid; $result = $dbh->query($q); - if ($result != NULL) { - $row = $result->fetch(PDO::FETCH_ASSOC); - if ($row['CNT'] > 0) { - return true; - } + + if (!$result) { + return false; } - return false; + + $row = $result->fetch(PDO::FETCH_NUM); + return ($row[0] > 0); } /** -- 1.8.5.3
* Add information on mkaurball and metadata parsing. * Slightly update the feature section. * Remove the top-level directory file listing. * Consolidate sections with links to our online presence. * Reformat everything for consistency. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- README | 95 +++++++++++++++++++++++++++--------------------------------------- 1 file changed, 39 insertions(+), 56 deletions(-) diff --git a/README b/README index 8f6892a..7688ab5 100644 --- a/README +++ b/README @@ -1,67 +1,50 @@ -=================== Arch User Repository (AUR) -=================== +========================== -About: -===== The Arch User Repository (AUR) is a framework for hosting a collection of packaging scripts that are created and submitted by the Arch community. The -scripts contained in the repository (PKGBUILDS) can be built using the Arch -building/packaging script (makepkg) and installed via the Arch pacman manager -(pacman). The AUR project aims to provide the necessary web interface, database -schema, and scripts for a multi-lingual community-driven repository. +scripts contained in the repository (PKGBUILDs) can be built using the AUR +building/packaging script `mkaurball` and installed via the Arch package +manager `pacman`. The AUR project aims to provide the necessary web interface, +database schema, and scripts for a multi-lingual community-driven repository. -Functionality: -========= --Users may submit source packages that contain a PKGBUILD --User accounts with varying permission levels (User, Trusted User, Developer) --Ability to search for specific submitted packages (based on package name, -package description, package submitter, package maintainer) --Display submitted package information by parsing PKGBUILD (description, -license, package dependencies, etc) --Users can make comments on package information page --Mark packages as out-of-date --Vote for well-done and popular user submitted packages --Trusted User and Developer have ability to search for and modify accounts --Area for Trusted Users -and Developers to post AUR-related proposals and vote on them +Functionality +------------- -File Hierarchy: -========== +* Users may submit source packages that contain a PKGBUILD. +* User accounts with varying permission levels (User, Trusted User, Developer). +* Ability to search for specific submitted packages. +* Display package information by parsing meta-data provided with the packages. +* Users can make comments on package information page. +* Mark packages as out-of-date. +* Vote for well-done and popular user submitted packages. +* Trusted User and Developer can search for and modify accounts. +* Area for Trusted Users to post AUR-related proposals and vote on them. -Directory Layout: -------------------- -./po - Translation files for strings in the AUR web - interface. -./scripts - aurblup package blacklist tool. Scripts for AUR - maintenance. -./support - Schema for SQL database. Script for dummy data generation. -./web - Web interface for the AUR. +Directory Layout +---------------- -Files: ------- -AUTHORS - List of maintainers, contributors, and translators for AUR - project. -COPYING - License information for AUR project (GPL version 2). -HACKING - Guidelines for modifying source and submitting - patches. -INSTALL - Installation procedure for AUR. -TODO - List of potential features and changes to be made to the AUR. -TRANSLATING - Directions for creating and updating string translations. -UPGRADING - Changes needed to upgrade older AUR version to newer version. +po:: + Translation files for strings in the AUR web interface. -Code: -===== -Official repository hosted at git://projects.archlinux.org/aur.git -See HACKING for information on submitting patches +scripts:: + aurblup package blacklist tool. Scripts for AUR maintenance. -Bugs: -===== -Discovered bugs can be submitted to the AUR bug tracker: -https://bugs.archlinux.org/index.php?project=2 +support:: + Schema for SQL database. Script for dummy data generation. -Contact: -======== -Questions, comments, and patches related to the AUR can be sent to the AUR -development mailing list: aur-dev@archlinux.org -Mailing list archives: https://mailman.archlinux.org/mailman/listinfo/aur-dev +web:: + Web interface for the AUR. + +Links +----- + +* The official repository is hosted at git://projects.archlinux.org/aur.git -- + see HACKING for information on submitting patches. + +* Discovered bugs can be submitted to the AUR bug tracker: + https://bugs.archlinux.org/index.php?project=2 + +* Questions, comments, and patches related to the AUR can be sent to the AUR + development mailing list: aur-dev@archlinux.org -- mailing list archives: + https://mailman.archlinux.org/mailman/listinfo/aur-dev -- 1.8.5.3
There haven't been any real changes to this file for more than five years. Most of the items mentioned have been addressed. Use the bug tracker for further feature requests or general issues. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- TODO | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index ccd19be..0000000 --- a/TODO +++ /dev/null @@ -1,17 +0,0 @@ -TODO - -Here's a list of things that currently need doing in the AUR which -aren't bugs that need investigation, they just need some time to fix. -Don't forget to remove anything from this list that gets fixed if you -can and feel free to add to it. - -* HTML basically needs a complete rewrite, rife with broken html -* Use mod_rewrite for urls, allows for nicer looking urls and no more - deciphering of those insane variables -* Rename those insane variables (the url variables on the search page), - probably make them more verbose and actually relate to what they are -- Shuffle around secondary nav links (does every page really need - bugs/discuss/etc? front page material?) -- search page formattting (squashed columns) -- improve package searching (fulltext is nifty, needs discussion) - -- 1.8.5.3
There aren't any other subdirectories in support/. Reduce the nesting depth by moving schema/ to the top-level source directory. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- INSTALL | 4 +- schema/aur-schema.sql | 228 +++++++++++++++++++++++++++++++ schema/gendummydata.py | 302 +++++++++++++++++++++++++++++++++++++++++ schema/reloadtestdb.sh | 29 ++++ support/schema/aur-schema.sql | 228 ------------------------------- support/schema/gendummydata.py | 302 ----------------------------------------- support/schema/reloadtestdb.sh | 29 ---- 7 files changed, 561 insertions(+), 561 deletions(-) create mode 100644 schema/aur-schema.sql create mode 100755 schema/gendummydata.py create mode 100755 schema/reloadtestdb.sh delete mode 100644 support/schema/aur-schema.sql delete mode 100755 support/schema/gendummydata.py delete mode 100755 support/schema/reloadtestdb.sh diff --git a/INSTALL b/INSTALL index e8bf797..cbb9f44 100644 --- a/INSTALL +++ b/INSTALL @@ -66,12 +66,12 @@ Setup on Arch Linux: mysql> quit - Load the schema file - $ mysql -uaur -p AUR < ~/aur/support/schema/aur-schema.sql + $ mysql -uaur -p AUR < ~/aur/schema/aur-schema.sql (give password 'aur' at the prompt) - Optionally load some test data for development purposes. # pacman -S words fortune-mod - $ cd ~/aur/support/schema/ + $ cd ~/aur/schema/ $ python gendummydata.py dummy-data.sql $ bzip2 dummy-data.sql $ bzcat dummy-data.sql.bz2 | mysql -uaur -p AUR diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql new file mode 100644 index 0000000..c01701c --- /dev/null +++ b/schema/aur-schema.sql @@ -0,0 +1,228 @@ +-- The MySQL database layout for the AUR. Certain data +-- is also included such as AccountTypes, etc. +-- +DROP DATABASE IF EXISTS AUR; +CREATE DATABASE AUR DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; +USE AUR; + +-- Define the Account Types for the AUR. +-- +CREATE TABLE AccountTypes ( + ID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, + AccountType VARCHAR(32) NOT NULL DEFAULT '', + PRIMARY KEY (ID) +) ENGINE = InnoDB; +INSERT INTO AccountTypes (ID, AccountType) VALUES (1, 'User'); +INSERT INTO AccountTypes (ID, AccountType) VALUES (2, 'Trusted User'); +INSERT INTO AccountTypes (ID, AccountType) VALUES (3, 'Developer'); + + +-- User information for each user regardless of type. +-- +CREATE TABLE Users ( + ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + AccountTypeID TINYINT UNSIGNED NOT NULL DEFAULT 1, + Suspended TINYINT UNSIGNED NOT NULL DEFAULT 0, + Username VARCHAR(32) NOT NULL, + Email VARCHAR(64) NOT NULL, + Passwd CHAR(32) NOT NULL, + Salt CHAR(32) NOT NULL DEFAULT '', + ResetKey CHAR(32) NOT NULL DEFAULT '', + RealName VARCHAR(64) NOT NULL DEFAULT '', + LangPreference VARCHAR(5) NOT NULL DEFAULT 'en', + IRCNick VARCHAR(32) NOT NULL DEFAULT '', + PGPKey VARCHAR(40) NULL DEFAULT NULL, + LastVoted BIGINT UNSIGNED NOT NULL DEFAULT 0, + LastLogin BIGINT UNSIGNED NOT NULL DEFAULT 0, + LastLoginIPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0, + InactivityTS BIGINT UNSIGNED NOT NULL DEFAULT 0, + RegistrationTS TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (ID), + UNIQUE (Username), + UNIQUE (Email), + INDEX (AccountTypeID), + FOREIGN KEY (AccountTypeID) REFERENCES AccountTypes(ID) ON DELETE NO ACTION +) ENGINE = InnoDB; +-- A default developer account for testing purposes +INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd) VALUES ( + 1, 3, 'dev', 'dev@localhost', MD5('dev')); +INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd) VALUES ( + 2, 2, 'tu', 'tu@localhost', MD5('tu')); +INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd) VALUES ( + 3, 1, 'user', 'user@localhost', MD5('user')); + + +-- Track Users logging in/out of AUR web site. +-- +CREATE TABLE Sessions ( + UsersID INTEGER UNSIGNED NOT NULL, + SessionID CHAR(32) NOT NULL, + LastUpdateTS BIGINT UNSIGNED NOT NULL, + FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE, + UNIQUE (SessionID) +) ENGINE = InnoDB; + + +-- Categories for grouping packages when they reside in +-- Unsupported or the AUR - based on the categories defined +-- in 'extra'. +-- +CREATE TABLE PackageCategories ( + ID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, + Category VARCHAR(32) NOT NULL, + PRIMARY KEY (ID) +) ENGINE = InnoDB; +INSERT INTO PackageCategories (Category) VALUES ('none'); +INSERT INTO PackageCategories (Category) VALUES ('daemons'); +INSERT INTO PackageCategories (Category) VALUES ('devel'); +INSERT INTO PackageCategories (Category) VALUES ('editors'); +INSERT INTO PackageCategories (Category) VALUES ('emulators'); +INSERT INTO PackageCategories (Category) VALUES ('games'); +INSERT INTO PackageCategories (Category) VALUES ('gnome'); +INSERT INTO PackageCategories (Category) VALUES ('i18n'); +INSERT INTO PackageCategories (Category) VALUES ('kde'); +INSERT INTO PackageCategories (Category) VALUES ('lib'); +INSERT INTO PackageCategories (Category) VALUES ('modules'); +INSERT INTO PackageCategories (Category) VALUES ('multimedia'); +INSERT INTO PackageCategories (Category) VALUES ('network'); +INSERT INTO PackageCategories (Category) VALUES ('office'); +INSERT INTO PackageCategories (Category) VALUES ('science'); +INSERT INTO PackageCategories (Category) VALUES ('system'); +INSERT INTO PackageCategories (Category) VALUES ('x11'); +INSERT INTO PackageCategories (Category) VALUES ('xfce'); +INSERT INTO PackageCategories (Category) VALUES ('fonts'); + + +-- Information about the actual packages +-- +CREATE TABLE Packages ( + ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + Name VARCHAR(64) NOT NULL, + Version VARCHAR(32) NOT NULL DEFAULT '', + CategoryID TINYINT UNSIGNED NOT NULL DEFAULT 1, + Description VARCHAR(255) NOT NULL DEFAULT "An Arch Package", + URL VARCHAR(255) NOT NULL DEFAULT "https://www.archlinux.org", + License VARCHAR(40) NOT NULL DEFAULT '', + NumVotes INTEGER UNSIGNED NOT NULL DEFAULT 0, + OutOfDateTS BIGINT UNSIGNED NULL DEFAULT NULL, + SubmittedTS BIGINT UNSIGNED NOT NULL, + ModifiedTS BIGINT UNSIGNED NOT NULL, + SubmitterUID INTEGER UNSIGNED NULL DEFAULT NULL, -- who submitted it? + MaintainerUID INTEGER UNSIGNED NULL DEFAULT NULL, -- User + PRIMARY KEY (ID), + UNIQUE (Name), + INDEX (CategoryID), + INDEX (NumVotes), + INDEX (SubmitterUID), + INDEX (MaintainerUID), + FOREIGN KEY (CategoryID) REFERENCES PackageCategories(ID) ON DELETE NO ACTION, + -- deleting a user will cause packages to be orphaned, not deleted + FOREIGN KEY (SubmitterUID) REFERENCES Users(ID) ON DELETE SET NULL, + FOREIGN KEY (MaintainerUID) REFERENCES Users(ID) ON DELETE SET NULL +) ENGINE = InnoDB; + + +-- Track which dependencies a package has +-- +CREATE TABLE PackageDepends ( + PackageID INTEGER UNSIGNED NOT NULL, + DepName VARCHAR(64) NOT NULL, + DepCondition VARCHAR(20), + INDEX (PackageID), + INDEX (DepName), + FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE +) ENGINE = InnoDB; + + +-- Track which sources a package has +-- +CREATE TABLE PackageSources ( + PackageID INTEGER UNSIGNED NOT NULL, + Source VARCHAR(255) NOT NULL DEFAULT "/dev/null", + INDEX (PackageID), + FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE +) ENGINE = InnoDB; + + +-- Track votes for packages +-- +CREATE TABLE PackageVotes ( + UsersID INTEGER UNSIGNED NOT NULL, + PackageID INTEGER UNSIGNED NOT NULL, + INDEX (UsersID), + INDEX (PackageID), + FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE, + FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE +) ENGINE = InnoDB; +CREATE UNIQUE INDEX VoteUsersIDPackageID ON PackageVotes (UsersID, PackageID); + +-- Record comments for packages +-- +CREATE TABLE PackageComments ( + ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + PackageID INTEGER UNSIGNED NOT NULL, + UsersID INTEGER UNSIGNED NULL DEFAULT NULL, + Comments TEXT NOT NULL DEFAULT '', + CommentTS BIGINT UNSIGNED NOT NULL DEFAULT 0, + DelUsersID INTEGER UNSIGNED NULL DEFAULT NULL, + PRIMARY KEY (ID), + INDEX (UsersID), + INDEX (PackageID), + FOREIGN KEY (UsersID) REFERENCES Users(ID) ON SET NULL, + FOREIGN KEY (DelUsersID) REFERENCES Users(ID) ON DELETE CASCADE, + FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE +) ENGINE = InnoDB; + +-- Comment addition notifications +-- +CREATE TABLE CommentNotify ( + PkgID INTEGER UNSIGNED NOT NULL, + UserID INTEGER UNSIGNED NOT NULL, + FOREIGN KEY (PkgID) REFERENCES Packages(ID) ON DELETE CASCADE, + FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE +) ENGINE = InnoDB; +CREATE UNIQUE INDEX NotifyUserIDPkgID ON CommentNotify (UserID, PkgID); + +-- Package name blacklist +-- +CREATE TABLE PackageBlacklist ( + ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + Name VARCHAR(64) NOT NULL, + PRIMARY KEY (ID), + UNIQUE (Name) +) ENGINE = InnoDB; + +-- Vote information +-- +CREATE TABLE IF NOT EXISTS TU_VoteInfo ( + ID int(10) unsigned NOT NULL auto_increment, + Agenda text NOT NULL, + User VARCHAR(32) NOT NULL, + Submitted bigint(20) unsigned NOT NULL, + End bigint(20) unsigned NOT NULL, + Quorum decimal(2, 2) unsigned NOT NULL, + SubmitterID int(10) unsigned NOT NULL, + Yes tinyint(3) unsigned NOT NULL default '0', + No tinyint(3) unsigned NOT NULL default '0', + Abstain tinyint(3) unsigned NOT NULL default '0', + ActiveTUs tinyint(3) unsigned NOT NULL default '0', + PRIMARY KEY (ID), + FOREIGN KEY (SubmitterID) REFERENCES Users(ID) ON DELETE CASCADE +) ENGINE = InnoDB; + +-- Individual vote records +-- +CREATE TABLE IF NOT EXISTS TU_Votes ( + VoteID int(10) unsigned NOT NULL, + UserID int(10) unsigned NOT NULL, + FOREIGN KEY (VoteID) REFERENCES TU_VoteInfo(ID) ON DELETE CASCADE, + FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE +) ENGINE = InnoDB; + +-- Malicious user banning +-- +CREATE TABLE Bans ( + IPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0, + BanTS TIMESTAMP NOT NULL, + PRIMARY KEY (IPAddress) +) ENGINE = InnoDB; diff --git a/schema/gendummydata.py b/schema/gendummydata.py new file mode 100755 index 0000000..361d1f9 --- /dev/null +++ b/schema/gendummydata.py @@ -0,0 +1,302 @@ +#!/usr/bin/python3 +""" +usage: gendummydata.py outputfilename.sql +""" +# +# This script seeds the AUR database with dummy data for +# use during development/testing. It uses random entries +# from /usr/share/dict/words to create user accounts and +# package names. It generates the SQL statements to +# insert these users/packages into the AUR database. +# +import random +import time +import os +import sys +import io +import logging + +LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output +SEED_FILE = "/usr/share/dict/words" +DB_HOST = os.getenv("DB_HOST", "localhost") +DB_NAME = os.getenv("DB_NAME", "AUR") +DB_USER = os.getenv("DB_USER", "aur") +DB_PASS = os.getenv("DB_PASS", "aur") +USER_ID = 5 # Users.ID of first bogus user +PKG_ID = 1 # Packages.ID of first package +MAX_USERS = 300 # how many users to 'register' +MAX_DEVS = .1 # what percentage of MAX_USERS are Developers +MAX_TUS = .2 # what percentage of MAX_USERS are Trusted Users +MAX_PKGS = 900 # how many packages to load +PKG_DEPS = (1, 5) # min/max depends a package has +PKG_SRC = (1, 3) # min/max sources a package has +PKG_CMNTS = (1, 5) # min/max number of comments a package has +CATEGORIES_COUNT = 17 # the number of categories from aur-schema +VOTING = (0, .30) # percentage range for package voting +OPEN_PROPOSALS = 5 # number of open trusted user proposals +CLOSE_PROPOSALS = 15 # number of closed trusted user proposals +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") +FORTUNE_FILE = "/usr/share/fortune/cookie" + +# setup logging +logformat = "%(levelname)s: %(message)s" +logging.basicConfig(format=logformat, level=LOG_LEVEL) +log = logging.getLogger() + +if len(sys.argv) != 2: + log.error("Missing output filename argument") + raise SystemExit + +# make sure the seed file exists +# +if not os.path.exists(SEED_FILE): + log.error("Please install the 'words' Arch package") + raise SystemExit + +# make sure comments can be created +# +if not os.path.exists(FORTUNE_FILE): + log.error("Please install the 'fortune-mod' Arch package") + raise SystemExit + +# track what users/package names have been used +# +seen_users = {} +seen_pkgs = {} +user_keys = [] + +# some functions to generate random data +# +def genVersion(): + ver = [] + ver.append("%d" % random.randrange(0,10)) + ver.append("%d" % random.randrange(0,20)) + if random.randrange(0,2) == 0: + ver.append("%d" % random.randrange(0,100)) + return ".".join(ver) + "-%d" % random.randrange(1,11) +def genCategory(): + return random.randrange(1,CATEGORIES_COUNT) +def genUID(): + return seen_users[user_keys[random.randrange(0,len(user_keys))]] +def genFortune(): + return fortunes[random.randrange(0,len(fortunes))].replace("'", "") + + +# load the words, and make sure there are enough words for users/pkgs +# +log.debug("Grabbing words from seed file...") +fp = open(SEED_FILE, "r", encoding="utf-8") +contents = fp.readlines() +fp.close() +if MAX_USERS > len(contents): + MAX_USERS = len(contents) +if MAX_PKGS > len(contents): + MAX_PKGS = len(contents) +if len(contents) - MAX_USERS > MAX_PKGS: + need_dupes = 0 +else: + need_dupes = 1 + +# select random usernames +# +log.debug("Generating random user names...") +user_id = USER_ID +while len(seen_users) < MAX_USERS: + user = random.randrange(0, len(contents)) + word = contents[user].replace("'", "").replace(".","").replace(" ", "_") + word = word.strip().lower() + if word not in seen_users: + seen_users[word] = user_id + user_id += 1 +user_keys = list(seen_users.keys()) + +# select random package names +# +log.debug("Generating random package names...") +num_pkgs = PKG_ID +while len(seen_pkgs) < MAX_PKGS: + pkg = random.randrange(0, len(contents)) + word = contents[pkg].replace("'", "").replace(".","").replace(" ", "_") + word = word.strip().lower() + if not need_dupes: + if word not in seen_pkgs and word not in seen_users: + seen_pkgs[word] = num_pkgs + num_pkgs += 1 + else: + if word not in seen_pkgs: + seen_pkgs[word] = num_pkgs + num_pkgs += 1 + +# free up contents memory +# +contents = None + +# developer/tu IDs +# +developers = [] +trustedusers = [] +has_devs = 0 +has_tus = 0 + +# Just let python throw the errors if any happen +# +out = open(sys.argv[1], "w", encoding="utf-8") +out.write("BEGIN;\n") + +# Begin by creating the User statements +# +log.debug("Creating SQL statements for users.") +for u in user_keys: + account_type = 1 # default to normal user + if not has_devs or not has_tus: + account_type = random.randrange(1, 4) + if account_type == 3 and not has_devs: + # this will be a dev account + # + developers.append(seen_users[u]) + if len(developers) >= MAX_DEVS * MAX_USERS: + has_devs = 1 + elif account_type == 2 and not has_tus: + # this will be a trusted user account + # + trustedusers.append(seen_users[u]) + if len(trustedusers) >= MAX_TUS * MAX_USERS: + has_tus = 1 + else: + # a normal user account + # + pass + + s = ("INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd)" + " VALUES (%d, %d, '%s', '%s@example.com', MD5('%s'));\n") + s = s % (seen_users[u], account_type, u, u, u) + out.write(s) + +log.debug("Number of developers: %d" % len(developers)) +log.debug("Number of trusted users: %d" % len(trustedusers)) +log.debug("Number of users: %d" % (MAX_USERS-len(developers)-len(trustedusers))) +log.debug("Number of packages: %d" % MAX_PKGS) + +log.debug("Gathering text from fortune file...") +fp = open(FORTUNE_FILE, "r", encoding="utf-8") +fortunes = fp.read().split("%\n") +fp.close() + +# Create the package statements +# +log.debug("Creating SQL statements for packages.") +count = 0 +for p in list(seen_pkgs.keys()): + NOW = int(time.time()) + if count % 2 == 0: + muid = developers[random.randrange(0,len(developers))] + else: + muid = trustedusers[random.randrange(0,len(trustedusers))] + if count % 20 == 0: # every so often, there are orphans... + muid = "NULL" + + uuid = genUID() # the submitter/user + + s = ("INSERT INTO Packages (ID, Name, Version, CategoryID," + " SubmittedTS, SubmitterUID, MaintainerUID) VALUES " + " (%d, '%s', '%s', %d, %d, %d, %s);\n") + s = s % (seen_pkgs[p], p, genVersion(), genCategory(), NOW, uuid, muid) + + out.write(s) + count += 1 + + # create random comments for this package + # + num_comments = random.randrange(PKG_CMNTS[0], PKG_CMNTS[1]) + for i in range(0, num_comments): + now = NOW + random.randrange(400, 86400*3) + s = ("INSERT INTO PackageComments (PackageID, UsersID," + " Comments, CommentTS) VALUES (%d, %d, '%s', %d);\n") + s = s % (seen_pkgs[p], genUID(), genFortune(), now) + out.write(s) + +# Cast votes +# +track_votes = {} +log.debug("Casting votes for packages.") +for u in user_keys: + num_votes = random.randrange(int(len(seen_pkgs)*VOTING[0]), + int(len(seen_pkgs)*VOTING[1])) + pkgvote = {} + for v in range(num_votes): + pkg = random.randrange(1, len(seen_pkgs) + 1) + if pkg not in pkgvote: + s = ("INSERT INTO PackageVotes (UsersID, PackageID)" + " VALUES (%d, %d);\n") + s = s % (seen_users[u], pkg) + pkgvote[pkg] = 1 + if pkg not in track_votes: + track_votes[pkg] = 0 + track_votes[pkg] += 1 + out.write(s) + +# Update statements for package votes +# +for p in list(track_votes.keys()): + s = "UPDATE Packages SET NumVotes = %d WHERE ID = %d;\n" + s = s % (track_votes[p], p) + out.write(s) + +# Create package dependencies and sources +# +log.debug("Creating statements for package depends/sources.") +for p in list(seen_pkgs.keys()): + num_deps = random.randrange(PKG_DEPS[0], PKG_DEPS[1]) + this_deps = {} + i = 0 + while i != num_deps: + dep = random.choice([k for k in seen_pkgs]) + if dep not in this_deps: + s = "INSERT INTO PackageDepends VALUES (%d, '%s', NULL);\n" + s = s % (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" + s = s % (seen_pkgs[p], src) + out.write(s) + +# Create trusted user proposals +# +log.debug("Creating SQL statements for trusted user proposals.") +count=0 +for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS): + now = int(time.time()) + if count < CLOSE_PROPOSALS: + start = now - random.randrange(3600*24*7, 3600*24*21) + end = now - random.randrange(0, 3600*24*7) + else: + start = now + end = now + random.randrange(3600*24, 3600*24*7) + if count % 5 == 0: # Don't make the vote about anyone once in a while + user = "" + else: + user = user_keys[random.randrange(0,len(user_keys))] + suid = trustedusers[random.randrange(0,len(trustedusers))] + s = ("INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End," + " SubmitterID) VALUES ('%s', '%s', %d, %d, %d);\n") + s = s % (genFortune(), user, start, end, suid) + out.write(s) + count += 1 + +# close output file +# +out.write("COMMIT;\n") +out.write("\n") +out.close() +log.debug("Done.") diff --git a/schema/reloadtestdb.sh b/schema/reloadtestdb.sh new file mode 100755 index 0000000..ecaaaa8 --- /dev/null +++ b/schema/reloadtestdb.sh @@ -0,0 +1,29 @@ +#!/bin/bash -e + +DB_NAME=${DB_NAME:-AUR} +DB_USER=${DB_USER:-aur} +# Password should allow empty definition +DB_PASS=${DB_PASS-aur} +DB_HOST=${DB_HOST:-localhost} +DATA_FILE=${DATA_FILE:-dummy-data.sql} + +echo "Using database $DB_NAME, user $DB_USER, host $DB_HOST" + +mydir=$(pwd) +if [ $(basename $mydir) != "schema" ]; then + echo "you must be in the aur/schema directory to run this script" + exit 1 +fi + +echo "recreating database..." +mysql -h $DB_HOST -u $DB_USER -p$DB_PASS < aur-schema.sql + +if [ ! -f $DATA_FILE ]; then + echo "creating dumy-data..." + python3 gendummydata.py $DATA_FILE +fi + +echo "loading dummy-data..." +mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME < $DATA_FILE + +echo "done." diff --git a/support/schema/aur-schema.sql b/support/schema/aur-schema.sql deleted file mode 100644 index c01701c..0000000 --- a/support/schema/aur-schema.sql +++ /dev/null @@ -1,228 +0,0 @@ --- The MySQL database layout for the AUR. Certain data --- is also included such as AccountTypes, etc. --- -DROP DATABASE IF EXISTS AUR; -CREATE DATABASE AUR DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; -USE AUR; - --- Define the Account Types for the AUR. --- -CREATE TABLE AccountTypes ( - ID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, - AccountType VARCHAR(32) NOT NULL DEFAULT '', - PRIMARY KEY (ID) -) ENGINE = InnoDB; -INSERT INTO AccountTypes (ID, AccountType) VALUES (1, 'User'); -INSERT INTO AccountTypes (ID, AccountType) VALUES (2, 'Trusted User'); -INSERT INTO AccountTypes (ID, AccountType) VALUES (3, 'Developer'); - - --- User information for each user regardless of type. --- -CREATE TABLE Users ( - ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, - AccountTypeID TINYINT UNSIGNED NOT NULL DEFAULT 1, - Suspended TINYINT UNSIGNED NOT NULL DEFAULT 0, - Username VARCHAR(32) NOT NULL, - Email VARCHAR(64) NOT NULL, - Passwd CHAR(32) NOT NULL, - Salt CHAR(32) NOT NULL DEFAULT '', - ResetKey CHAR(32) NOT NULL DEFAULT '', - RealName VARCHAR(64) NOT NULL DEFAULT '', - LangPreference VARCHAR(5) NOT NULL DEFAULT 'en', - IRCNick VARCHAR(32) NOT NULL DEFAULT '', - PGPKey VARCHAR(40) NULL DEFAULT NULL, - LastVoted BIGINT UNSIGNED NOT NULL DEFAULT 0, - LastLogin BIGINT UNSIGNED NOT NULL DEFAULT 0, - LastLoginIPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0, - InactivityTS BIGINT UNSIGNED NOT NULL DEFAULT 0, - RegistrationTS TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (ID), - UNIQUE (Username), - UNIQUE (Email), - INDEX (AccountTypeID), - FOREIGN KEY (AccountTypeID) REFERENCES AccountTypes(ID) ON DELETE NO ACTION -) ENGINE = InnoDB; --- A default developer account for testing purposes -INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd) VALUES ( - 1, 3, 'dev', 'dev@localhost', MD5('dev')); -INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd) VALUES ( - 2, 2, 'tu', 'tu@localhost', MD5('tu')); -INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd) VALUES ( - 3, 1, 'user', 'user@localhost', MD5('user')); - - --- Track Users logging in/out of AUR web site. --- -CREATE TABLE Sessions ( - UsersID INTEGER UNSIGNED NOT NULL, - SessionID CHAR(32) NOT NULL, - LastUpdateTS BIGINT UNSIGNED NOT NULL, - FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE, - UNIQUE (SessionID) -) ENGINE = InnoDB; - - --- Categories for grouping packages when they reside in --- Unsupported or the AUR - based on the categories defined --- in 'extra'. --- -CREATE TABLE PackageCategories ( - ID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, - Category VARCHAR(32) NOT NULL, - PRIMARY KEY (ID) -) ENGINE = InnoDB; -INSERT INTO PackageCategories (Category) VALUES ('none'); -INSERT INTO PackageCategories (Category) VALUES ('daemons'); -INSERT INTO PackageCategories (Category) VALUES ('devel'); -INSERT INTO PackageCategories (Category) VALUES ('editors'); -INSERT INTO PackageCategories (Category) VALUES ('emulators'); -INSERT INTO PackageCategories (Category) VALUES ('games'); -INSERT INTO PackageCategories (Category) VALUES ('gnome'); -INSERT INTO PackageCategories (Category) VALUES ('i18n'); -INSERT INTO PackageCategories (Category) VALUES ('kde'); -INSERT INTO PackageCategories (Category) VALUES ('lib'); -INSERT INTO PackageCategories (Category) VALUES ('modules'); -INSERT INTO PackageCategories (Category) VALUES ('multimedia'); -INSERT INTO PackageCategories (Category) VALUES ('network'); -INSERT INTO PackageCategories (Category) VALUES ('office'); -INSERT INTO PackageCategories (Category) VALUES ('science'); -INSERT INTO PackageCategories (Category) VALUES ('system'); -INSERT INTO PackageCategories (Category) VALUES ('x11'); -INSERT INTO PackageCategories (Category) VALUES ('xfce'); -INSERT INTO PackageCategories (Category) VALUES ('fonts'); - - --- Information about the actual packages --- -CREATE TABLE Packages ( - ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, - Name VARCHAR(64) NOT NULL, - Version VARCHAR(32) NOT NULL DEFAULT '', - CategoryID TINYINT UNSIGNED NOT NULL DEFAULT 1, - Description VARCHAR(255) NOT NULL DEFAULT "An Arch Package", - URL VARCHAR(255) NOT NULL DEFAULT "https://www.archlinux.org", - License VARCHAR(40) NOT NULL DEFAULT '', - NumVotes INTEGER UNSIGNED NOT NULL DEFAULT 0, - OutOfDateTS BIGINT UNSIGNED NULL DEFAULT NULL, - SubmittedTS BIGINT UNSIGNED NOT NULL, - ModifiedTS BIGINT UNSIGNED NOT NULL, - SubmitterUID INTEGER UNSIGNED NULL DEFAULT NULL, -- who submitted it? - MaintainerUID INTEGER UNSIGNED NULL DEFAULT NULL, -- User - PRIMARY KEY (ID), - UNIQUE (Name), - INDEX (CategoryID), - INDEX (NumVotes), - INDEX (SubmitterUID), - INDEX (MaintainerUID), - FOREIGN KEY (CategoryID) REFERENCES PackageCategories(ID) ON DELETE NO ACTION, - -- deleting a user will cause packages to be orphaned, not deleted - FOREIGN KEY (SubmitterUID) REFERENCES Users(ID) ON DELETE SET NULL, - FOREIGN KEY (MaintainerUID) REFERENCES Users(ID) ON DELETE SET NULL -) ENGINE = InnoDB; - - --- Track which dependencies a package has --- -CREATE TABLE PackageDepends ( - PackageID INTEGER UNSIGNED NOT NULL, - DepName VARCHAR(64) NOT NULL, - DepCondition VARCHAR(20), - INDEX (PackageID), - INDEX (DepName), - FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE -) ENGINE = InnoDB; - - --- Track which sources a package has --- -CREATE TABLE PackageSources ( - PackageID INTEGER UNSIGNED NOT NULL, - Source VARCHAR(255) NOT NULL DEFAULT "/dev/null", - INDEX (PackageID), - FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE -) ENGINE = InnoDB; - - --- Track votes for packages --- -CREATE TABLE PackageVotes ( - UsersID INTEGER UNSIGNED NOT NULL, - PackageID INTEGER UNSIGNED NOT NULL, - INDEX (UsersID), - INDEX (PackageID), - FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE, - FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE -) ENGINE = InnoDB; -CREATE UNIQUE INDEX VoteUsersIDPackageID ON PackageVotes (UsersID, PackageID); - --- Record comments for packages --- -CREATE TABLE PackageComments ( - ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - PackageID INTEGER UNSIGNED NOT NULL, - UsersID INTEGER UNSIGNED NULL DEFAULT NULL, - Comments TEXT NOT NULL DEFAULT '', - CommentTS BIGINT UNSIGNED NOT NULL DEFAULT 0, - DelUsersID INTEGER UNSIGNED NULL DEFAULT NULL, - PRIMARY KEY (ID), - INDEX (UsersID), - INDEX (PackageID), - FOREIGN KEY (UsersID) REFERENCES Users(ID) ON SET NULL, - FOREIGN KEY (DelUsersID) REFERENCES Users(ID) ON DELETE CASCADE, - FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE -) ENGINE = InnoDB; - --- Comment addition notifications --- -CREATE TABLE CommentNotify ( - PkgID INTEGER UNSIGNED NOT NULL, - UserID INTEGER UNSIGNED NOT NULL, - FOREIGN KEY (PkgID) REFERENCES Packages(ID) ON DELETE CASCADE, - FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE -) ENGINE = InnoDB; -CREATE UNIQUE INDEX NotifyUserIDPkgID ON CommentNotify (UserID, PkgID); - --- Package name blacklist --- -CREATE TABLE PackageBlacklist ( - ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, - Name VARCHAR(64) NOT NULL, - PRIMARY KEY (ID), - UNIQUE (Name) -) ENGINE = InnoDB; - --- Vote information --- -CREATE TABLE IF NOT EXISTS TU_VoteInfo ( - ID int(10) unsigned NOT NULL auto_increment, - Agenda text NOT NULL, - User VARCHAR(32) NOT NULL, - Submitted bigint(20) unsigned NOT NULL, - End bigint(20) unsigned NOT NULL, - Quorum decimal(2, 2) unsigned NOT NULL, - SubmitterID int(10) unsigned NOT NULL, - Yes tinyint(3) unsigned NOT NULL default '0', - No tinyint(3) unsigned NOT NULL default '0', - Abstain tinyint(3) unsigned NOT NULL default '0', - ActiveTUs tinyint(3) unsigned NOT NULL default '0', - PRIMARY KEY (ID), - FOREIGN KEY (SubmitterID) REFERENCES Users(ID) ON DELETE CASCADE -) ENGINE = InnoDB; - --- Individual vote records --- -CREATE TABLE IF NOT EXISTS TU_Votes ( - VoteID int(10) unsigned NOT NULL, - UserID int(10) unsigned NOT NULL, - FOREIGN KEY (VoteID) REFERENCES TU_VoteInfo(ID) ON DELETE CASCADE, - FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE -) ENGINE = InnoDB; - --- Malicious user banning --- -CREATE TABLE Bans ( - IPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0, - BanTS TIMESTAMP NOT NULL, - PRIMARY KEY (IPAddress) -) ENGINE = InnoDB; diff --git a/support/schema/gendummydata.py b/support/schema/gendummydata.py deleted file mode 100755 index 361d1f9..0000000 --- a/support/schema/gendummydata.py +++ /dev/null @@ -1,302 +0,0 @@ -#!/usr/bin/python3 -""" -usage: gendummydata.py outputfilename.sql -""" -# -# This script seeds the AUR database with dummy data for -# use during development/testing. It uses random entries -# from /usr/share/dict/words to create user accounts and -# package names. It generates the SQL statements to -# insert these users/packages into the AUR database. -# -import random -import time -import os -import sys -import io -import logging - -LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output -SEED_FILE = "/usr/share/dict/words" -DB_HOST = os.getenv("DB_HOST", "localhost") -DB_NAME = os.getenv("DB_NAME", "AUR") -DB_USER = os.getenv("DB_USER", "aur") -DB_PASS = os.getenv("DB_PASS", "aur") -USER_ID = 5 # Users.ID of first bogus user -PKG_ID = 1 # Packages.ID of first package -MAX_USERS = 300 # how many users to 'register' -MAX_DEVS = .1 # what percentage of MAX_USERS are Developers -MAX_TUS = .2 # what percentage of MAX_USERS are Trusted Users -MAX_PKGS = 900 # how many packages to load -PKG_DEPS = (1, 5) # min/max depends a package has -PKG_SRC = (1, 3) # min/max sources a package has -PKG_CMNTS = (1, 5) # min/max number of comments a package has -CATEGORIES_COUNT = 17 # the number of categories from aur-schema -VOTING = (0, .30) # percentage range for package voting -OPEN_PROPOSALS = 5 # number of open trusted user proposals -CLOSE_PROPOSALS = 15 # number of closed trusted user proposals -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") -FORTUNE_FILE = "/usr/share/fortune/cookie" - -# setup logging -logformat = "%(levelname)s: %(message)s" -logging.basicConfig(format=logformat, level=LOG_LEVEL) -log = logging.getLogger() - -if len(sys.argv) != 2: - log.error("Missing output filename argument") - raise SystemExit - -# make sure the seed file exists -# -if not os.path.exists(SEED_FILE): - log.error("Please install the 'words' Arch package") - raise SystemExit - -# make sure comments can be created -# -if not os.path.exists(FORTUNE_FILE): - log.error("Please install the 'fortune-mod' Arch package") - raise SystemExit - -# track what users/package names have been used -# -seen_users = {} -seen_pkgs = {} -user_keys = [] - -# some functions to generate random data -# -def genVersion(): - ver = [] - ver.append("%d" % random.randrange(0,10)) - ver.append("%d" % random.randrange(0,20)) - if random.randrange(0,2) == 0: - ver.append("%d" % random.randrange(0,100)) - return ".".join(ver) + "-%d" % random.randrange(1,11) -def genCategory(): - return random.randrange(1,CATEGORIES_COUNT) -def genUID(): - return seen_users[user_keys[random.randrange(0,len(user_keys))]] -def genFortune(): - return fortunes[random.randrange(0,len(fortunes))].replace("'", "") - - -# load the words, and make sure there are enough words for users/pkgs -# -log.debug("Grabbing words from seed file...") -fp = open(SEED_FILE, "r", encoding="utf-8") -contents = fp.readlines() -fp.close() -if MAX_USERS > len(contents): - MAX_USERS = len(contents) -if MAX_PKGS > len(contents): - MAX_PKGS = len(contents) -if len(contents) - MAX_USERS > MAX_PKGS: - need_dupes = 0 -else: - need_dupes = 1 - -# select random usernames -# -log.debug("Generating random user names...") -user_id = USER_ID -while len(seen_users) < MAX_USERS: - user = random.randrange(0, len(contents)) - word = contents[user].replace("'", "").replace(".","").replace(" ", "_") - word = word.strip().lower() - if word not in seen_users: - seen_users[word] = user_id - user_id += 1 -user_keys = list(seen_users.keys()) - -# select random package names -# -log.debug("Generating random package names...") -num_pkgs = PKG_ID -while len(seen_pkgs) < MAX_PKGS: - pkg = random.randrange(0, len(contents)) - word = contents[pkg].replace("'", "").replace(".","").replace(" ", "_") - word = word.strip().lower() - if not need_dupes: - if word not in seen_pkgs and word not in seen_users: - seen_pkgs[word] = num_pkgs - num_pkgs += 1 - else: - if word not in seen_pkgs: - seen_pkgs[word] = num_pkgs - num_pkgs += 1 - -# free up contents memory -# -contents = None - -# developer/tu IDs -# -developers = [] -trustedusers = [] -has_devs = 0 -has_tus = 0 - -# Just let python throw the errors if any happen -# -out = open(sys.argv[1], "w", encoding="utf-8") -out.write("BEGIN;\n") - -# Begin by creating the User statements -# -log.debug("Creating SQL statements for users.") -for u in user_keys: - account_type = 1 # default to normal user - if not has_devs or not has_tus: - account_type = random.randrange(1, 4) - if account_type == 3 and not has_devs: - # this will be a dev account - # - developers.append(seen_users[u]) - if len(developers) >= MAX_DEVS * MAX_USERS: - has_devs = 1 - elif account_type == 2 and not has_tus: - # this will be a trusted user account - # - trustedusers.append(seen_users[u]) - if len(trustedusers) >= MAX_TUS * MAX_USERS: - has_tus = 1 - else: - # a normal user account - # - pass - - s = ("INSERT INTO Users (ID, AccountTypeID, Username, Email, Passwd)" - " VALUES (%d, %d, '%s', '%s@example.com', MD5('%s'));\n") - s = s % (seen_users[u], account_type, u, u, u) - out.write(s) - -log.debug("Number of developers: %d" % len(developers)) -log.debug("Number of trusted users: %d" % len(trustedusers)) -log.debug("Number of users: %d" % (MAX_USERS-len(developers)-len(trustedusers))) -log.debug("Number of packages: %d" % MAX_PKGS) - -log.debug("Gathering text from fortune file...") -fp = open(FORTUNE_FILE, "r", encoding="utf-8") -fortunes = fp.read().split("%\n") -fp.close() - -# Create the package statements -# -log.debug("Creating SQL statements for packages.") -count = 0 -for p in list(seen_pkgs.keys()): - NOW = int(time.time()) - if count % 2 == 0: - muid = developers[random.randrange(0,len(developers))] - else: - muid = trustedusers[random.randrange(0,len(trustedusers))] - if count % 20 == 0: # every so often, there are orphans... - muid = "NULL" - - uuid = genUID() # the submitter/user - - s = ("INSERT INTO Packages (ID, Name, Version, CategoryID," - " SubmittedTS, SubmitterUID, MaintainerUID) VALUES " - " (%d, '%s', '%s', %d, %d, %d, %s);\n") - s = s % (seen_pkgs[p], p, genVersion(), genCategory(), NOW, uuid, muid) - - out.write(s) - count += 1 - - # create random comments for this package - # - num_comments = random.randrange(PKG_CMNTS[0], PKG_CMNTS[1]) - for i in range(0, num_comments): - now = NOW + random.randrange(400, 86400*3) - s = ("INSERT INTO PackageComments (PackageID, UsersID," - " Comments, CommentTS) VALUES (%d, %d, '%s', %d);\n") - s = s % (seen_pkgs[p], genUID(), genFortune(), now) - out.write(s) - -# Cast votes -# -track_votes = {} -log.debug("Casting votes for packages.") -for u in user_keys: - num_votes = random.randrange(int(len(seen_pkgs)*VOTING[0]), - int(len(seen_pkgs)*VOTING[1])) - pkgvote = {} - for v in range(num_votes): - pkg = random.randrange(1, len(seen_pkgs) + 1) - if pkg not in pkgvote: - s = ("INSERT INTO PackageVotes (UsersID, PackageID)" - " VALUES (%d, %d);\n") - s = s % (seen_users[u], pkg) - pkgvote[pkg] = 1 - if pkg not in track_votes: - track_votes[pkg] = 0 - track_votes[pkg] += 1 - out.write(s) - -# Update statements for package votes -# -for p in list(track_votes.keys()): - s = "UPDATE Packages SET NumVotes = %d WHERE ID = %d;\n" - s = s % (track_votes[p], p) - out.write(s) - -# Create package dependencies and sources -# -log.debug("Creating statements for package depends/sources.") -for p in list(seen_pkgs.keys()): - num_deps = random.randrange(PKG_DEPS[0], PKG_DEPS[1]) - this_deps = {} - i = 0 - while i != num_deps: - dep = random.choice([k for k in seen_pkgs]) - if dep not in this_deps: - s = "INSERT INTO PackageDepends VALUES (%d, '%s', NULL);\n" - s = s % (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" - s = s % (seen_pkgs[p], src) - out.write(s) - -# Create trusted user proposals -# -log.debug("Creating SQL statements for trusted user proposals.") -count=0 -for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS): - now = int(time.time()) - if count < CLOSE_PROPOSALS: - start = now - random.randrange(3600*24*7, 3600*24*21) - end = now - random.randrange(0, 3600*24*7) - else: - start = now - end = now + random.randrange(3600*24, 3600*24*7) - if count % 5 == 0: # Don't make the vote about anyone once in a while - user = "" - else: - user = user_keys[random.randrange(0,len(user_keys))] - suid = trustedusers[random.randrange(0,len(trustedusers))] - s = ("INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End," - " SubmitterID) VALUES ('%s', '%s', %d, %d, %d);\n") - s = s % (genFortune(), user, start, end, suid) - out.write(s) - count += 1 - -# close output file -# -out.write("COMMIT;\n") -out.write("\n") -out.close() -log.debug("Done.") diff --git a/support/schema/reloadtestdb.sh b/support/schema/reloadtestdb.sh deleted file mode 100755 index f6a8ae2..0000000 --- a/support/schema/reloadtestdb.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -e - -DB_NAME=${DB_NAME:-AUR} -DB_USER=${DB_USER:-aur} -# Password should allow empty definition -DB_PASS=${DB_PASS-aur} -DB_HOST=${DB_HOST:-localhost} -DATA_FILE=${DATA_FILE:-dummy-data.sql} - -echo "Using database $DB_NAME, user $DB_USER, host $DB_HOST" - -mydir=$(pwd) -if [ $(basename $mydir) != "schema" ]; then - echo "you must be in the aur/support/schema directory to run this script" - exit 1 -fi - -echo "recreating database..." -mysql -h $DB_HOST -u $DB_USER -p$DB_PASS < aur-schema.sql - -if [ ! -f $DATA_FILE ]; then - echo "creating dumy-data..." - python3 gendummydata.py $DATA_FILE -fi - -echo "loading dummy-data..." -mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME < $DATA_FILE - -echo "done." -- 1.8.5.3
On Thu, Feb 6, 2014 at 1:42 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
There aren't any other subdirectories in support/. Reduce the nesting depth by moving schema/ to the top-level source directory.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- INSTALL | 4 +- schema/aur-schema.sql | 228 +++++++++++++++++++++++++++++++ schema/gendummydata.py | 302 +++++++++++++++++++++++++++++++++++++++++ schema/reloadtestdb.sh | 29 ++++ support/schema/aur-schema.sql | 228 ------------------------------- support/schema/gendummydata.py | 302 ----------------------------------------- support/schema/reloadtestdb.sh | 29 ---- 7 files changed, 561 insertions(+), 561 deletions(-) create mode 100644 schema/aur-schema.sql create mode 100755 schema/gendummydata.py create mode 100755 schema/reloadtestdb.sh delete mode 100644 support/schema/aur-schema.sql delete mode 100755 support/schema/gendummydata.py delete mode 100755 support/schema/reloadtestdb.sh
For patches where files are moved like this can you use `git format-patch -M`? It makes it easier to figure out what has actually changed in the files being renamed. This is especially true for this patch as you can't even reply due to the mailman size limitation. <snip>
On Fri, 07 Feb 2014 at 00:33:48, canyonknight wrote:
On Thu, Feb 6, 2014 at 1:42 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
There aren't any other subdirectories in support/. Reduce the nesting depth by moving schema/ to the top-level source directory.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- INSTALL | 4 +- schema/aur-schema.sql | 228 +++++++++++++++++++++++++++++++ schema/gendummydata.py | 302 +++++++++++++++++++++++++++++++++++++++++ schema/reloadtestdb.sh | 29 ++++ support/schema/aur-schema.sql | 228 ------------------------------- support/schema/gendummydata.py | 302 ----------------------------------------- support/schema/reloadtestdb.sh | 29 ---- 7 files changed, 561 insertions(+), 561 deletions(-) create mode 100644 schema/aur-schema.sql create mode 100755 schema/gendummydata.py create mode 100755 schema/reloadtestdb.sh delete mode 100644 support/schema/aur-schema.sql delete mode 100755 support/schema/gendummydata.py delete mode 100755 support/schema/reloadtestdb.sh
For patches where files are moved like this can you use `git format-patch -M`? It makes it easier to figure out what has actually changed in the files being renamed.
This is especially true for this patch as you can't even reply due to the mailman size limitation.
<snip>
Of course. I wanted to do this but somehow forgot about it when calling git-send-email(1). Will do next time.
participants (2)
-
canyonknight
-
Lukas Fleischer