nx_client_installer.py 2.23 KB
Newer Older
1
#!/usr/bin/env python
2 3
# -*- coding: utf-8 -*-

4
"""
5
NX Client for Windows installer
6 7 8
Checks whether NX Client for Windows is installed in the system, the
classes used for this process are used for other operations too.
"""
9

10 11 12 13
import os
import argparse
import subprocess
import time
14
import windowsclasses
15

16 17 18 19 20 21 22 23 24

def parse_arguments():
    """
    Argument parser, based on argparse module

    Keyword arguments:
    @return args -- arguments given by console
    """
    parser = argparse.ArgumentParser()
25 26
    if windowsclasses.DecideArchitecture.Is64Windows():
        local_default = (windowsclasses.DecideArchitecture.GetProgramFiles64()
27
                         + "\\CIRCLE\\")
28
    else:
29
        local_default = (windowsclasses.DecideArchitecture.GetProgramFiles32()
30 31
                         + "\\CIRCLE\\")
    if (not os.path.exists(local_default[:-1])
32
            and os.path.exists(os.environ['APPDATA']+"\\CIRCLE")):
33
        local_default = os.environ['APPDATA']+"\\CIRCLE\\"
34 35 36 37 38
    parser.add_argument(
        "-l", "--location",
        help="Location of the client files in the system",
        default=local_default)
    args = parser.parse_args()
39 40
    return args

41

42 43 44 45 46
def main():
    try:
        nx_install_location = None
        while nx_install_location is None:
            print "Checking whether NX Client for Windows is installed"
47
            handler = windowsclasses.RegistryHandler()
48
            try:
49
                nx_install_location = handler.get_key_value(
50 51
                    "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
                    + "Uninstall\\nxclient_is1",
52 53
                    "InstallLocation", "key")
                print ("NX Client for Windows is found at "
54
                       "'%s'" % nx_install_location)
55 56
                process = subprocess.Popen(
                    "%s\\nxclient.exe" % nx_install_location)
57 58 59 60 61
                time.sleep(2)
                process.terminate()
            except:
                print "NX Client for Windows isn't installed on the system."
                print "\tCommencing the install"
62
                subprocess.Popen(os.path.dirname(
63 64
                    os.path.realpath(__file__))
                    + "\\nxclient-3.5.0-9.exe").wait()
65 66
    except:
        pass
67

68
if __name__ == "__main__":
69
    main()