summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsupport/schema/gendummydata.py22
-rw-r--r--web/html/index.php10
-rw-r--r--web/html/packages.php4
-rw-r--r--web/lib/pkgfuncs.inc.php74
4 files changed, 62 insertions, 48 deletions
diff --git a/support/schema/gendummydata.py b/support/schema/gendummydata.py
index 68f58b69..361d1f90 100755
--- a/support/schema/gendummydata.py
+++ b/support/schema/gendummydata.py
@@ -14,7 +14,6 @@ import time
import os
import sys
import io
-import subprocess
import logging
LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output
@@ -39,7 +38,7 @@ 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_CMD = "/usr/bin/fortune"
+FORTUNE_FILE = "/usr/share/fortune/cookie"
# setup logging
logformat = "%(levelname)s: %(message)s"
@@ -58,7 +57,7 @@ if not os.path.exists(SEED_FILE):
# make sure comments can be created
#
-if not os.path.exists(FORTUNE_CMD):
+if not os.path.exists(FORTUNE_FILE):
log.error("Please install the 'fortune-mod' Arch package")
raise SystemExit
@@ -81,12 +80,14 @@ 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")
+fp = open(SEED_FILE, "r", encoding="utf-8")
contents = fp.readlines()
fp.close()
if MAX_USERS > len(contents):
@@ -141,7 +142,7 @@ has_tus = 0
# Just let python throw the errors if any happen
#
-out = open(sys.argv[1], "w")
+out = open(sys.argv[1], "w", encoding="utf-8")
out.write("BEGIN;\n")
# Begin by creating the User statements
@@ -178,6 +179,11 @@ 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.")
@@ -205,11 +211,10 @@ for p in list(seen_pkgs.keys()):
#
num_comments = random.randrange(PKG_CMNTS[0], PKG_CMNTS[1])
for i in range(0, num_comments):
- fortune = subprocess.getoutput(FORTUNE_CMD).replace("'","")
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(), fortune, now)
+ s = s % (seen_pkgs[p], genUID(), genFortune(), now)
out.write(s)
# Cast votes
@@ -271,7 +276,6 @@ for p in list(seen_pkgs.keys()):
log.debug("Creating SQL statements for trusted user proposals.")
count=0
for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS):
- fortune = subprocess.getoutput(FORTUNE_CMD).replace("'","")
now = int(time.time())
if count < CLOSE_PROPOSALS:
start = now - random.randrange(3600*24*7, 3600*24*21)
@@ -286,7 +290,7 @@ for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS):
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 % (fortune, user, start, end, suid)
+ s = s % (genFortune(), user, start, end, suid)
out.write(s)
count += 1
diff --git a/web/html/index.php b/web/html/index.php
index 3b46ab9e..a197d0bc 100644
--- a/web/html/index.php
+++ b/web/html/index.php
@@ -22,12 +22,6 @@ if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) {
}
if (!empty($tokens[3])) {
- if ($tokens[3] == 'voters') {
- $_GET['ID'] = pkgid_from_name($tokens[2]);
- include('voters.php');
- return;
- }
-
/* TODO: Remove support for legacy URIs and move these
* actions to separate modules. */
switch ($tokens[3]) {
@@ -55,6 +49,10 @@ if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) {
case "merge":
include('pkgmerge.php');
return;
+ case "voters":
+ $_GET['ID'] = pkgid_from_name($tokens[2]);
+ include('voters.php');
+ return;
default:
header("HTTP/1.0 404 Not Found");
include "./404.php";
diff --git a/web/html/packages.php b/web/html/packages.php
index 094c221d..61825501 100644
--- a/web/html/packages.php
+++ b/web/html/packages.php
@@ -51,9 +51,9 @@ if (isset($_POST['IDs'])) {
$output = "";
if (check_token()) {
if (current_action("do_Flag")) {
- $output = pkg_flag($atype, $ids, true);
+ $output = pkg_flag($atype, $ids);
} elseif (current_action("do_UnFlag")) {
- $output = pkg_flag($atype, $ids, False);
+ $output = pkg_unflag($atype, $ids);
} elseif (current_action("do_Adopt")) {
$output = pkg_adopt($atype, $ids, true);
} elseif (current_action("do_Disown")) {
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index cfdd9a79..c00c33db 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -772,33 +772,24 @@ function sanitize_ids($ids) {
}
/**
- * Flag and un-flag packages out-of-date
+ * Flag package(s) as out-of-date
*
* @global string $AUR_LOCATION The AUR's URL used for notification e-mails
* @param string $atype Account type, output of account_from_sid
* @param array $ids Array of package IDs to flag/unflag
- * @param bool $action true flags out-of-date, false un-flags. Flags by default
*
* @return string Translated success or error messages
*/
-function pkg_flag ($atype, $ids, $action=true, $dbh=NULL) {
+function pkg_flag($atype, $ids, $dbh=NULL) {
global $AUR_LOCATION;
if (!$atype) {
- if ($action) {
- return __("You must be logged in before you can flag packages.");
- } else {
- return __("You must be logged in before you can unflag packages.");
- }
+ return __("You must be logged in before you can flag packages.");
}
$ids = sanitize_ids($ids);
if (empty($ids)) {
- if ($action) {
- return __("You did not select any packages to flag.");
- } else {
- return __("You did not select any packages to unflag.");
- }
+ return __("You did not select any packages to flag.");
}
if(!$dbh) {
@@ -806,25 +797,13 @@ function pkg_flag ($atype, $ids, $action=true, $dbh=NULL) {
}
$q = "UPDATE Packages SET";
- if ($action) {
- $q.= " OutOfDateTS = UNIX_TIMESTAMP()";
- }
- else {
- $q.= " OutOfDateTS = NULL";
- }
+ $q.= " OutOfDateTS = UNIX_TIMESTAMP()";
$q.= " WHERE ID IN (" . implode(",", $ids) . ")";
-
- if (!$action && ($atype != "Trusted User" && $atype != "Developer")) {
- $q.= "AND MaintainerUID = " . uid_from_sid($_COOKIE["AURSID"], $dbh);
- }
-
- if ($action) {
- $q.= " AND OutOfDateTS IS NULL";
- }
+ $q.= " AND OutOfDateTS IS NULL";
$affected_pkgs = $dbh->exec($q);
- if ($action && $affected_pkgs > 0) {
+ if ($affected_pkgs > 0) {
# Notify of flagging by email
$f_name = username_from_sid($_COOKIE['AURSID'], $dbh);
$f_email = email_from_sid($_COOKIE['AURSID'], $dbh);
@@ -846,9 +825,42 @@ function pkg_flag ($atype, $ids, $action=true, $dbh=NULL) {
}
}
- if ($action) {
- return __("The selected packages have been flagged out-of-date.");
- } else {
+ return __("The selected packages have been flagged out-of-date.");
+}
+
+/**
+ * Unflag package(s) as out-of-date
+ *
+ * @param string $atype Account type, output of account_from_sid
+ * @param array $ids Array of package IDs to flag/unflag
+ *
+ * @return string Translated success or error messages
+ */
+function pkg_unflag($atype, $ids, $dbh=NULL) {
+ if (!$atype) {
+ return __("You must be logged in before you can unflag packages.");
+ }
+
+ $ids = sanitize_ids($ids);
+ if (empty($ids)) {
+ return __("You did not select any packages to unflag.");
+ }
+
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "UPDATE Packages SET ";
+ $q.= "OutOfDateTS = NULL ";
+ $q.= "WHERE ID IN (" . implode(",", $ids) . ") ";
+
+ if ($atype != "Trusted User" && $atype != "Developer") {
+ $q.= "AND MaintainerUID = " . uid_from_sid($_COOKIE["AURSID"], $dbh);
+ }
+
+ $result = $dbh->exec($q);
+
+ if ($result) {
return __("The selected packages have been unflagged.");
}
}