File: make_uninstall_nsh.py

package info (click to toggle)
spring 98.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,928 kB
  • ctags: 60,665
  • sloc: cpp: 356,167; ansic: 39,434; python: 12,228; java: 12,203; awk: 5,856; sh: 1,719; xml: 997; perl: 405; php: 253; objc: 194; makefile: 72; sed: 2
file content (81 lines) | stat: -rwxr-xr-x 2,002 bytes parent folder | download
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
#!/usr/bin/env python
#
# this scripts creates an nullsoft script that removes files for a given .7z archive
# python {this_script}.py > installer/sections/luaui.nsh
#
# @param baseDir for example: "/home/userX/src/spring"
#


import subprocess, sys

def uniquify(list):
    checked = []
    for e in list:
        if e not in checked:
            checked.append(e)
    return checked

def toWinPath(path):
	return path.replace('/', '\\')

def parseArgv(argv):
	prefix=""
	config = argv.split(":")
	if len(config)==2:
		prefix=config[1]
	return config[0], prefix

def getContents(archives):
	"""
		parses the output of 7z for file and returns a list of files/paths found inside it
	"""
	paths=[]
	files=[]
	for archive in archives:
		path, prefix=parseArgv(archive)
		output=str(subprocess.check_output(["7z","l","-slt", path]))
		lines=output.split("\n")
		if (len(lines)==1): # python 3 hack
			lines = output.split("\\n")
		for line in lines:
			isdir=False
			if line.startswith('Path = '):
				path=line[7:]
			if line.startswith('Attributes = '):
				if line[13]=='D':
					paths.append(toWinPath(prefix+path))
				else:
					files.append(toWinPath(prefix+path))

	return uniquify(files), uniquify(paths)

def writeNsh(files, paths, argv):
	"""
		writes uninstall cmds for files + paths into the file nsh
	"""
	print("; This file is automaticly created, don't edit it!")
	command="make_uninstall_nsh.py"
	for arg in argv:
		command=command+" " +arg

	print("; created with: %s" % command)
	print(";")
	for file in files:
		print('Delete "$INSTDIR\%s"'%(file))
	for path in paths:
		print('RmDir "$INSTDIR\%s"'%(path))
	for archive in argv:
		path, prefix = parseArgv(archive)
		if prefix!="":
			#strip backslash at the end
			if prefix.endswith("\\"):
				prefix=prefix[:-1]
			print('RmDir "$INSTDIR\%s"'%(prefix))

if len(sys.argv)<2:
	print("Usage %s [<7z archive>[:<subpath to extract]]+"%(sys.argv[0]))
else:
	files, paths = getContents(sys.argv[1:])
	writeNsh(files, paths, sys.argv[1:])