Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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