commodconverter
 All Classes Namespaces Files Functions Variables Macros
install.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import os
3 import sys
4 import subprocess
5 import shutil
6 
7 try:
8  import argparse as ap
9 except ImportError:
10  import pyne._argparse as ap
11 
12 absexpanduser = lambda x: os.path.abspath(os.path.expanduser(x))
13 
14 
15 def check_windows_cmake(cmake_cmd):
16  if os.name == 'nt':
17  files_on_path = set()
18  for p in os.environ['PATH'].split(';')[::-1]:
19  if os.path.exists(p):
20  files_on_path.update(os.listdir(p))
21  if 'cl.exe' in files_on_path:
22  pass
23  elif 'sh.exe' in files_on_path:
24  cmake_cmd += ['-G "MSYS Makefiles"']
25  elif 'gcc.exe' in files_on_path:
26  cmake_cmd += ['-G "MinGW Makefiles"']
27  cmake_cmd = ' '.join(cmake_cmd)
28 
29 
30 def install(args):
31  if not os.path.exists(args.build_dir):
32  os.mkdir(args.build_dir)
33  elif args.clean_build:
34  shutil.rmtree(args.build_dir)
35  os.mkdir(args.build_dir)
36 
37  root_dir = os.path.split(__file__)[0]
38  makefile = os.path.join(args.build_dir, 'Makefile')
39 
40  if not os.path.exists(makefile):
41  rtn = subprocess.call(['which', 'cmake'], shell=(os.name == 'nt'))
42  if rtn != 0:
43  sys.exit("CMake could not be found, "
44  "please install CMake before developing Cyclus.")
45  cmake_cmd = ['cmake', os.path.abspath(root_dir)]
46  if args.prefix:
47  cmake_cmd += ['-DCMAKE_INSTALL_PREFIX=' +
48  absexpanduser(args.prefix)]
49  if args.cmake_prefix_path:
50  cmake_cmd += ['-DCMAKE_PREFIX_PATH=' +
51  absexpanduser(args.cmake_prefix_path)]
52  if args.coin_root:
53  cmake_cmd += ['-DCOIN_ROOT_DIR=' + absexpanduser(args.coin_root)]
54  if args.boost_root:
55  cmake_cmd += ['-DBOOST_ROOT=' + absexpanduser(args.boost_root)]
56  if args.build_type:
57  cmake_cmd += ['-DCMAKE_BUILD_TYPE=' + args.build_type]
58  check_windows_cmake(cmake_cmd)
59  rtn = subprocess.check_call(cmake_cmd, cwd=args.build_dir,
60  shell=(os.name == 'nt'))
61 
62  make_cmd = ['make']
63  if args.threads:
64  make_cmd += ['-j' + str(args.threads)]
65  rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
66  shell=(os.name == 'nt'))
67 
68  if args.test:
69  make_cmd += ['test']
70  elif not args.build_only:
71  make_cmd += ['install']
72 
73  rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
74  shell=(os.name == 'nt'))
75 
76 def uninstall(args):
77  makefile = os.path.join(args.build_dir, 'Makefile')
78  if not os.path.exists(args.build_dir) or not os.path.exists(makefile):
79  sys.exist("May not uninstall Cyclus since it has not yet been built.")
80  rtn = subprocess.check_call(['make', 'uninstall'], cwd=args.build_dir,
81  shell=(os.name == 'nt'))
82 
83 
84 def main():
85  localdir = absexpanduser('~/.local')
86 
87  description = "An installation helper script. " +\
88  "For more information, please see fuelcycle.org."
89  parser = ap.ArgumentParser(description=description)
90 
91  build_dir = 'where to place the build directory'
92  parser.add_argument('--build_dir', help=build_dir, default='build')
93 
94  uninst = 'uninstall'
95  parser.add_argument('--uninstall', action='store_true', help=uninst, default=False)
96 
97  clean = 'attempt to remove the build directory before building'
98  parser.add_argument('--clean-build', action='store_true', help=clean)
99 
100  threads = "the number of threads to use in the make step"
101  parser.add_argument('-j', '--threads', type=int, help=threads)
102 
103  prefix = "the relative path to the installation directory"
104  parser.add_argument('--prefix', help=prefix, default=localdir)
105 
106  build_only = 'only build the package, do not install'
107  parser.add_argument('--build-only', action='store_true', help=build_only)
108 
109  test = 'run tests after building'
110  parser.add_argument('--test', action='store_true', help=test)
111 
112  coin = "the relative path to the Coin-OR libraries directory"
113  parser.add_argument('--coin_root', help=coin)
114 
115  boost = "the relative path to the Boost libraries directory"
116  parser.add_argument('--boost_root', help=boost)
117 
118  cmake_prefix_path = "the cmake prefix path for use with FIND_PACKAGE, " + \
119  "FIND_PATH, FIND_PROGRAM, or FIND_LIBRARY macros"
120  parser.add_argument('--cmake_prefix_path', help=cmake_prefix_path)
121 
122  build_type = "the CMAKE_BUILD_TYPE"
123  parser.add_argument('--build_type', help=build_type)
124 
125  args = parser.parse_args()
126  if args.uninstall:
127  uninstall(args)
128  else:
129  install(args)
130 
131 if __name__ == "__main__":
132  main()
def main
Definition: install.py:84
tuple absexpanduser
Definition: install.py:12
def check_windows_cmake
Definition: install.py:15
def uninstall
Definition: install.py:76
def install
Definition: install.py:30