Changeset 266997 in webkit


Ignore:
Timestamp:
Sep 13, 2020 10:21:33 AM (4 years ago)
Author:
ap@apple.com
Message:

Move block-spammers tool to python 3
https://bugs.webkit.org/show_bug.cgi?id=216457

Reviewed by Sam Weinig.

  • Scripts/block-spammers: Updated for new print() and translate() syntax, and

moved from raw_input() to input().

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r266993 r266997  
     12020-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
    1112020-09-13  Wenson Hsieh  <wenson_hsieh@apple.com>
    212
  • 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.
    44#
    55# Redistribution and use in source and binary forms, with or without
     
    3232import requests
    3333import os
    34 import sys
    3534from dateutil.parser import parse
    3635from webkitpy.common.net.credentials import Credentials
     
    121120        params = {'token': bugzilla_token})
    122121    if not response:
    123         print '!!! Failed to move bug ' + str(bug_id) + ': ' + response.text
     122        print('!!! Failed to move bug ' + str(bug_id) + ': ' + response.text)
    124123
    125124
     
    129128        params={'token': bugzilla_token})
    130129    if not response:
    131         print '!!! Failed to hide comments for bug ' + str(bug_id) + ': ' + response.text
     130        print('!!! Failed to hide comments for bug ' + str(bug_id) + ': ' + response.text)
    132131    for comment_id in comment_ids:
    133132        response = requests.put('https://bugs.webkit.org/rest/bug/comment/' + str(comment_id) + '/tags',
     
    135134                                params={'token': bugzilla_token})
    136135        if not response:
    137             print '!!! Failed to mark comment with spam tag: ' + response.text
     136            print('!!! Failed to mark comment with spam tag: ' + response.text)
    138137
    139138def hide_attachments(bug_id, attachment_ids):
     
    142141        params={'token': bugzilla_token})
    143142    if not response:
    144         print '!!! Failed to hide attachments for bug ' + str(bug_id) + ': ' + response.text
     143        print('!!! Failed to hide attachments for bug ' + str(bug_id) + ': ' + response.text)
    145144
    146145
     
    155154    answers= {'yes': True, 'y': True, 'ye': True, 'no': False, 'n': False}
    156155    while True:
    157         sys.stdout.write(question + prompt_string)
    158         response = raw_input().lower()
     156        response = input(question + prompt_string).lower()
    159157        if default is not None and response == '':
    160158            return answers[default]
     
    164162
    165163def sanitized_string(string):
    166     return string.encode('utf-8').translate(None, '\x1B')
     164    return string.translate(str.maketrans('', '', '\x1B'))
    167165
    168166def main():
     
    174172
    175173    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.')
    177175        exit(1)
    178176
    179     print 'Fetching account activity...'
     177    print('Fetching account activity...')
    180178
    181179    users_to_disable = []
     
    193191
    194192    for user in users_to_disable:
    195         print sanitized_string(user['real_name']) + ' <' + user['name'] + '>'
     193        print(sanitized_string(user['real_name']) + ' <' + user['name'] + '>')
    196194        if not user['can_login']:
    197             print '*** already disabled ***'
     195            print('*** already disabled ***')
    198196        if user['bugs_created']:
    199             print 'Created ' + str(len(user['bugs_created'])) + ' bug(s):'
     197            print('Created ' + str(len(user['bugs_created'])) + ' bug(s):')
    200198            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']))
    202200        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):')
    204202        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']))
    206204            for comment in bug['comments']:
    207205                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']))
    209207        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):')
    211209        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']))
    213211            for attachment in bug['attachments']:
    214212                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()
    217215
    218216    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 ***")
    220218        exit(0)
    221219
     
    223221    for user in users_to_disable:
    224222        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')
    226224            continue
    227         print 'Disabling user ' + str(user['name'])
     225        print('Disabling user ' + str(user['name']))
    228226        disable_user(user['id'], 'spam')
    229227
     
    231229        for bug in user['bugs_created']:
    232230            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')
    234232                continue
    235             print 'Moving bug ' + str(bug['id']) + ' to the Spam product'
     233            print('Moving bug ' + str(bug['id']) + ' to the Spam product')
    236234            hide_bug(bug['id'])
    237235
     
    242240                    continue
    243241                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')
    245243                    continue
    246244                assert(comment['bug_id'] == bug['id'])
    247245                comments_to_hide.append(comment['id'])
    248246            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']))
    250248            hide_comments(bug['id'], comments_to_hide)
    251249
     
    256254                    continue
    257255                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')
    259257                    continue
    260258                assert(attachment['bug_id'] == bug['id'])
    261259                attachments_to_hide.append(attachment['id'])
    262260            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']))
    264262            hide_attachments(bug['id'], attachments_to_hide)
    265263
Note: See TracChangeset for help on using the changeset viewer.