~extension-hackers/globalmenu-extension/3.5

« back to all changes in this revision

Viewing changes to config/createprecomplete.py

  • Committer: Chris Coulson
  • Date: 2011-08-05 17:37:02 UTC
  • Revision ID: chrisccoulson@ubuntu.com-20110805173702-n11ykbt0tdp5u07q
Refresh build system from FIREFOX_6_0b5_BUILD1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Any copyright is dedicated to the Public Domain.
 
2
# http://creativecommons.org/publicdomain/zero/1.0/
 
3
 
 
4
# Creates the precomplete file containing the remove, remove-cc, and rmdir
 
5
# application update instructions which is used to remove files and directories
 
6
# that are no longer present in a complete update. The current working directory
 
7
# is used for the location to enumerate and to create the precomplete file.
 
8
 
 
9
import sys
 
10
import os
 
11
 
 
12
def get_build_entries(root_path):
 
13
    """ Iterates through the root_path, creating a list for each file and
 
14
        directory. Excludes any path starting with extensions or distribution.
 
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.startswith("distribution/") or
 
24
                    rel_path_file.startswith("extensions/")):
 
25
                rel_file_path_set.add(rel_path_file)
 
26
 
 
27
        for dir_name in dirs:
 
28
            parent_dir_rel_path = root[len(root_path)+1:]
 
29
            rel_path_dir = os.path.join(parent_dir_rel_path, dir_name)
 
30
            rel_path_dir = rel_path_dir.replace("\\", "/")+"/"
 
31
            if not (rel_path_dir.startswith("distribution/") or
 
32
                    rel_path_dir.startswith("extensions/")):
 
33
                rel_dir_path_set.add(rel_path_dir)
 
34
 
 
35
    rel_file_path_list = list(rel_file_path_set)
 
36
    rel_file_path_list.sort(reverse=True)
 
37
    rel_dir_path_list = list(rel_dir_path_set)
 
38
    rel_dir_path_list.sort(reverse=True)
 
39
 
 
40
    return rel_file_path_list, rel_dir_path_list
 
41
 
 
42
def generate_precomplete():
 
43
    """ Creates the precomplete file containing the remove, remove-cc, and rmdir
 
44
        application update instructions. The current working directory is used
 
45
        for the location to enumerate and to create the precomplete file.
 
46
    """
 
47
    root_path = os.getcwd()
 
48
    # If inside a Mac bundle use the root of the bundle for the path.
 
49
    if os.path.basename(root_path) == "MacOS":
 
50
        root_path = os.path.abspath(os.path.join(root_path, '../../'))
 
51
 
 
52
    rel_file_path_list, rel_dir_path_list = get_build_entries(root_path)
 
53
    precomplete_file_path = os.path.join(root_path,"precomplete")
 
54
    # open in binary mode to prevent OS specific line endings.
 
55
    precomplete_file = open(precomplete_file_path, "wb")
 
56
    for rel_file_path in rel_file_path_list:
 
57
        if rel_file_path.endswith("channel-prefs.js"):
 
58
            precomplete_file.writelines("remove-cc \""+rel_file_path+"\"\n")
 
59
        else:
 
60
            precomplete_file.writelines("remove \""+rel_file_path+"\"\n")
 
61
 
 
62
    for rel_dir_path in rel_dir_path_list:
 
63
        precomplete_file.writelines("rmdir \""+rel_dir_path+"\"\n")
 
64
 
 
65
    precomplete_file.close()
 
66
 
 
67
if __name__ == "__main__":
 
68
    generate_precomplete()