Page MenuHomePhabricator
Paste P65796

linter_cleaner.py
ActivePublic

Authored by Ladsgroup on Jul 4 2024, 8:32 AM.
Project Tags
None
Referenced Files
F56217519: linter_cleaner.py
Jul 4 2024, 8:32 AM
Subscribers
None
import re
import subprocess
import sys
import time
from datetime import datetime
def run(command):
print(datetime.fromtimestamp(time.time()), command)
if '--run' not in sys.argv and 'show slave' not in command:
return ''
return run_internal(command)
def run_internal(command):
"""Do not call this function directly."""
res = subprocess.run(command, capture_output=True, shell=True)
stderr = res.stderr.decode('utf-8')
stderr_cleaned = re.sub(r'\s', '', stderr)
if stderr_cleaned:
print('ERROR: ')
print('--------')
print(stderr)
print('--------')
else:
stderr = ''
stdout = res.stdout.decode('utf-8')
print('STDOUT')
stdout_cleaned = re.sub(r'\s', '', stdout)
if stdout_cleaned:
print(stdout)
else:
stdout = ''
output = stdout
if stderr_cleaned:
output += '\nerror:\n' + stderr
return output
while True:
if sys.argv[1] == 'commonswiki' and '--force' not in sys.argv:
break
res = run('sql {} -- -e "select linter_id from linter left join page on linter_page = page_id where page_namespace is null limit 400;"'.format(sys.argv[1]))
ids = re.findall(r'\d+', res)
if not ids:
break
run('sql {} --write -- -e "delete from linter where linter_id in ({});"'.format(sys.argv[1], ','.join(ids)))
print('sleeeping zzzz')
time.sleep(5)