Bug 1802093 [wpt PR 37101] - Soft navigations timestamp test clarifications and clean...
[gecko.git] / config / createprecomplete.py
blob7a442d65bf458e2c7f2ad6b70d8a1ff959b44b81
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, unicode_literals
11 import io
12 import os
15 def get_build_entries(root_path):
16 """Iterates through the root_path, creating a list for each file and
17 directory. Excludes any file paths ending with channel-prefs.js.
18 """
19 rel_file_path_set = set()
20 rel_dir_path_set = set()
21 for root, dirs, files in os.walk(root_path):
22 for file_name in files:
23 parent_dir_rel_path = root[len(root_path) + 1 :]
24 rel_path_file = os.path.join(parent_dir_rel_path, file_name)
25 rel_path_file = rel_path_file.replace("\\", "/")
26 if not (
27 rel_path_file.endswith("channel-prefs.js")
28 or rel_path_file.endswith("update-settings.ini")
29 or rel_path_file.find("distribution/") != -1
31 rel_file_path_set.add(rel_path_file)
33 for dir_name in dirs:
34 parent_dir_rel_path = root[len(root_path) + 1 :]
35 rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
36 rel_path_dir = rel_path_dir.replace("\\", "/") + "/"
37 if rel_path_dir.find("distribution/") == -1:
38 rel_dir_path_set.add(rel_path_dir)
40 rel_file_path_list = list(rel_file_path_set)
41 rel_file_path_list.sort(reverse=True)
42 rel_dir_path_list = list(rel_dir_path_set)
43 rel_dir_path_list.sort(reverse=True)
45 return rel_file_path_list, rel_dir_path_list
48 def generate_precomplete(root_path):
49 """Creates the precomplete file containing the remove and rmdir
50 application update instructions. The given directory is used
51 for the location to enumerate and to create the precomplete file.
52 """
53 rel_path_precomplete = "precomplete"
54 # If inside a Mac bundle use the root of the bundle for the path.
55 if os.path.basename(root_path) == "Resources":
56 root_path = os.path.abspath(os.path.join(root_path, "../../"))
57 rel_path_precomplete = "Contents/Resources/precomplete"
59 precomplete_file_path = os.path.join(root_path, rel_path_precomplete)
60 # Open the file so it exists before building the list of files and open it
61 # in binary mode to prevent OS specific line endings.
62 precomplete_file = io.open(precomplete_file_path, mode="wt", newline="\n")
63 rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
64 for rel_file_path in rel_file_path_list:
65 precomplete_file.write('remove "' + rel_file_path + '"\n')
67 for rel_dir_path in rel_dir_path_list:
68 precomplete_file.write('rmdir "' + rel_dir_path + '"\n')
70 precomplete_file.close()
73 if __name__ == "__main__":
74 generate_precomplete(os.getcwd())