Attachment 'manual_install.py'

Download

   1 # Nick Hilton
   2 # 2013-10-05
   3 #
   4 # Installs a Python build from the Visual Studio directory to target directory
   5 #
   6 
   7 import glob
   8 import os
   9 import shutil
  10 import sys
  11 
  12 import os.path
  13 
  14 from os.path import dirname
  15 from os.path import abspath
  16 
  17 #------------------------------------------------------------------------------
  18 # Globals
  19 
  20 EXTERNALS_DIR = dirname(abspath(__file__))
  21 PYTHON_DIR = "Python-2.7.5"
  22 TCLTK_DIR = "tcltk64"
  23 
  24 DST_DIR = r"C:\Python27_d"
  25 CPU = "amd64"
  26 
  27 
  28 def make_directory(d):
  29     if not os.path.exists(d):
  30         print "Creating directory: %s" % repr(d)
  31         os.makedirs(d)
  32 
  33 
  34 def copy_files(filelist, dst):
  35 
  36     for f in filelist:
  37 
  38         f = f.replace('/', '\\')
  39 
  40         f, ext = os.path.splitext(f)
  41 
  42         for ext_ in [ext, '_d' + ext]:
  43 
  44             f_ = f + ext_
  45 
  46             if os.path.isfile(f_):
  47                 print "Copying %s --> %s" % (f_, dst)
  48                 shutil.copy(f_, dst)
  49 
  50 def copy_directory(src_dir, dst_dir):
  51 
  52     if not os.path.isdir(src_dir):
  53         raise RuntimeError("Oops, couldn't find path: %s" % repr(src_dir))
  54 
  55     if os.path.isdir(dst_dir):
  56         shutil.rmtree(dst_dir)
  57 
  58     print "Copying %s --> %s" % (src_dir, dst_dir)
  59     shutil.copytree(src_dir, dst_dir)
  60 
  61 
  62 if __name__ == "__main__":
  63 
  64     print "EXTERNALS_DIR =", EXTERNALS_DIR
  65     print "PYTHON_DIR =", PYTHON_DIR
  66     print "TCLTK_DIR =", TCLTK_DIR
  67 
  68     for p in [EXTERNALS_DIR, PYTHON_DIR, TCLTK_DIR]:
  69 
  70         if not os.path.isdir(p):
  71             raise RuntimeError("Oops, could not find path: %s" % repr(p))
  72 
  73     #--------------------------------------------------------------------------
  74     # Create destination directory
  75 
  76     if DST_DIR is None:
  77 
  78         DST_DIR = r"C:\Python27_d"
  79 
  80         d = raw_input("Enter destination directory [%s]: " % repr(DST_DIR))
  81 
  82         if len(d) > 0:
  83             DST_DIR = d
  84 
  85     print "DST_DIR =", DST_DIR
  86 
  87     if os.path.isdir(DST_DIR):
  88 
  89         choice = raw_input("Destination directory exists, continue? ").upper()
  90 
  91         if choice not in ['Y', 'YES']:
  92             print "Aborting ..."
  93             exit(1)
  94 
  95     make_directory(DST_DIR)
  96 
  97     #--------------------------------------------------------------------------
  98     # copy python.exe
  99 
 100     SRC_DIR = os.path.join(EXTERNALS_DIR, PYTHON_DIR)
 101 
 102     PCBUILD_DIR = "{SRC_DIR}/PCbuild/{CPU}".format(SRC_DIR = SRC_DIR, CPU = CPU)
 103 
 104     filelist = """
 105         {py_prefix}/python.exe
 106         {py_prefix}/pythonw.exe
 107         {py_prefix}/python27.dll
 108     """.format(py_prefix = PCBUILD_DIR).split()
 109 
 110     copy_files(filelist, DST_DIR)
 111 
 112 
 113     #--------------------------------------------------------------------------
 114     # copy DLLs
 115 
 116     src_list = glob.glob(PCBUILD_DIR + r"\*.pyd")
 117 
 118     dst_dir = os.path.join(DST_DIR, "DLLs")
 119 
 120     make_directory(dst_dir)
 121 
 122     copy_files(src_list, dst_dir)
 123 
 124     # Tcl dlls
 125     src_list = glob.glob(TCLTK_DIR + r"\bin\*.dll")
 126 
 127     copy_files(src_list, dst_dir)
 128 
 129     #--------------------------------------------------------------------------
 130     # copy include
 131 
 132     src_dir = os.path.join(SRC_DIR, "Include")
 133     dst_dir = os.path.join(DST_DIR, "include")
 134 
 135     copy_directory(src_dir, dst_dir)
 136 
 137     src_list = ["{SRC_DIR}/PC/pyconfig.h".format(SRC_DIR = SRC_DIR)]
 138 
 139     copy_files(src_list, dst_dir)
 140 
 141     #--------------------------------------------------------------------------
 142     # copy Lib
 143 
 144     src_dir = os.path.join(SRC_DIR, "Lib")
 145     dst_dir = os.path.join(DST_DIR, "Lib")
 146 
 147     copy_directory(src_dir, dst_dir)
 148 
 149     #--------------------------------------------------------------------------
 150     # copy libs
 151 
 152     src_list = glob.glob(PCBUILD_DIR + r"\*.lib")
 153 
 154     dst_dir = os.path.join(DST_DIR, "libs")
 155 
 156     make_directory(dst_dir)
 157 
 158     copy_files(src_list, dst_dir)
 159 
 160     #--------------------------------------------------------------------------
 161     # Scripts dir
 162 
 163     make_directory(os.path.join(DST_DIR, "Scripts"))
 164 
 165     #--------------------------------------------------------------------------
 166     # tcl
 167 
 168     src_dir = os.path.join(EXTERNALS_DIR, TCLTK_DIR, "lib")
 169     dst_dir = os.path.join(DST_DIR, "tcl")
 170 
 171     copy_directory(src_dir, dst_dir)
 172 
 173 
 174     print "All done!"

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2013-10-05 19:50:53, 48.2 KB) [[attachment:PCbuild_patches.txt]]
  • [get | view] (2013-10-06 00:57:08, 4.2 KB) [[attachment:manual_install.py]]
  • [get | view] (2013-10-05 21:46:11, 369.0 KB) [[attachment:openssl-headers-1.0.1e.zip]]
  • [get | view] (2013-10-06 21:33:42, 20.8 KB) [[attachment:plot.png]]
  • [get | view] (2013-10-05 20:00:49, 9.9 KB) [[attachment:python-2.7.5-amd64-pcbuild.zip]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

Unable to edit the page? See the FrontPage for instructions.