Changeset 266997 in webkit
- Timestamp:
- Sep 13, 2020 10:21:33 AM (4 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r266993 r266997 1 2020-09-13 Alexey Proskuryakov <ap@apple.com> 2 3 Move block-spammers tool to python 3 4 https://bugs.webkit.org/show_bug.cgi?id=216457 5 6 Reviewed by Sam Weinig. 7 8 * Scripts/block-spammers: Updated for new print() and translate() syntax, and 9 moved from raw_input() to input(). 10 1 11 2020-09-13 Wenson Hsieh <wenson_hsieh@apple.com> 2 12 -
trunk/Tools/Scripts/block-spammers
r261128 r266997 1 #!/usr/bin/env python 2 3 # Copyright (C) 2019 Apple Inc. All rights reserved.1 #!/usr/bin/env python3 2 3 # Copyright (C) 2019-2020 Apple Inc. All rights reserved. 4 4 # 5 5 # Redistribution and use in source and binary forms, with or without … … 32 32 import requests 33 33 import os 34 import sys35 34 from dateutil.parser import parse 36 35 from webkitpy.common.net.credentials import Credentials … … 121 120 params = {'token': bugzilla_token}) 122 121 if not response: 123 print '!!! Failed to move bug ' + str(bug_id) + ': ' + response.text122 print('!!! Failed to move bug ' + str(bug_id) + ': ' + response.text) 124 123 125 124 … … 129 128 params={'token': bugzilla_token}) 130 129 if not response: 131 print '!!! Failed to hide comments for bug ' + str(bug_id) + ': ' + response.text130 print('!!! Failed to hide comments for bug ' + str(bug_id) + ': ' + response.text) 132 131 for comment_id in comment_ids: 133 132 response = requests.put('https://bugs.webkit.org/rest/bug/comment/' + str(comment_id) + '/tags', … … 135 134 params={'token': bugzilla_token}) 136 135 if not response: 137 print '!!! Failed to mark comment with spam tag: ' + response.text136 print('!!! Failed to mark comment with spam tag: ' + response.text) 138 137 139 138 def hide_attachments(bug_id, attachment_ids): … … 142 141 params={'token': bugzilla_token}) 143 142 if not response: 144 print '!!! Failed to hide attachments for bug ' + str(bug_id) + ': ' + response.text143 print('!!! Failed to hide attachments for bug ' + str(bug_id) + ': ' + response.text) 145 144 146 145 … … 155 154 answers= {'yes': True, 'y': True, 'ye': True, 'no': False, 'n': False} 156 155 while True: 157 sys.stdout.write(question + prompt_string) 158 response = raw_input().lower() 156 response = input(question + prompt_string).lower() 159 157 if default is not None and response == '': 160 158 return answers[default] … … 164 162 165 163 def sanitized_string(string): 166 return string. encode('utf-8').translate(None, '\x1B')164 return string.translate(str.maketrans('', '', '\x1B')) 167 165 168 166 def main(): … … 174 172 175 173 if not can_use_this_tool(): 176 print 'You need to be a Bugzilla admin to use this tool.'174 print('You need to be a Bugzilla admin to use this tool.') 177 175 exit(1) 178 176 179 print 'Fetching account activity...'177 print('Fetching account activity...') 180 178 181 179 users_to_disable = [] … … 193 191 194 192 for user in users_to_disable: 195 print sanitized_string(user['real_name']) + ' <' + user['name'] + '>'193 print(sanitized_string(user['real_name']) + ' <' + user['name'] + '>') 196 194 if not user['can_login']: 197 print '*** already disabled ***'195 print('*** already disabled ***') 198 196 if user['bugs_created']: 199 print 'Created ' + str(len(user['bugs_created'])) + ' bug(s):'197 print('Created ' + str(len(user['bugs_created'])) + ' bug(s):') 200 198 for bug in user['bugs_created']: 201 print 'https://bugs.webkit.org/show_bug.cgi?id=' + str(bug['id']) + ' ' + sanitized_string(bug['summary'])199 print('https://bugs.webkit.org/show_bug.cgi?id=' + str(bug['id']) + ' ' + sanitized_string(bug['summary'])) 202 200 if user['bugs_commented']: 203 print 'Commented on ' + str(len(user['bugs_commented'])) + ' bug(s):'201 print('Commented on ' + str(len(user['bugs_commented'])) + ' bug(s):') 204 202 for bug in user['bugs_commented']: 205 print 'https://bugs.webkit.org/show_bug.cgi?id=' + str(bug['id']) + ' ' + sanitized_string(bug['summary'])203 print('https://bugs.webkit.org/show_bug.cgi?id=' + str(bug['id']) + ' ' + sanitized_string(bug['summary'])) 206 204 for comment in bug['comments']: 207 205 if comment['creator'] == user['name']: 208 print 'Comment ' + str(comment['count']) + ', ' + str(parse(comment['creation_time'])) + ': ' + sanitized_string(comment['text'])206 print('Comment ' + str(comment['count']) + ', ' + str(parse(comment['creation_time'])) + ': ' + sanitized_string(comment['text'])) 209 207 if user['bugs_with_attachments_added']: 210 print 'Added attachments to ' + str(len(user['bugs_with_attachments_added'])) + ' bug(s):'208 print('Added attachments to ' + str(len(user['bugs_with_attachments_added'])) + ' bug(s):') 211 209 for bug in user['bugs_with_attachments_added']: 212 print 'https://bugs.webkit.org/show_bug.cgi?id=' + str(bug['id']) + ' ' + sanitized_string(bug['summary'])210 print('https://bugs.webkit.org/show_bug.cgi?id=' + str(bug['id']) + ' ' + sanitized_string(bug['summary'])) 213 211 for attachment in bug['attachments']: 214 212 if attachment['creator'] == user['name']: 215 print 'Attachment ' + str(attachment['id']) + ', ' + str(parse(attachment['creation_time'])) + ': ' + sanitized_string(attachment['summary'])216 print 213 print('Attachment ' + str(attachment['id']) + ', ' + str(parse(attachment['creation_time'])) + ': ' + sanitized_string(attachment['summary'])) 214 print() 217 215 218 216 if not ask_yes_no("Block all these accounts, and hide their bugs and comments?"): 219 print "*** Exiting, no work performed ***"217 print("*** Exiting, no work performed ***") 220 218 exit(0) 221 219 … … 223 221 for user in users_to_disable: 224 222 if not user['can_login']: 225 print 'User ' + str(user['name']) + ' is already disabled, skipping'223 print('User ' + str(user['name']) + ' is already disabled, skipping') 226 224 continue 227 print 'Disabling user ' + str(user['name'])225 print('Disabling user ' + str(user['name'])) 228 226 disable_user(user['id'], 'spam') 229 227 … … 231 229 for bug in user['bugs_created']: 232 230 if bug['product'] == 'Spam': 233 print 'Bug ' + str(bug['id']) + ' is already in the Spam product, skipping'231 print('Bug ' + str(bug['id']) + ' is already in the Spam product, skipping') 234 232 continue 235 print 'Moving bug ' + str(bug['id']) + ' to the Spam product'233 print('Moving bug ' + str(bug['id']) + ' to the Spam product') 236 234 hide_bug(bug['id']) 237 235 … … 242 240 continue 243 241 if comment['is_private']: 244 print 'Comment ' + str(comment['count']) + ' on bug ' + str(bug['id']) + ' is already private, skipping'242 print('Comment ' + str(comment['count']) + ' on bug ' + str(bug['id']) + ' is already private, skipping') 245 243 continue 246 244 assert(comment['bug_id'] == bug['id']) 247 245 comments_to_hide.append(comment['id']) 248 246 if comments_to_hide: 249 print 'Hiding comment(s) from user ' + str(user['name']) + ' on bug ' + str(bug['id'])247 print('Hiding comment(s) from user ' + str(user['name']) + ' on bug ' + str(bug['id'])) 250 248 hide_comments(bug['id'], comments_to_hide) 251 249 … … 256 254 continue 257 255 if attachment['is_private']: 258 print 'Attachment ' + str(attachment['id']) + ' on bug ' + str(bug['id']) + ' is already private, skipping'256 print('Attachment ' + str(attachment['id']) + ' on bug ' + str(bug['id']) + ' is already private, skipping') 259 257 continue 260 258 assert(attachment['bug_id'] == bug['id']) 261 259 attachments_to_hide.append(attachment['id']) 262 260 if attachments_to_hide: 263 print 'Deleting attachment(s) from user ' + str(user['name']) + ' on bug ' + str(bug['id'])261 print('Deleting attachment(s) from user ' + str(user['name']) + ' on bug ' + str(bug['id'])) 264 262 hide_attachments(bug['id'], attachments_to_hide) 265 263
Note: See TracChangeset
for help on using the changeset viewer.