| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import os, tempfile |
| 6 |
|
| 7 |
GTK_PATH = "../gtk-mini/" |
| 8 |
GWYDDION_PATH = "inst/" |
| 9 |
GWYDDION_CONFIG_H = "config.h" |
| 10 |
GWYDDION_NSI_TEMPLATE = "utils/gwyddion3.nsi.template" |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
def get_version(): |
| 16 |
config_file = file(GWYDDION_CONFIG_H, "r") |
| 17 |
l = config_file.readline() |
| 18 |
while l != "": |
| 19 |
if l.startswith("#define PACKAGE_VERSION"): |
| 20 |
return l.split('"')[1] |
| 21 |
l = config_file.readline() |
| 22 |
print "Warning: Cannot determine version." |
| 23 |
return "" |
| 24 |
|
| 25 |
ignore_dirs = ['devel-docs', 'gone'] |
| 26 |
ignore_files = ['pygwy.dll'] |
| 27 |
|
| 28 |
def list_of_files(arg, dirname, fnames): |
| 29 |
print dirname |
| 30 |
for c in dirname.split('\\'): |
| 31 |
if c.lower() in ignore_dirs: |
| 32 |
return |
| 33 |
arg.append(dirname) |
| 34 |
for fname in fnames: |
| 35 |
if fname.lower() in ignore_dirs: |
| 36 |
continue |
| 37 |
if fname.lower() in ignore_files: |
| 38 |
continue |
| 39 |
arg.append(create_path(dirname, fname)) |
| 40 |
|
| 41 |
def create_path(dir, filename): |
| 42 |
if dir == "": |
| 43 |
return filename |
| 44 |
if dir.endswith('\\'): |
| 45 |
return dir + filename |
| 46 |
return dir + '\\' + filename |
| 47 |
|
| 48 |
def get_install_line(filename, prefix): |
| 49 |
if os.path.isdir(filename): |
| 50 |
return ' CreateDirectory "$INSTDIR\\'+filename.replace(prefix, "", 1)+'"\n' |
| 51 |
else: |
| 52 |
return ' File "/oname='+filename.replace(prefix, "", 1)+'" "'+filename+'"\n' |
| 53 |
|
| 54 |
def get_uninstall_line(filename, prefix): |
| 55 |
if os.path.isdir(filename): |
| 56 |
return ' RmDir "$INSTDIR\\'+filename.replace(prefix, "", 1)+'"\n' |
| 57 |
else: |
| 58 |
return ' Delete "$INSTDIR\\'+filename.replace(prefix, "", 1)+'"\n' |
| 59 |
|
| 60 |
gtk_files = [] |
| 61 |
gwyddion_files = [] |
| 62 |
|
| 63 |
os.path.walk(GTK_PATH, list_of_files, gtk_files) |
| 64 |
os.path.walk(GWYDDION_PATH, list_of_files, gwyddion_files) |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
gtk_install_files = "" |
| 69 |
for f in gtk_files: |
| 70 |
gtk_install_files += get_install_line(f, GTK_PATH) |
| 71 |
|
| 72 |
gtk_uninstall_files = "" |
| 73 |
gtk_files.reverse() |
| 74 |
for f in gtk_files: |
| 75 |
gtk_uninstall_files += get_uninstall_line(f, GTK_PATH) |
| 76 |
|
| 77 |
gwyddion_install_files = "" |
| 78 |
for f in gwyddion_files: |
| 79 |
gwyddion_install_files += get_install_line(f, GWYDDION_PATH) |
| 80 |
|
| 81 |
gwyddion_uninstall_files = "" |
| 82 |
gwyddion_files.reverse() |
| 83 |
for f in gwyddion_files: |
| 84 |
gwyddion_uninstall_files += get_uninstall_line(f, GWYDDION_PATH) |
| 85 |
|
| 86 |
|
| 87 |
nsi_template = file(GWYDDION_NSI_TEMPLATE ,"r") |
| 88 |
content_nsi = nsi_template.read() |
| 89 |
nsi_template.close() |
| 90 |
|
| 91 |
content_nsi = content_nsi.replace("%VERSION%", get_version()) |
| 92 |
|
| 93 |
content_nsi = content_nsi.replace("%GWYDDION_INSTALL%", gwyddion_install_files) |
| 94 |
content_nsi = content_nsi.replace("%GTK_INSTALL%", gtk_install_files) |
| 95 |
content_nsi = content_nsi.replace("%GWYDDION_UNINSTALL%", gwyddion_uninstall_files) |
| 96 |
content_nsi = content_nsi.replace("%GTK_UNINSTALL%", gtk_uninstall_files) |
| 97 |
content_nsi = content_nsi.replace("%PYGWY_INSTALL%", ' File "'+GWYDDION_PATH+'modules\\pygwy.dll"') |
| 98 |
content_nsi = content_nsi.replace("%PYGWY_UNINSTALL%", ' Delete "$INSTDIR\\modules\\pygwy.dll"') |
| 99 |
|
| 100 |
nsi = file("gwyddion3.nsi", "w") |
| 101 |
nsi.write(content_nsi) |
| 102 |
nsi.close() |