parameters: (flags_path, new_threshold)
docstring: Updates the flagfile at `flags_path`, changing the value for
      `resign_threshold` to `new_threshold`
docstring_summary: Updates the flagfile at `flags_path`, changing the value for
      `resign_threshold` to `new_threshold`
docstring_tokens: Updates the flagfile at flags_path changing the value for resign_threshold to new_threshold
function: def update_flagfile(flags_path, new_threshold):
      """Updates the flagfile at `flags_path`, changing the value for
      `resign_threshold` to `new_threshold`
      """
      if abs(new_threshold) > 1:
          raise ValueError("Invalid new percentile for resign threshold")
      with tf.gfile.GFile(flags_path) as f:
          lines = f.read()
      if new_threshold > 0:
          new_threshold *= -1
      if not RESIGN_FLAG_REGEX.search(lines):
          print("Resign threshold flag not found in flagfile {}!  Aborting.".format(flags_path))
          sys.exit(1)
      old_threshold = RESIGN_FLAG_REGEX.search(lines).groups(1)
      lines = re.sub(RESIGN_FLAG_REGEX, "--resign_threshold={:.3f}".format(new_threshold), lines)
  
      if abs(float(old_threshold[0]) - new_threshold) < 0.001:
          print("Not updating percentiles; {} ~= {:.3f}".format(
                  old_threshold[0], new_threshold), flush=True)
      else:
          print("Updated percentile from {} to {:.3f}".format(
                  old_threshold[0], new_threshold), flush=True)
          with tf.gfile.GFile(flags_path, 'w') as f:
              f.write(lines)
function_tokens: def update_flagfile ( flags_path , new_threshold ) : if abs ( new_threshold ) > 1 : raise ValueError ( "Invalid new percentile for resign threshold" ) with tf . gfile . GFile ( flags_path ) as f : lines = f . read ( ) if new_threshold > 0 : new_threshold *= - 1 if not RESIGN_FLAG_REGEX . search ( lines ) : print ( "Resign threshold flag not found in flagfile {}!  Aborting." . format ( flags_path ) ) sys . exit ( 1 ) old_threshold = RESIGN_FLAG_REGEX . search ( lines ) . groups ( 1 ) lines = re . sub ( RESIGN_FLAG_REGEX , "--resign_threshold={:.3f}" . format ( new_threshold ) , lines ) if abs ( float ( old_threshold [ 0 ] ) - new_threshold ) < 0.001 : print ( "Not updating percentiles; {} ~= {:.3f}" . format ( old_threshold [ 0 ] , new_threshold ) , flush = True ) else : print ( "Updated percentile from {} to {:.3f}" . format ( old_threshold [ 0 ] , new_threshold ) , flush = True ) with tf . gfile . GFile ( flags_path , 'w' ) as f : f . write ( lines )