<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import json <EOL> import logging <EOL> from website . app import init_app <EOL> from scripts import utils as script_utils <EOL> from website import models as mdl <EOL> import datetime as dt <EOL> logger = logging . getLogger ( __name__ ) <EOL> HERE = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> AFFECTED_REGISTRATION_GUIDS_FILE = os . path . join ( HERE , '<STR_LIT>' ) <EOL> REGRESSION_DATE = dt . datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> HOTFIX_DATE = dt . datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:30> , <NUM_LIT:0> ) <EOL> def is_errant_log ( log ) : <EOL> """<STR_LIT>""" <EOL> return ( <EOL> log . should_hide is not True and <EOL> ( <EOL> log . action in mdl . NodeLog . PROJECT_REGISTERED <EOL> and log . user is None <EOL> and log . date . hour == <NUM_LIT:4> <EOL> and log . date . minute == <NUM_LIT:0> <EOL> ) or <EOL> ( <EOL> log . action in mdl . NodeLog . REGISTRATION_APPROVAL_APPROVED <EOL> and log . date . hour == <NUM_LIT:4> <EOL> and log . date . minute == <NUM_LIT:0> <EOL> ) <EOL> ) <EOL> def get_errant_logs ( node ) : <EOL> return [ <EOL> each for each in node . logs <EOL> if REGRESSION_DATE <= each . date < HOTFIX_DATE <EOL> and is_errant_log ( each ) <EOL> ] <EOL> def get_errant_logs_for_tree ( root_node ) : <EOL> """<STR_LIT>""" <EOL> return ( <EOL> log <EOL> for node in root_node . node_and_primary_descendants ( ) <EOL> for log in get_errant_logs ( node ) <EOL> ) <EOL> def do_migration ( dry = True ) : <EOL> with open ( AFFECTED_REGISTRATION_GUIDS_FILE ) as fp : <EOL> affected = json . load ( fp ) <EOL> for guid in affected : <EOL> registration = mdl . Node . load ( guid ) <EOL> node = registration . registered_from <EOL> errant_logs = list ( get_errant_logs_for_tree ( node ) ) <EOL> logger . info ( '<STR_LIT>' . format ( len ( errant_logs ) , node . _id ) ) <EOL> for log in errant_logs : <EOL> log . should_hide = True <EOL> if not dry : <EOL> log . save ( ) <EOL> def main ( dry = True ) : <EOL> init_app ( set_backends = True , routes = False ) <EOL> do_migration ( dry = dry ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> dry = '<STR_LIT>' in sys . argv <EOL> if not dry : <EOL> script_utils . add_file_logger ( logger , __file__ ) <EOL> main ( dry = dry ) </s>
