-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoose_random_files
executable file
·38 lines (33 loc) · 1.32 KB
/
choose_random_files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python -B
# -*- coding: utf-8 -*-
##############################################################################
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
##############################################################################
#
# Throwaway script to randomly choose one file from each tag in a slic output
# file and print it out. These can then be used as testcases in the test suite,
# so the test suite has wide coverage of the different possible types of file.
import os
import sys
import argparse
import subprocess
import json
import shutil
import random
with open("/usr/src/b2g/occurrences.json", "r") as fh:
occurrences = json.load(fh)
# Rejig data structure so top-level key is the tag instead of the license
# text hash, and value is a list of the corresponding license objects
bytag = {}
for hash, occurrence in occurrences.items():
tag = occurrence['tag']
if tag in bytag:
bytag[tag].append(occurrence)
else:
bytag[tag] = [occurrence]
for tag, info in bytag.items():
item = random.choice(info)
filename = random.choice(item['files'])
print "/usr/src/b2g/" + filename