1823b8294SYaroslav Brustinov#!/router/bin/python
2823b8294SYaroslav Brustinovimport sys, site
3823b8294SYaroslav Brustinovimport platform, os
4420216e5SHanoh Haimimport pprint
5823b8294SYaroslav Brustinov
6823b8294SYaroslav BrustinovCURRENT_PATH        = os.path.dirname(os.path.realpath(__file__)) # alternate use  with: os.getcwd()
7823b8294SYaroslav BrustinovTREX_PATH           = os.getenv('TREX_UNDER_TEST')     # path to <trex-core>/scripts directory, env. variable TREX_UNDER_TEST should override it.
8823b8294SYaroslav Brustinovif not TREX_PATH or not os.path.isfile('%s/trex_daemon_server' % TREX_PATH):
9823b8294SYaroslav Brustinov    TREX_PATH       = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir, os.pardir))
10823b8294SYaroslav BrustinovPATH_TO_PYTHON_LIB  = os.path.abspath(os.path.join(TREX_PATH, 'external_libs'))
11823b8294SYaroslav BrustinovPATH_TO_CTRL_PLANE  = os.path.abspath(os.path.join(TREX_PATH, 'automation', 'trex_control_plane'))
12b91c216dSYaroslav BrustinovPATH_STF_API        = os.path.abspath(os.path.join(PATH_TO_CTRL_PLANE, 'stf'))
130f03cc46SYaroslav BrustinovPATH_STL_API        = os.path.abspath(os.path.join(PATH_TO_CTRL_PLANE, 'stl'))
14823b8294SYaroslav Brustinov
1589a2be82Simarom
1689a2be82SimaromNIGHTLY_MODULES = [ {'name': 'ansi2html'},
1789a2be82Simarom                    {'name': 'enum34-1.0.4'},
1889a2be82Simarom                    {'name': 'rednose-0.4.1'},
1989a2be82Simarom                    {'name': 'progressbar-2.2'},
2089a2be82Simarom                    {'name': 'termstyle'},
21420216e5SHanoh Haim                    {'name': 'urllib3'},
22420216e5SHanoh Haim                    {'name': 'elasticsearch'},
23420216e5SHanoh Haim                    {'name': 'requests'},
2489a2be82Simarom                    {'name': 'pyyaml-3.11', 'py-dep': True},
25420216e5SHanoh Haim                    {'name': 'nose-1.3.4', 'py-dep': True},
26823b8294SYaroslav Brustinov                    ]
27823b8294SYaroslav Brustinov
2889a2be82Simarom
29cfcbe7a0SYaroslav Brustinovdef generate_module_path (module, is_python3, is_64bit, is_ucs2):
3089a2be82Simarom    platform_path = [module['name']]
3189a2be82Simarom
3289a2be82Simarom    if module.get('py-dep'):
3389a2be82Simarom        platform_path.append('python3' if is_python3 else 'python2')
3489a2be82Simarom
3589a2be82Simarom    if module.get('arch-dep'):
36cfcbe7a0SYaroslav Brustinov        platform_path.append('ucs2' if is_ucs2 else 'ucs4')
3789a2be82Simarom        platform_path.append('64bit' if is_64bit else '32bit')
3889a2be82Simarom
3989a2be82Simarom    return os.path.normcase(os.path.join(PATH_TO_PYTHON_LIB, *platform_path))
4089a2be82Simarom
4189a2be82Simarom
4289a2be82Simaromdef import_module_list(modules_list):
4389a2be82Simarom
4489a2be82Simarom    # platform data
4589a2be82Simarom    is_64bit   = platform.architecture()[0] == '64bit'
4689a2be82Simarom    is_python3 = (sys.version_info >= (3, 0))
47cfcbe7a0SYaroslav Brustinov    is_ucs2    = (sys.maxunicode == 65535)
4889a2be82Simarom
4989a2be82Simarom    # regular modules
5089a2be82Simarom    for p in modules_list:
51cfcbe7a0SYaroslav Brustinov        full_path = generate_module_path(p, is_python3, is_64bit, is_ucs2)
5289a2be82Simarom
5389a2be82Simarom        if not os.path.exists(full_path):
5489a2be82Simarom            print("Unable to find required module library: '{0}'".format(p['name']))
5589a2be82Simarom            print("Please provide the correct path using PATH_TO_PYTHON_LIB variable")
5689a2be82Simarom            print("current path used: '{0}'".format(full_path))
5789a2be82Simarom            exit(0)
58cfcbe7a0SYaroslav Brustinov        if full_path not in sys.path:
59cfcbe7a0SYaroslav Brustinov            sys.path.insert(1, full_path)
6089a2be82Simarom
6189a2be82Simarom
62823b8294SYaroslav Brustinovdef import_nightly_modules ():
63b91c216dSYaroslav Brustinov    #sys.path.append(PATH_TO_CTRL_PLANE)
64cfcbe7a0SYaroslav Brustinov    for path in (TREX_PATH, PATH_STL_API, PATH_STF_API):
65cfcbe7a0SYaroslav Brustinov        if path not in sys.path:
66cfcbe7a0SYaroslav Brustinov            sys.path.append(path)
67823b8294SYaroslav Brustinov    import_module_list(NIGHTLY_MODULES)
68420216e5SHanoh Haim    #pprint.pprint(sys.path)
69823b8294SYaroslav Brustinov
70823b8294SYaroslav Brustinov
71823b8294SYaroslav Brustinovimport_nightly_modules()
72823b8294SYaroslav Brustinov
73823b8294SYaroslav Brustinov
74823b8294SYaroslav Brustinovif __name__ == "__main__":
75823b8294SYaroslav Brustinov    pass
76