1#!/usr/local/bin/python3.8
2"""Script to create the Windows installer for BLAST command line applications"""
3# $Id: make_win.py 595505 2019-10-22 21:45:54Z camacho $
4#
5# Author: Christiam camacho
6
7from __future__ import print_function
8import os, sys, os.path
9import shutil
10from optparse import OptionParser
11SCRIPT_DIR = os.path.dirname(os.path.abspath(sys.argv[0]))
12sys.path.append(os.path.join(SCRIPT_DIR, ".."))
13from blast_utils import safe_exec, update_blast_version
14
15VERBOSE = False
16
17# NSIS Configuration file
18NSIS_CONFIG = os.path.join(SCRIPT_DIR, "ncbi-blast.nsi")
19
20def extract_installer():
21    """Extract name of the installer file from NSIS configuration file"""
22    from fileinput import FileInput
23
24    retval = "unknown"
25    for line in FileInput(NSIS_CONFIG):
26        if line.find("OutFile") != -1:
27            retval = line.split()[1]
28            return retval.strip('"')
29
30def main():
31    """ Creates NSIS installer for BLAST command line binaries """
32    global VERBOSE #IGNORE:W0603
33    parser = OptionParser("%prog <blast_version> <installation directory>")
34    parser.add_option("-v", "--verbose", action="store_true", default=False,
35                      help="Show verbose output", dest="VERBOSE")
36    options, args = parser.parse_args()
37    if len(args) != 2:
38        parser.error("Incorrect number of arguments")
39        return 1
40
41    blast_version, installdir = args
42    VERBOSE = options.VERBOSE
43
44    apps = [ "blastn.exe",
45             "blastp.exe",
46             "blastx.exe",
47             "tblastx.exe",
48             "tblastn.exe",
49             "rpsblast.exe",
50             "rpstblastn.exe",
51             "psiblast.exe",
52             "blastdbcmd.exe",
53             "makeblastdb.exe",
54             "makembindex.exe",
55             "makeprofiledb.exe",
56             "blastdb_aliastool.exe",
57             "segmasker.exe",
58             "dustmasker.exe",
59             "windowmasker.exe",
60             "convert2blastmask.exe",
61             "blastdbcheck.exe",
62             "blast_formatter.exe",
63             "deltablast.exe",
64             "legacy_blast.pl",
65             "update_blastdb.pl",
66             "cleanup-blastdb-volumes.py",
67             "get_species_taxids.sh"
68             ]
69
70    cwd = os.getcwd()
71    for app in apps:
72        app = os.path.join(installdir, "bin", app)
73        if VERBOSE:
74            print("Copying", app, "to", cwd)
75        shutil.copy(app, cwd)
76
77    dll = os.path.join('\\\\', 'snowman', 'win-coremake', 'Lib', 'ThirdParty', 'nghttp2', 'vs2017.64', '1.33.0', 'bin', 'ReleaseDLL', 'nghttp2.dll')
78    shutil.copy(dll, cwd)
79
80
81    update_blast_version(NSIS_CONFIG, blast_version)
82    # Copy necessary files to the current working directory
83    shutil.copy(NSIS_CONFIG, cwd)
84    license_file = os.path.join(SCRIPT_DIR, "..", "..", "LICENSE")
85    shutil.copy(license_file, cwd)
86
87    f = open("README.txt", "w")
88    f.write("The user manual is available in http://www.ncbi.nlm.nih.gov/books/NBK279690\n")
89    f.write("Release notes are available in http://www.ncbi.nlm.nih.gov/books/NBK131777\n")
90    f.close()
91
92    for aux_file in ("EnvVarUpdate.nsh", "ncbilogo.ico"):
93        src = os.path.join(SCRIPT_DIR, aux_file)
94        if VERBOSE:
95            print("Copying", src, "to", cwd)
96        shutil.copy(src, cwd)
97
98    # makensis is in the path of the script courtesy of the release framework
99    cmd = "makensis " + os.path.basename(NSIS_CONFIG)
100    safe_exec(cmd)
101
102    installer_dir = os.path.join(installdir, "installer")
103    if not os.path.exists(installer_dir):
104        os.makedirs(installer_dir)
105
106    installer = extract_installer()
107    shutil.copy(installer, installer_dir)
108
109if __name__ == "__main__":
110    sys.exit(main())
111
112