Bug 1655413 [wpt PR 24763] - Make CSP default-src without 'unsafe-eval' block eval...
[gecko.git] / config / createprecomplete.py
blobfadd796aa21f404b6c5f8fe4495842a806ef7821
1 # Any copyright is dedicated to the Public Domain.
2 # http://creativecommons.org/publicdomain/zero/1.0/
4 # Creates the precomplete file containing the remove and rmdir application
5 # update instructions which is used to remove files and directories that are no
6 # longer present in a complete update. The current working directory is used for
7 # the location to enumerate and to create the precomplete file.
9 from __future__ import absolute_import
10 from __future__ import unicode_literals
12 import os
13 import io
16 def get_build_entries(root_path):
17 """ Iterates through the root_path, creating a list for each file and
18 directory. Excludes any file paths ending with channel-prefs.js.
19 """
20 rel_file_path_set = set()
21 rel_dir_path_set = set()
22 for root, dirs, files in os.walk(root_path):
23 for file_name in files:
24 parent_dir_rel_path = root[len(root_path)+1:]
25 rel_path_file = os.path.join(parent_dir_rel_path, file_name)
26 rel_path_file = rel_path_file.replace("\\", "/")
27 if not (rel_path_file.endswith("channel-prefs.js") or
28 rel_path_file.endswith("update-settings.ini") or
29 rel_path_file.find("distribution/") != -1):
30 rel_file_path_set.add(rel_path_file)
32 for dir_name in dirs:
33 parent_dir_rel_path = root[len(root_path)+1:]
34 rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
35 rel_path_dir = rel_path_dir.replace("\\", "/")+"/"
36 if rel_path_dir.find("distribution/") == -1:
37 rel_dir_path_set.add(rel_path_dir)
39 rel_file_path_list = list(rel_file_path_set)
40 rel_file_path_list.sort(reverse=True)
41 rel_dir_path_list = list(rel_dir_path_set)
42 rel_dir_path_list.sort(reverse=True)
44 return rel_file_path_list, rel_dir_path_list
47 def generate_precomplete(root_path):
48 """ Creates the precomplete file containing the remove and rmdir
49 application update instructions. The given directory is used
50 for the location to enumerate and to create the precomplete file.
51 """
52 rel_path_precomplete = "precomplete"
53 # If inside a Mac bundle use the root of the bundle for the path.
54 if os.path.basename(root_path) == "Resources":
55 root_path = os.path.abspath(os.path.join(root_path, '../../'))
56 rel_path_precomplete = "Contents/Resources/precomplete"
58 precomplete_file_path = os.path.join(root_path, rel_path_precomplete)
59 # Open the file so it exists before building the list of files and open it
60 # in binary mode to prevent OS specific line endings.
61 precomplete_file = io.open(precomplete_file_path, mode="wt", newline='\n')
62 rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
63 for rel_file_path in rel_file_path_list:
64 precomplete_file.write("remove \""+rel_file_path+"\"\n")
66 for rel_dir_path in rel_dir_path_list:
67 precomplete_file.write("rmdir \""+rel_dir_path+"\"\n")
69 precomplete_file.close()
72 if __name__ == "__main__":
73 generate_precomplete(os.getcwd())