2011-04-12 08:23:18 +04:00
|
|
|
# Any copyright is dedicated to the Public Domain.
|
|
|
|
# http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
|
2012-01-19 02:10:25 +04:00
|
|
|
# Creates the precomplete file containing the remove and rmdir application
|
|
|
|
# update instructions which is used to remove files and directories that are no
|
|
|
|
# longer present in a complete update. The current working directory is used for
|
|
|
|
# the location to enumerate and to create the precomplete file.
|
2011-04-12 08:23:18 +04:00
|
|
|
|
2019-05-28 17:28:57 +03:00
|
|
|
import io
|
2022-11-24 01:04:39 +03:00
|
|
|
import os
|
2011-04-12 08:23:18 +04:00
|
|
|
|
2018-05-22 01:01:01 +03:00
|
|
|
|
2011-04-12 08:23:18 +04:00
|
|
|
def get_build_entries(root_path):
|
|
|
|
"""Iterates through the root_path, creating a list for each file and
|
2013-09-18 09:15:53 +04:00
|
|
|
directory. Excludes any file paths ending with channel-prefs.js.
|
2011-04-12 08:23:18 +04:00
|
|
|
"""
|
|
|
|
rel_file_path_set = set()
|
|
|
|
rel_dir_path_set = set()
|
|
|
|
for root, dirs, files in os.walk(root_path):
|
|
|
|
for file_name in files:
|
|
|
|
parent_dir_rel_path = root[len(root_path) + 1 :]
|
|
|
|
rel_path_file = os.path.join(parent_dir_rel_path, file_name)
|
|
|
|
rel_path_file = rel_path_file.replace("\\", "/")
|
2014-03-05 23:42:56 +04:00
|
|
|
if not (
|
|
|
|
rel_path_file.endswith("channel-prefs.js")
|
|
|
|
or rel_path_file.endswith("update-settings.ini")
|
|
|
|
or rel_path_file.find("distribution/") != -1
|
|
|
|
):
|
2011-04-12 08:23:18 +04:00
|
|
|
rel_file_path_set.add(rel_path_file)
|
|
|
|
|
|
|
|
for dir_name in dirs:
|
|
|
|
parent_dir_rel_path = root[len(root_path) + 1 :]
|
|
|
|
rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
|
|
|
|
rel_path_dir = rel_path_dir.replace("\\", "/") + "/"
|
2014-03-05 23:42:56 +04:00
|
|
|
if rel_path_dir.find("distribution/") == -1:
|
|
|
|
rel_dir_path_set.add(rel_path_dir)
|
2011-04-12 08:23:18 +04:00
|
|
|
|
|
|
|
rel_file_path_list = list(rel_file_path_set)
|
|
|
|
rel_file_path_list.sort(reverse=True)
|
|
|
|
rel_dir_path_list = list(rel_dir_path_set)
|
|
|
|
rel_dir_path_list.sort(reverse=True)
|
|
|
|
|
|
|
|
return rel_file_path_list, rel_dir_path_list
|
|
|
|
|
2018-05-22 01:01:01 +03:00
|
|
|
|
2012-11-13 11:19:43 +04:00
|
|
|
def generate_precomplete(root_path):
|
2012-01-19 02:10:25 +04:00
|
|
|
"""Creates the precomplete file containing the remove and rmdir
|
2012-11-13 11:19:43 +04:00
|
|
|
application update instructions. The given directory is used
|
2011-04-12 08:23:18 +04:00
|
|
|
for the location to enumerate and to create the precomplete file.
|
|
|
|
"""
|
2014-09-29 22:51:55 +04:00
|
|
|
rel_path_precomplete = "precomplete"
|
2011-04-13 00:46:02 +04:00
|
|
|
# If inside a Mac bundle use the root of the bundle for the path.
|
2014-09-29 22:50:56 +04:00
|
|
|
if os.path.basename(root_path) == "Resources":
|
2011-04-13 00:46:02 +04:00
|
|
|
root_path = os.path.abspath(os.path.join(root_path, "../../"))
|
2014-09-29 22:51:55 +04:00
|
|
|
rel_path_precomplete = "Contents/Resources/precomplete"
|
2011-04-13 00:46:02 +04:00
|
|
|
|
2018-05-22 01:01:01 +03:00
|
|
|
precomplete_file_path = os.path.join(root_path, rel_path_precomplete)
|
2014-09-29 22:51:55 +04:00
|
|
|
# Open the file so it exists before building the list of files and open it
|
|
|
|
# in binary mode to prevent OS specific line endings.
|
2019-05-28 17:28:57 +03:00
|
|
|
precomplete_file = io.open(precomplete_file_path, mode="wt", newline="\n")
|
2014-09-29 22:51:55 +04:00
|
|
|
rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
|
2011-04-12 08:23:18 +04:00
|
|
|
for rel_file_path in rel_file_path_list:
|
2019-05-28 17:28:57 +03:00
|
|
|
precomplete_file.write('remove "' + rel_file_path + '"\n')
|
2011-04-12 08:23:18 +04:00
|
|
|
|
|
|
|
for rel_dir_path in rel_dir_path_list:
|
2019-05-28 17:28:57 +03:00
|
|
|
precomplete_file.write('rmdir "' + rel_dir_path + '"\n')
|
2011-04-12 08:23:18 +04:00
|
|
|
|
|
|
|
precomplete_file.close()
|
|
|
|
|
2018-05-22 01:01:01 +03:00
|
|
|
|
2011-04-12 08:23:18 +04:00
|
|
|
if __name__ == "__main__":
|
2012-11-13 11:19:43 +04:00
|
|
|
generate_precomplete(os.getcwd())
|