diff options
author | Lukas Fleischer <archlinux@cryptocrack.de> | 2011-04-12 14:47:54 +0200 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2011-04-13 12:14:37 +0200 |
commit | 31cda618ca3c726c6f5f89a52a7da2b8c9663aef (patch) | |
tree | 8cf66c4b4d1d6557ab96c25c2d183411c5cc0629 /support/schema/gendummydata.py | |
parent | e1bf49e03c91d0e102531d07199903c2f7a6d523 (diff) |
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>
Diffstat (limited to 'support/schema/gendummydata.py')
-rwxr-xr-x | support/schema/gendummydata.py | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/support/schema/gendummydata.py b/support/schema/gendummydata.py index a7679b5..d0b8b71 100755 --- a/support/schema/gendummydata.py +++ b/support/schema/gendummydata.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 """ usage: gendummydata.py outputfilename.sql """ @@ -13,8 +13,8 @@ import random import time import os import sys -import cStringIO -import commands +import io +import subprocess import logging 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)) word = contents[user].replace("'", "").replace(".","").replace(" ", "_") word = word.strip().lower() - if not seen_users.has_key(word): + if word not in seen_users: seen_users[word] = user_id user_id += 1 -user_keys = seen_users.keys() +user_keys = list(seen_users.keys()) # select random package names # @@ -119,11 +119,11 @@ while len(seen_pkgs) < MAX_PKGS: word = contents[pkg].replace("'", "").replace(".","").replace(" ", "_") word = word.strip().lower() 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 num_pkgs += 1 else: - if not seen_pkgs.has_key(word): + if word not in seen_pkgs: seen_pkgs[word] = num_pkgs num_pkgs += 1 @@ -181,7 +181,7 @@ log.debug("Number of packages: %d" % MAX_PKGS) # log.debug("Creating SQL statements for packages.") count = 0 -for p in seen_pkgs.keys(): +for p in list(seen_pkgs.keys()): NOW = int(time.time()) if count % 2 == 0: 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]) 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) s = ("INSERT INTO PackageComments (PackageID, UsersID," " Comments, CommentTS) VALUES (%d, %d, '%s', %d);\n") @@ -227,19 +227,19 @@ for u in user_keys: pkgvote = {} for v in range(num_votes): 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)" " VALUES (%d, %d);\n") s = s % (seen_users[u], pkg) pkgvote[pkg] = 1 - if not track_votes.has_key(pkg): + 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 track_votes.keys(): +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) @@ -247,13 +247,13 @@ for p in track_votes.keys(): # Create package dependencies and 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]) this_deps = {} i = 0 while i != num_deps: 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 = s % (seen_pkgs[p], dep) out.write(s) |