Offline Server  1.6
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
createprecomplete.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Any copyright is dedicated to the Public Domain.
4 # http://creativecommons.org/publicdomain/zero/1.0/
5 
6 # Creates the precomplete file containing the remove, remove-cc, and rmdir
7 # application update instructions which is used to remove files and directories
8 # that are no longer present in a complete update. The current working directory
9 # is used for the location to enumerate and to create the precomplete file.
10 
11 import sys
12 import os
13 
14 def get_build_entries(root_path):
15  """ Iterates through the root_path, creating a list for each file and
16  directory. Excludes any path starting with extensions or distribution.
17  """
18  rel_file_path_set = set()
19  rel_dir_path_set = set()
20  for root, dirs, files in os.walk(root_path):
21  for file_name in files:
22  parent_dir_rel_path = root[len(root_path)+1:]
23  rel_path_file = os.path.join(parent_dir_rel_path, file_name)
24  rel_path_file = rel_path_file.replace("\\", "/")
25  if not (rel_path_file.startswith("distribution/") or
26  rel_path_file.startswith("extensions/")):
27  rel_file_path_set.add(rel_path_file)
28 
29  for dir_name in dirs:
30  parent_dir_rel_path = root[len(root_path)+1:]
31  rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
32  rel_path_dir = rel_path_dir.replace("\\", "/")+"/"
33  if not (rel_path_dir.startswith("distribution/") or
34  rel_path_dir.startswith("extensions/")):
35  rel_dir_path_set.add(rel_path_dir)
36 
37  rel_file_path_list = list(rel_file_path_set)
38  rel_file_path_list.sort(reverse=True)
39  rel_dir_path_list = list(rel_dir_path_set)
40  rel_dir_path_list.sort(reverse=True)
41 
42  return rel_file_path_list, rel_dir_path_list
43 
45  """ Creates the precomplete file containing the remove, remove-cc, and rmdir
46  application update instructions. The current working directory is used
47  for the location to enumerate and to create the precomplete file.
48  """
49  root_path = os.getcwd()
50  # If inside a Mac bundle use the root of the bundle for the path.
51  if os.path.basename(root_path) == "MacOS":
52  root_path = os.path.abspath(os.path.join(root_path, '../../'))
53 
54  rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
55  precomplete_file_path = os.path.join(root_path,"precomplete")
56  # open in binary mode to prevent OS specific line endings.
57  precomplete_file = open(precomplete_file_path, "wb")
58  for rel_file_path in rel_file_path_list:
59  if rel_file_path.endswith("channel-prefs.js"):
60  precomplete_file.writelines("remove-cc \""+rel_file_path+"\"\n")
61  else:
62  precomplete_file.writelines("remove \""+rel_file_path+"\"\n")
63 
64  for rel_dir_path in rel_dir_path_list:
65  precomplete_file.writelines("rmdir \""+rel_dir_path+"\"\n")
66 
67  precomplete_file.close()
68 
69 if __name__ == "__main__":
← centre documentaire © anakeen - published under CC License - Dynacase