1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/config/createprecomplete.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +# Any copyright is dedicated to the Public Domain. 1.5 +# http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + 1.7 +# Creates the precomplete file containing the remove and rmdir application 1.8 +# update instructions which is used to remove files and directories that are no 1.9 +# longer present in a complete update. The current working directory is used for 1.10 +# the location to enumerate and to create the precomplete file. 1.11 +# For symlinks, remove instructions are always generated. 1.12 + 1.13 +import sys 1.14 +import os 1.15 + 1.16 +def get_build_entries(root_path): 1.17 + """ Iterates through the root_path, creating a list for each file and 1.18 + directory. Excludes any file paths ending with channel-prefs.js. 1.19 + To support Tor Browser updates, excludes: 1.20 + TorBrowser/Data/Browser/profiles.ini 1.21 + TorBrowser/Data/Browser/profile.default/bookmarks.html 1.22 + TorBrowser/Data/Tor/torrc 1.23 + """ 1.24 + rel_file_path_set = set() 1.25 + rel_dir_path_set = set() 1.26 + for root, dirs, files in os.walk(root_path): 1.27 + for file_name in files: 1.28 + parent_dir_rel_path = root[len(root_path)+1:] 1.29 + rel_path_file = os.path.join(parent_dir_rel_path, file_name) 1.30 + rel_path_file = rel_path_file.replace("\\", "/") 1.31 + if not (rel_path_file.endswith("channel-prefs.js") or 1.32 + rel_path_file.endswith("update-settings.ini") or 1.33 + rel_path_file == "TorBrowser/Data/Browser/profiles.ini" or 1.34 + rel_path_file == "TorBrowser/Data/Browser/profile.default/bookmarks.html" or 1.35 + rel_path_file == "TorBrowser/Data/Tor/torrc" or 1.36 + rel_path_file.find("distribution/") != -1): 1.37 + rel_file_path_set.add(rel_path_file) 1.38 + 1.39 + for dir_name in dirs: 1.40 + parent_dir_rel_path = root[len(root_path)+1:] 1.41 + rel_path_dir = os.path.join(parent_dir_rel_path, dir_name) 1.42 + rel_path_dir = rel_path_dir.replace("\\", "/")+"/" 1.43 + if rel_path_dir.find("distribution/") == -1: 1.44 + if (os.path.islink(rel_path_dir[:-1])): 1.45 + rel_file_path_set.add(rel_path_dir[:-1]) 1.46 + else: 1.47 + rel_dir_path_set.add(rel_path_dir) 1.48 + 1.49 + rel_file_path_list = list(rel_file_path_set) 1.50 + rel_file_path_list.sort(reverse=True) 1.51 + rel_dir_path_list = list(rel_dir_path_set) 1.52 + rel_dir_path_list.sort(reverse=True) 1.53 + 1.54 + return rel_file_path_list, rel_dir_path_list 1.55 + 1.56 +def generate_precomplete(root_path): 1.57 + """ Creates the precomplete file containing the remove and rmdir 1.58 + application update instructions. The given directory is used 1.59 + for the location to enumerate and to create the precomplete file. 1.60 + """ 1.61 + # If inside a Mac bundle use the root of the bundle for the path. 1.62 + if os.path.basename(root_path) == "MacOS": 1.63 + root_path = os.path.abspath(os.path.join(root_path, '../../')) 1.64 + 1.65 + rel_file_path_list, rel_dir_path_list = get_build_entries(root_path) 1.66 + precomplete_file_path = os.path.join(root_path,"precomplete") 1.67 + # open in binary mode to prevent OS specific line endings. 1.68 + precomplete_file = open(precomplete_file_path, "wb") 1.69 + for rel_file_path in rel_file_path_list: 1.70 + precomplete_file.writelines("remove \""+rel_file_path+"\"\n") 1.71 + 1.72 + for rel_dir_path in rel_dir_path_list: 1.73 + precomplete_file.writelines("rmdir \""+rel_dir_path+"\"\n") 1.74 + 1.75 + precomplete_file.close() 1.76 + 1.77 +if __name__ == "__main__": 1.78 + generate_precomplete(os.getcwd())