forked from dawbarton/pdf2svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_win_installer_file_lists.py
107 lines (89 loc) · 3.98 KB
/
create_win_installer_file_lists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
This script generates 2 lists of NSIS commands (install&uninstall)
for all files in a given directory
It has been taken from
http://nsis.sourceforge.net/Talk:Uninstall_only_installed_files
and has been slightly modified.
Usage:
gen_list_files_for_nsis.py
Where
<dir src> : dir with sources; must exist
<inst list> : list of files to install (NSIS syntax)
<uninst list> : list of files to uninstall (NSIS syntax)
(both these will be overwriten each time)
"""
import sys, os, glob
# global settings
dirs_and_files = [['build/dist-32bits', 'inst_file_list_32bits.txt', 'uninst_file_list_32bits.txt'], ['build/dist-64bits', 'inst_file_list_64bits.txt', 'uninst_file_list_64bits.txt']]
just_print_flag = 0 # turn to 1 for debugging
# templates for the output
inst_dir_tpl = ' SetOutPath "$INSTDIR%s"'
inst_file_tpl = ' File "${FILES_SOURCE_PATH}%s"'
uninst_file_tpl = ' Delete "$INSTDIR%s"'
uninst_dir_tpl = ' RMDir "$INSTDIR%s"'
for source_dir, inst_list, uninst_list in dirs_and_files:
if not os.path.isdir(source_dir):
print('Directory %s not found!' % (soure_dir))
sys.exit(1)
def open_file_for_writting(filename):
"return a handle to the file to write to"
try:
h = file(filename, "w")
except:
print "Problem opening file %s for writting"%filename
sys.exit(1)
return h
if not just_print_flag:
ih= open_file_for_writting(inst_list)
uh= open_file_for_writting(uninst_list)
stack_of_visited = []
counter_files = 0
counter_dirs = 0
print "Generating the install & uninstall list of files"
print " for directory", source_dir
print >> ih, " ; Files to install\n"
print >> uh, " ; Files and dirs to remove\n"
# man page of walk() in Python 2.2 (the new one in 2.4 is easier to use)
# os.path.walk(path, visit, arg)
#~ Calls the function visit with arguments (arg, dirname, names) for each directory
#~ in the directory tree rooted at path (including path itself, if it is a directory).
#~ The argument dirname specifies the visited directory, the argument names lists
#~ the files in the directory (gotten from os.listdir(dirname)). The visit function
#~ may modify names to influence the set of directories visited below dirname,
#~ e.g., to avoid visiting certain parts of the tree. (The object referred to by names
#~ must be modified in place, using del or slice assignment.)
def my_visitor(my_stack, cur_dir, files_and_dirs):
"add files to the install list and accumulate files for the uninstall list"
global counter_dirs, counter_files, stack_of_visited
counter_dirs += 1
if just_print_flag:
print "here", my_dir
return
# first separate files
my_files = [x for x in files_and_dirs if os.path.isfile(cur_dir+os.sep+x)]
# and truncate dir name
my_dir = cur_dir[len(source_dir):]
if my_dir=="": my_dir = "\\."
# save it for uninstall
stack_of_visited.append( (my_files, my_dir) )
# build install list
if len(my_files):
print >> ih, inst_dir_tpl % my_dir
for f in my_files:
print >> ih, inst_file_tpl % (my_dir+os.sep+f)
counter_files += 1
print >> ih, " "
os.path.walk( source_dir, my_visitor, stack_of_visited)
ih.close()
print "Install list done"
print " ", counter_files, "files in", counter_dirs, "dirs"
stack_of_visited.reverse()
# Now build the uninstall list
for (my_files, my_dir) in stack_of_visited:
for f in my_files:
print >> uh, uninst_file_tpl % (my_dir+os.sep+f)
print >> uh, uninst_dir_tpl % my_dir
print >> uh, " "
# now close everything
uh.close()
print "Uninstall list done. Got to end.\n"