comparison tools/load_tracker.py @ 5376:64b05e24dbd8

Python 3 preparation: convert print to a function. Tool-assisted patch. It is possible that some "from __future__ import print_function" are not in fact needed, if a file only uses print() with a single string as an argument and so would work fine in Python 2 without that import.
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 09:54:52 +0000
parents 6e9b9743de89
children 2120f77554d5
comparison
equal deleted inserted replaced
5375:1ad46057ae4a 5376:64b05e24dbd8
3 Usage: %s <tracker home> <N> 3 Usage: %s <tracker home> <N>
4 4
5 Load up the indicated tracker with N issues and N/100 users. 5 Load up the indicated tracker with N issues and N/100 users.
6 ''' 6 '''
7 7
8 from __future__ import print_function
8 import sys, os, random 9 import sys, os, random
9 from roundup import instance 10 from roundup import instance
10 11
11 # open the instance 12 # open the instance
12 if len(sys.argv) < 2: 13 if len(sys.argv) < 2:
13 print "Error: Not enough arguments" 14 print("Error: Not enough arguments")
14 print __doc__.strip()%(sys.argv[0]) 15 print(__doc__.strip()%(sys.argv[0]))
15 sys.exit(1) 16 sys.exit(1)
16 tracker_home = sys.argv[1] 17 tracker_home = sys.argv[1]
17 N = int(sys.argv[2]) 18 N = int(sys.argv[2])
18 19
19 # open the tracker 20 # open the tracker
56 db.user.lookup('alpha0') 57 db.user.lookup('alpha0')
57 except: 58 except:
58 # add some users 59 # add some users
59 M = N/100 60 M = N/100
60 for i in range(M): 61 for i in range(M):
61 print '\ruser', i, ' ', 62 print('\ruser', i, ' ', end=' ')
62 sys.stdout.flush() 63 sys.stdout.flush()
63 if i/17 == 0: 64 if i/17 == 0:
64 db.user.create(username=names[i%17]) 65 db.user.create(username=names[i%17])
65 else: 66 else:
66 db.user.create(username=names[i%17]+str(i/17)) 67 db.user.create(username=names[i%17]+str(i/17))
67 68
68 # assignable user list 69 # assignable user list
69 users = db.user.list() 70 users = db.user.list()
70 users.remove(db.user.lookup('anonymous')) 71 users.remove(db.user.lookup('anonymous'))
71 print 72 print()
72 73
73 # now create the issues 74 # now create the issues
74 for i in range(N): 75 for i in range(N):
75 print '\rissue', i, ' ', 76 print('\rissue', i, ' ', end=' ')
76 sys.stdout.flush() 77 sys.stdout.flush()
77 # in practise, about 90% of issues are resolved 78 # in practise, about 90% of issues are resolved
78 if random.random() > .9: 79 if random.random() > .9:
79 status = random.choice(statuses) 80 status = random.choice(statuses)
80 else: 81 else:
84 priority=random.choice(priorities), 85 priority=random.choice(priorities),
85 status=status, 86 status=status,
86 assignedto=random.choice(users)) 87 assignedto=random.choice(users))
87 if not i%1000: 88 if not i%1000:
88 db.commit() 89 db.commit()
89 print 90 print()
90 91
91 db.commit() 92 db.commit()
92 finally: 93 finally:
93 db.close() 94 db.close()
94 95

Roundup Issue Tracker: http://roundup-tracker.org/