Backed out changeset b1aca8e61c5c (bug 958980) for bustage. a=backout
[gecko.git] / config / createprecomplete.py
blob2c39306edc9056821f1a893190f1d0078608eb11
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")):
24 rel_file_path_set.add(rel_path_file)
26 for dir_name in dirs:
27 parent_dir_rel_path = root[len(root_path)+1:]
28 rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
29 rel_path_dir = rel_path_dir.replace("\\", "/")+"/"
30 rel_dir_path_set.add(rel_path_dir)
32 rel_file_path_list = list(rel_file_path_set)
33 rel_file_path_list.sort(reverse=True)
34 rel_dir_path_list = list(rel_dir_path_set)
35 rel_dir_path_list.sort(reverse=True)
37 return rel_file_path_list, rel_dir_path_list
39 def generate_precomplete(root_path):
40 """ Creates the precomplete file containing the remove and rmdir
41 application update instructions. The given directory is used
42 for the location to enumerate and to create the precomplete file.
43 """
44 # If inside a Mac bundle use the root of the bundle for the path.
45 if os.path.basename(root_path) == "MacOS":
46 root_path = os.path.abspath(os.path.join(root_path, '../../'))
48 rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
49 precomplete_file_path = os.path.join(root_path,"precomplete")
50 # open in binary mode to prevent OS specific line endings.
51 precomplete_file = open(precomplete_file_path, "wb")
52 for rel_file_path in rel_file_path_list:
53 precomplete_file.writelines("remove \""+rel_file_path+"\"\n")
55 for rel_dir_path in rel_dir_path_list:
56 precomplete_file.writelines("rmdir \""+rel_dir_path+"\"\n")
58 precomplete_file.close()
60 if __name__ == "__main__":
61 generate_precomplete(os.getcwd())