backoug Bug 1034294 - Fix SharedBufferManagerParent r=jgilbert
[gecko.git] / config / createprecomplete.py
blobe58dfe520b81e8905a7d565749993e8aa9e35b18
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 import sys
10 import os
12 def get_build_entries(root_path):
13 """ Iterates through the root_path, creating a list for each file and
14 directory. Excludes any file paths ending with channel-prefs.js.
15 """
16 rel_file_path_set = set()
17 rel_dir_path_set = set()
18 for root, dirs, files in os.walk(root_path):
19 for file_name in files:
20 parent_dir_rel_path = root[len(root_path)+1:]
21 rel_path_file = os.path.join(parent_dir_rel_path, file_name)
22 rel_path_file = rel_path_file.replace("\\", "/")
23 if not (rel_path_file.endswith("channel-prefs.js") or
24 rel_path_file.endswith("update-settings.ini") or
25 rel_path_file.find("distribution/") != -1):
26 rel_file_path_set.add(rel_path_file)
28 for dir_name in dirs:
29 parent_dir_rel_path = root[len(root_path)+1:]
30 rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
31 rel_path_dir = rel_path_dir.replace("\\", "/")+"/"
32 if rel_path_dir.find("distribution/") == -1:
33 rel_dir_path_set.add(rel_path_dir)
35 rel_file_path_list = list(rel_file_path_set)
36 rel_file_path_list.sort(reverse=True)
37 rel_dir_path_list = list(rel_dir_path_set)
38 rel_dir_path_list.sort(reverse=True)
40 return rel_file_path_list, rel_dir_path_list
42 def generate_precomplete(root_path):
43 """ Creates the precomplete file containing the remove and rmdir
44 application update instructions. The given directory is used
45 for the location to enumerate and to create the precomplete file.
46 """
47 # If inside a Mac bundle use the root of the bundle for the path.
48 if os.path.basename(root_path) == "MacOS":
49 root_path = os.path.abspath(os.path.join(root_path, '../../'))
51 rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
52 precomplete_file_path = os.path.join(root_path,"precomplete")
53 # open in binary mode to prevent OS specific line endings.
54 precomplete_file = open(precomplete_file_path, "wb")
55 for rel_file_path in rel_file_path_list:
56 precomplete_file.writelines("remove \""+rel_file_path+"\"\n")
58 for rel_dir_path in rel_dir_path_list:
59 precomplete_file.writelines("rmdir \""+rel_dir_path+"\"\n")
61 precomplete_file.close()
63 if __name__ == "__main__":
64 generate_precomplete(os.getcwd())