mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Make "gendummydata.py" Python 3 compliant.
* Transform into valid Python 3.x code using 2to3. * Change shebang from "/usr/bin/python2" to "/usr/bin/python3". * Invoke with "python3" instead of "python2" in "reloadtestdb.sh". Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
parent
e1bf49e03c
commit
31cda618ca
2 changed files with 15 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python2
|
#!/usr/bin/python3
|
||||||
"""
|
"""
|
||||||
usage: gendummydata.py outputfilename.sql
|
usage: gendummydata.py outputfilename.sql
|
||||||
"""
|
"""
|
||||||
|
@ -13,8 +13,8 @@ import random
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import cStringIO
|
import io
|
||||||
import commands
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output
|
LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output
|
||||||
|
@ -105,10 +105,10 @@ while len(seen_users) < MAX_USERS:
|
||||||
user = random.randrange(0, len(contents))
|
user = random.randrange(0, len(contents))
|
||||||
word = contents[user].replace("'", "").replace(".","").replace(" ", "_")
|
word = contents[user].replace("'", "").replace(".","").replace(" ", "_")
|
||||||
word = word.strip().lower()
|
word = word.strip().lower()
|
||||||
if not seen_users.has_key(word):
|
if word not in seen_users:
|
||||||
seen_users[word] = user_id
|
seen_users[word] = user_id
|
||||||
user_id += 1
|
user_id += 1
|
||||||
user_keys = seen_users.keys()
|
user_keys = list(seen_users.keys())
|
||||||
|
|
||||||
# select random package names
|
# select random package names
|
||||||
#
|
#
|
||||||
|
@ -119,11 +119,11 @@ while len(seen_pkgs) < MAX_PKGS:
|
||||||
word = contents[pkg].replace("'", "").replace(".","").replace(" ", "_")
|
word = contents[pkg].replace("'", "").replace(".","").replace(" ", "_")
|
||||||
word = word.strip().lower()
|
word = word.strip().lower()
|
||||||
if not need_dupes:
|
if not need_dupes:
|
||||||
if not seen_pkgs.has_key(word) and not seen_users.has_key(word):
|
if word not in seen_pkgs and word not in seen_users:
|
||||||
seen_pkgs[word] = num_pkgs
|
seen_pkgs[word] = num_pkgs
|
||||||
num_pkgs += 1
|
num_pkgs += 1
|
||||||
else:
|
else:
|
||||||
if not seen_pkgs.has_key(word):
|
if word not in seen_pkgs:
|
||||||
seen_pkgs[word] = num_pkgs
|
seen_pkgs[word] = num_pkgs
|
||||||
num_pkgs += 1
|
num_pkgs += 1
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ log.debug("Number of packages: %d" % MAX_PKGS)
|
||||||
#
|
#
|
||||||
log.debug("Creating SQL statements for packages.")
|
log.debug("Creating SQL statements for packages.")
|
||||||
count = 0
|
count = 0
|
||||||
for p in seen_pkgs.keys():
|
for p in list(seen_pkgs.keys()):
|
||||||
NOW = int(time.time())
|
NOW = int(time.time())
|
||||||
if count % 2 == 0:
|
if count % 2 == 0:
|
||||||
muid = developers[random.randrange(0,len(developers))]
|
muid = developers[random.randrange(0,len(developers))]
|
||||||
|
@ -210,7 +210,7 @@ for p in seen_pkgs.keys():
|
||||||
#
|
#
|
||||||
num_comments = random.randrange(PKG_CMNTS[0], PKG_CMNTS[1])
|
num_comments = random.randrange(PKG_CMNTS[0], PKG_CMNTS[1])
|
||||||
for i in range(0, num_comments):
|
for i in range(0, num_comments):
|
||||||
fortune = commands.getoutput(FORTUNE_CMD).replace("'","")
|
fortune = subprocess.getoutput(FORTUNE_CMD).replace("'","")
|
||||||
now = NOW + random.randrange(400, 86400*3)
|
now = NOW + random.randrange(400, 86400*3)
|
||||||
s = ("INSERT INTO PackageComments (PackageID, UsersID,"
|
s = ("INSERT INTO PackageComments (PackageID, UsersID,"
|
||||||
" Comments, CommentTS) VALUES (%d, %d, '%s', %d);\n")
|
" Comments, CommentTS) VALUES (%d, %d, '%s', %d);\n")
|
||||||
|
@ -227,19 +227,19 @@ for u in user_keys:
|
||||||
pkgvote = {}
|
pkgvote = {}
|
||||||
for v in range(num_votes):
|
for v in range(num_votes):
|
||||||
pkg = random.randrange(1, len(seen_pkgs) + 1)
|
pkg = random.randrange(1, len(seen_pkgs) + 1)
|
||||||
if not pkgvote.has_key(pkg):
|
if pkg not in pkgvote:
|
||||||
s = ("INSERT INTO PackageVotes (UsersID, PackageID)"
|
s = ("INSERT INTO PackageVotes (UsersID, PackageID)"
|
||||||
" VALUES (%d, %d);\n")
|
" VALUES (%d, %d);\n")
|
||||||
s = s % (seen_users[u], pkg)
|
s = s % (seen_users[u], pkg)
|
||||||
pkgvote[pkg] = 1
|
pkgvote[pkg] = 1
|
||||||
if not track_votes.has_key(pkg):
|
if pkg not in track_votes:
|
||||||
track_votes[pkg] = 0
|
track_votes[pkg] = 0
|
||||||
track_votes[pkg] += 1
|
track_votes[pkg] += 1
|
||||||
out.write(s)
|
out.write(s)
|
||||||
|
|
||||||
# Update statements for package votes
|
# Update statements for package votes
|
||||||
#
|
#
|
||||||
for p in track_votes.keys():
|
for p in list(track_votes.keys()):
|
||||||
s = "UPDATE Packages SET NumVotes = %d WHERE ID = %d;\n"
|
s = "UPDATE Packages SET NumVotes = %d WHERE ID = %d;\n"
|
||||||
s = s % (track_votes[p], p)
|
s = s % (track_votes[p], p)
|
||||||
out.write(s)
|
out.write(s)
|
||||||
|
@ -247,13 +247,13 @@ for p in track_votes.keys():
|
||||||
# Create package dependencies and sources
|
# Create package dependencies and sources
|
||||||
#
|
#
|
||||||
log.debug("Creating statements for package depends/sources.")
|
log.debug("Creating statements for package depends/sources.")
|
||||||
for p in seen_pkgs.keys():
|
for p in list(seen_pkgs.keys()):
|
||||||
num_deps = random.randrange(PKG_DEPS[0], PKG_DEPS[1])
|
num_deps = random.randrange(PKG_DEPS[0], PKG_DEPS[1])
|
||||||
this_deps = {}
|
this_deps = {}
|
||||||
i = 0
|
i = 0
|
||||||
while i != num_deps:
|
while i != num_deps:
|
||||||
dep = random.choice([k for k in seen_pkgs])
|
dep = random.choice([k for k in seen_pkgs])
|
||||||
if not this_deps.has_key(dep):
|
if dep not in this_deps:
|
||||||
s = "INSERT INTO PackageDepends VALUES (%d, '%s', NULL);\n"
|
s = "INSERT INTO PackageDepends VALUES (%d, '%s', NULL);\n"
|
||||||
s = s % (seen_pkgs[p], dep)
|
s = s % (seen_pkgs[p], dep)
|
||||||
out.write(s)
|
out.write(s)
|
||||||
|
|
|
@ -20,7 +20,7 @@ mysql -h $DB_HOST -u $DB_USER -p$DB_PASS < aur-schema.sql
|
||||||
|
|
||||||
if [ ! -f $DATA_FILE ]; then
|
if [ ! -f $DATA_FILE ]; then
|
||||||
echo "creating dumy-data..."
|
echo "creating dumy-data..."
|
||||||
python2 gendummydata.py $DATA_FILE
|
python3 gendummydata.py $DATA_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "loading dummy-data..."
|
echo "loading dummy-data..."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue