Back to index

enigmail  1.4.3
createprecomplete.py
Go to the documentation of this file.
00001 # Any copyright is dedicated to the Public Domain.
00002 # http://creativecommons.org/publicdomain/zero/1.0/
00003 
00004 # Creates the precomplete file containing the remove and rmdir application
00005 # update instructions which is used to remove files and directories that are no
00006 # longer present in a complete update. The current working directory is used for
00007 # the location to enumerate and to create the precomplete file.
00008 
00009 import sys
00010 import os
00011 
00012 def get_build_entries(root_path):
00013     """ Iterates through the root_path, creating a list for each file and
00014         directory. Excludes any path starting with extensions or distribution
00015         and paths ending with channel-prefs.js.
00016     """
00017     rel_file_path_set = set()
00018     rel_dir_path_set = set()
00019     for root, dirs, files in os.walk(root_path):
00020         for file_name in files:
00021             parent_dir_rel_path = root[len(root_path)+1:]
00022             rel_path_file = os.path.join(parent_dir_rel_path, file_name)
00023             rel_path_file = rel_path_file.replace("\\", "/")
00024             if not (rel_path_file.startswith("distribution/") or
00025                     rel_path_file.startswith("extensions/") or
00026                     rel_path_file.endswith("channel-prefs.js")):
00027                 rel_file_path_set.add(rel_path_file)
00028 
00029         for dir_name in dirs:
00030             parent_dir_rel_path = root[len(root_path)+1:]
00031             rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
00032             rel_path_dir = rel_path_dir.replace("\\", "/")+"/"
00033             if not (rel_path_dir.startswith("distribution/") or
00034                     rel_path_dir.startswith("extensions/")):
00035                 rel_dir_path_set.add(rel_path_dir)
00036 
00037     rel_file_path_list = list(rel_file_path_set)
00038     rel_file_path_list.sort(reverse=True)
00039     rel_dir_path_list = list(rel_dir_path_set)
00040     rel_dir_path_list.sort(reverse=True)
00041 
00042     return rel_file_path_list, rel_dir_path_list
00043 
00044 def generate_precomplete():
00045     """ Creates the precomplete file containing the remove and rmdir
00046         application update instructions. The current working directory is used
00047         for the location to enumerate and to create the precomplete file.
00048     """
00049     root_path = os.getcwd()
00050     # If inside a Mac bundle use the root of the bundle for the path.
00051     if os.path.basename(root_path) == "MacOS":
00052         root_path = os.path.abspath(os.path.join(root_path, '../../'))
00053 
00054     rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
00055     precomplete_file_path = os.path.join(root_path,"precomplete")
00056     # open in binary mode to prevent OS specific line endings.
00057     precomplete_file = open(precomplete_file_path, "wb")
00058     for rel_file_path in rel_file_path_list:
00059         precomplete_file.writelines("remove \""+rel_file_path+"\"\n")
00060 
00061     for rel_dir_path in rel_dir_path_list:
00062         precomplete_file.writelines("rmdir \""+rel_dir_path+"\"\n")
00063 
00064     precomplete_file.close()
00065 
00066 if __name__ == "__main__":
00067     generate_precomplete()