1
1
import json
2
2
import os
3
+ import random
3
4
import re
5
+ import subprocess
4
6
import sys
5
7
from collections import defaultdict
6
8
from subprocess import check_output
@@ -39,9 +41,40 @@ def add_selected_mappings(mappings):
39
41
Args:
40
42
mappings (dict): A dictionary of mappings, where the keys are sites and the values are sets of regions.
41
43
"""
42
- for site , regions in mappings .items ():
43
- with open (OUTPUT_FILE , "a+" ) as f :
44
- f .write (f"{ site } { ' ' .join (regions )} \n " )
44
+ # sort the mappings by the length of the regions per site
45
+ mappings = dict (sorted (mappings .items (), key = lambda val : len (val [1 ]), reverse = True ))
46
+ print (mappings )
47
+ # place the mappings into 3 containers evenly according to the load
48
+ loads = [0 , 0 , 0 ]
49
+ containers = [[] for _ in range (3 )]
50
+ for key , value in mappings .items ():
51
+ min_idx = loads .index (min (loads ))
52
+ containers [min_idx ].append (f"{ key } { ' ' .join (value )} " )
53
+ loads [min_idx ] += len (value )
54
+ # shuffle the containers so each run for a beta is random.
55
+ random .shuffle (containers )
56
+ try :
57
+ version = int (
58
+ (
59
+ subprocess .check_output (
60
+ [sys .executable , "./collect_executables.py" , "-n" ]
61
+ )
62
+ .strip ()
63
+ .decode ()
64
+ )
65
+ .split ("-" )[0 ]
66
+ .split ("." )[1 ]
67
+ .split ("b" )[1 ]
68
+ )
69
+ except :
70
+ # failsafe version
71
+ version = 0
72
+ # get container index according to beta version
73
+ run_idx = version % 3
74
+ with open (OUTPUT_FILE , "a+" ) as f :
75
+ for mapping in containers [run_idx ]:
76
+ print (mapping )
77
+ f .write (f"{ mapping } \n " )
45
78
46
79
47
80
def process_changed_file (f , selected_mappings ):
@@ -53,7 +86,7 @@ def process_changed_file(f, selected_mappings):
53
86
selected_mappings: the selected mappings dictionary (updated in place).
54
87
"""
55
88
split = f .split (SLASH )
56
-
89
+ print ( split )
57
90
if f .startswith (os .path .join ("l10n_CM" , "sites" )) or f .startswith (
58
91
os .path .join ("l10n_CM" , "constants" )
59
92
):
0 commit comments