virtualenv/res/lib/lib_create_env.py
changeset 378 fb9c4686a903
parent 357 708517fbdffe
child 380 63dfc6dc3128
equal deleted inserted replaced
377:25304f0b98cc 378:fb9c4686a903
    41     'PIPELINE' : { 'setup': 'django-pipeline', 'url': 'https://github.com/cyberdelia/django-pipeline/archive/1.3.20.tar.gz', 'local': 'django-pipeline-1.3.20.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    41     'PIPELINE' : { 'setup': 'django-pipeline', 'url': 'https://github.com/cyberdelia/django-pipeline/archive/1.3.20.tar.gz', 'local': 'django-pipeline-1.3.20.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    42     'UNIDECODE' : { 'setup': 'unidecode', 'url': 'https://pypi.python.org/packages/source/U/Unidecode/Unidecode-0.04.14.tar.gz', 'local': 'Unidecode-0.04.14.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    42     'UNIDECODE' : { 'setup': 'unidecode', 'url': 'https://pypi.python.org/packages/source/U/Unidecode/Unidecode-0.04.14.tar.gz', 'local': 'Unidecode-0.04.14.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    43 }
    43 }
    44 
    44 
    45 if system_str == 'Windows':
    45 if system_str == 'Windows':
    46     
    46 
    47     size = 8 * struct.calcsize("P")
    47     size = 8 * struct.calcsize("P")
    48     if size==32:
    48     if size==32:
    49         mysqlres = "MySQL-python-1.2.3.win32-py2.7.exe"
    49         mysqlres = "MySQL-python-1.2.3.win32-py2.7.exe"
    50     else:
    50     else:
    51         mysqlres = "MySQL-python-1.2.3.win-amd64-py2.7.exe"
    51         mysqlres = "MySQL-python-1.2.3.win-amd64-py2.7.exe"
    52     
    52 
    53     URLS.update({
    53     URLS.update({
    54         'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.4.6.win32-py2.7-pg9.2.2-release.exe', 'local':"psycopg2-2.4.6.win32-py2.7-pg9.2.2-release.exe", 'install': {'method': 'install_psycopg2', 'option_str': None, 'dict_extra_env': None}},
    54         'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.4.6.win32-py2.7-pg9.2.2-release.exe', 'local':"psycopg2-2.4.6.win32-py2.7-pg9.2.2-release.exe", 'install': {'method': 'install_psycopg2', 'option_str': None, 'dict_extra_env': None}},
    55         'PIL': {'setup': 'pil', 'url': 'http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.7.exe', 'local':"PIL-1.1.7.win32-py2.7.exe", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    55         'PIL': {'setup': 'pil', 'url': 'http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.7.exe', 'local':"PIL-1.1.7.win32-py2.7.exe", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    56         'LXML': {'setup': 'lxml', 'url': 'http://pypi.python.org/packages/2.7/l/lxml/lxml-2.3-py2.7-win32.egg', 'local':"lxml-2.3-py2.7-win32.egg", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    56         'LXML': {'setup': 'lxml', 'url': 'http://pypi.python.org/packages/2.7/l/lxml/lxml-2.3-py2.7-win32.egg', 'local':"lxml-2.3-py2.7-win32.egg", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    57         'MYSQL': { 'setup': 'mysql-python', 'url': mysqlres, 'local': mysqlres, 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    57         'MYSQL': { 'setup': 'mysql-python', 'url': mysqlres, 'local': mysqlres, 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    58     })
    58     })
    59 else:
    59 else:
    60     if system_str == "Darwin":        
    60     if system_str == "Darwin":
    61         lxml_options = {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.9.1', 'LIBXSLT_VERSION': '1.1.28', 'LIBICONV_VERSION': '1.14'}
    61         lxml_options = {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.9.1', 'LIBXSLT_VERSION': '1.1.28', 'LIBICONV_VERSION': '1.14'}
    62         lxml_method = 'easy_install'
    62         lxml_method = 'easy_install'
    63         mysql_method = 'install_mysql'
    63         mysql_method = 'install_mysql'
    64     else:
    64     else:
    65         lxml_options = None
    65         lxml_options = None
    66         lxml_method = 'pip'
    66         lxml_method = 'pip'
    67         mysql_method = 'pip'
    67         mysql_method = 'pip'
    68 
    68 
    69     URLS.update({
    69     URLS.update({
    70         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.tar.gz', 'local':"psycopg2-2.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    70         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-8/psycopg2-2.8.4.tar.gz', 'local':"psycopg2-2.8.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    71         'PIL': {'setup': 'pil', 'url': 'https://github.com/python-imaging/Pillow/archive/2.3.0.tar.gz', 'local':"Pillow-2.3.0.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    71         'PIL': {'setup': 'pil', 'url': 'https://github.com/python-imaging/Pillow/archive/2.3.0.tar.gz', 'local':"Pillow-2.3.0.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    72         'LXML': {'setup': 'lxml', 'url':"lxml-3.2.1.tar.bz2", 'local':"lxml-3.2.1.tar.bz2", 'install': {'method': lxml_method, 'option_str': None, 'dict_extra_env': lxml_options}},
    72         'LXML': {'setup': 'lxml', 'url':"lxml-3.2.1.tar.bz2", 'local':"lxml-3.2.1.tar.bz2", 'install': {'method': lxml_method, 'option_str': None, 'dict_extra_env': lxml_options}},
    73         'MYSQL': { 'setup': 'mysql-python', 'url': 'http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.4b4/MySQL-python-1.2.4b4.tar.gz', 'local':"MySQL-python-1.2.4b4.tar.gz", 'install': {'method': mysql_method, 'option_str': None, 'dict_extra_env': None}},
    73         'MYSQL': { 'setup': 'mysql-python', 'url': 'http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.4b4/MySQL-python-1.2.4b4.tar.gz', 'local':"MySQL-python-1.2.4b4.tar.gz", 'install': {'method': mysql_method, 'option_str': None, 'dict_extra_env': None}},
    74     })
    74     })
    75     
    75 
    76 
    76 
    77 class ResourcesEnv(object):
    77 class ResourcesEnv(object):
    78 
    78 
    79     def __init__(self, src_base, run_base, urls, normal_installs):
    79     def __init__(self, src_base, run_base, urls, normal_installs):
    80         self.src_base = src_base
    80         self.src_base = src_base
    85 
    85 
    86     def get_src_base_path(self, fpath):
    86     def get_src_base_path(self, fpath):
    87         return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
    87         return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
    88 
    88 
    89     def get_run_res_base_path(self, fpath):
    89     def get_run_res_base_path(self, fpath):
    90         return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/")    
    90         return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/")
    91     
    91 
    92     def __add_package_def(self, key, dict):
    92     def __add_package_def(self, key, dict):
    93         self.URLS[key] = dict
    93         self.URLS[key] = dict
    94         
    94 
    95     def __init_url(self, urls):
    95     def __init_url(self, urls):
    96         for key, url_dict in urls.items():
    96         for key, url_dict in urls.items():
    97             url_dict_copy = url_dict.copy()
    97             url_dict_copy = url_dict.copy()
    98             if url_dict.get('install', {}).get('method','pip') == 'pip-req':
    98             if url_dict.get('install', {}).get('method','pip') == 'pip-req':
    99                 get_base_path = self.get_run_res_base_path
    99                 get_base_path = self.get_run_res_base_path
   100             else:
   100             else:
   101                 get_base_path = self.get_src_base_path                                
   101                 get_base_path = self.get_src_base_path
   102             if not url_dict['url'].startswith("http://"):
   102             if not url_dict['url'].startswith("http://"):
   103                 url_dict_copy['url'] = get_base_path(url_dict['url'])
   103                 url_dict_copy['url'] = get_base_path(url_dict['url'])
   104             url_dict_copy['local'] = get_base_path(url_dict['local'])
   104             url_dict_copy['local'] = get_base_path(url_dict['local'])
   105 
   105 
   106             self.__add_package_def(key, url_dict_copy )
   106             self.__add_package_def(key, url_dict_copy )
   109     logger.notify('Check directory %s' % dir)
   109     logger.notify('Check directory %s' % dir)
   110     if not os.path.exists(dir):
   110     if not os.path.exists(dir):
   111         logger.notify('Creating directory %s' % dir)
   111         logger.notify('Creating directory %s' % dir)
   112         os.makedirs(dir)
   112         os.makedirs(dir)
   113 
   113 
   114 def extend_parser(parser):    
   114 def extend_parser(parser):
   115     parser.add_option(
   115     parser.add_option(
   116         '--index-url',
   116         '--index-url',
   117         metavar='INDEX_URL',
   117         metavar='INDEX_URL',
   118         dest='index_url',
   118         dest='index_url',
   119         default='http://pypi.python.org/simple/',
   119         default='http://pypi.python.org/simple/',
   126     parser.add_option(
   126     parser.add_option(
   127         '--ignore-packages',
   127         '--ignore-packages',
   128         metavar='ignore_packages',
   128         metavar='ignore_packages',
   129         dest='ignore_packages',
   129         dest='ignore_packages',
   130         default=None,
   130         default=None,
   131         help='list of comma separated keys for package to ignore')    
   131         help='list of comma separated keys for package to ignore')
   132 
   132 
   133 def install_psycopg2(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
   133 def install_psycopg2(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
   134     psycopg2_src = os.path.join(src_dir,"psycopg2.zip")
   134     psycopg2_src = os.path.join(src_dir,"psycopg2.zip")
   135     shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src)
   135     shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src)
   136     #extract psycopg2
   136     #extract psycopg2
   137     zf = zipfile.ZipFile(psycopg2_src)
   137     zf = zipfile.ZipFile(psycopg2_src)
   138     psycopg2_base_path = os.path.join(src_dir,"psycopg2")
   138     psycopg2_base_path = os.path.join(src_dir,"psycopg2")
   139     zf.extractall(psycopg2_base_path)
   139     zf.extractall(psycopg2_base_path)
   140     zf.close()
   140     zf.close()
   141     
   141 
   142     psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
   142     psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
   143     shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
   143     shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
   144     shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.4.5-py2.7.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'site-packages')))
   144     shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.4.5-py2.7.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'site-packages')))
   145     
   145 
   146 
   146 
   147 def install_mysql(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
   147 def install_mysql(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
   148     
   148 
   149     args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]                
   149     args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]
   150     if option_str :
   150     if option_str :
   151         args.insert(4,option_str)
   151         args.insert(4,option_str)
   152     call_subprocess(args,
   152     call_subprocess(args,
   153             cwd=os.path.abspath(tmp_dir),
   153             cwd=os.path.abspath(tmp_dir),
   154             filter_stdout=filter_python_develop,
   154             filter_stdout=filter_python_develop,
   155             show_stdout=True,
   155             show_stdout=True,
   156             extra_env=extra_env)
   156             extra_env=extra_env)
   157 
   157 
   158     mysqlconfig_output = []
   158     mysqlconfig_output = []
   159     
   159 
   160     call_subprocess(['mysql_config', '--libmysqld-libs'],
   160     call_subprocess(['mysql_config', '--libmysqld-libs'],
   161         cwd=os.path.abspath(tmp_dir),
   161         cwd=os.path.abspath(tmp_dir),
   162         filter_stdout=lambda line: mysqlconfig_output.append(line),
   162         filter_stdout=lambda line: mysqlconfig_output.append(line),
   163         show_stdout=True)
   163         show_stdout=True)
   164         
   164 
   165     mysqlconfig_output = "".join(mysqlconfig_output)
   165     mysqlconfig_output = "".join(mysqlconfig_output)
   166     m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
   166     m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
   167     if m:
   167     if m:
   168         repdylibpath = m.group(1)
   168         repdylibpath = m.group(1)
   169     else:
   169     else:
   170         repdylibpath = '/usr/local/mysql/lib'
   170         repdylibpath = '/usr/local/mysql/lib'
   171         
   171 
   172     dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
   172     dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
   173     def key_func(s):
   173     def key_func(s):
   174         m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
   174         m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
   175         if m:
   175         if m:
   176             return int(m.group(1))
   176             return int(m.group(1))
   177         else:
   177         else:
   178             return sys.maxint
   178             return sys.maxint
   179     dyliblist.sort(key=key_func)
   179     dyliblist.sort(key=key_func)
   180     
   180 
   181     if dyliblist:
   181     if dyliblist:
   182         dylibpath = dyliblist[0]
   182         dylibpath = dyliblist[0]
   183     else:
   183     else:
   184         dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
   184         dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
   185         
   185 
   186     dylibname = os.path.basename(dylibpath)    
   186     dylibname = os.path.basename(dylibpath)
   187     sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
   187     sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
   188     
   188 
   189     call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
   189     call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
   190         cwd=os.path.abspath(tmp_dir),
   190         cwd=os.path.abspath(tmp_dir),
   191         filter_stdout=filter_python_develop,
   191         filter_stdout=filter_python_develop,
   192         show_stdout=True)
   192         show_stdout=True)
   193 
   193 
   194 
   194 
   195 def gen_install_comp_lib(lib_name, lib_key, configure_options=[]):
   195 def gen_install_comp_lib(lib_name, lib_key, configure_options=[]):
   196     
   196 
   197     def install_lib(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
   197     def install_lib(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
   198         lib_src = os.path.join(src_dir,lib_name+".tar.gz")
   198         lib_src = os.path.join(src_dir,lib_name+".tar.gz")
   199         logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src))
   199         logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src))
   200         shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
   200         shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
   201         tf = tarfile.open(lib_src,'r:gz')
   201         tf = tarfile.open(lib_src,'r:gz')
   202         lib_base_path = os.path.join(src_dir, lib_name) 
   202         lib_base_path = os.path.join(src_dir, lib_name)
   203         logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
   203         logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
   204         tf.extractall(lib_base_path)
   204         tf.extractall(lib_base_path)
   205         tf.close()
   205         tf.close()
   206         
   206 
   207         lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
   207         lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
   208     
   208 
   209         logger.notify(lib_name + " configure in " + lib_src_path)
   209         logger.notify(lib_name + " configure in " + lib_src_path)
   210         call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options,
   210         call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options,
   211                         cwd=os.path.abspath(lib_src_path),
   211                         cwd=os.path.abspath(lib_src_path),
   212                         filter_stdout=filter_python_develop,
   212                         filter_stdout=filter_python_develop,
   213                         show_stdout=True)
   213                         show_stdout=True)
   214         
   214 
   215         logger.notify(lib_name + " make in " + lib_src_path)
   215         logger.notify(lib_name + " make in " + lib_src_path)
   216         call_subprocess(['make'],
   216         call_subprocess(['make'],
   217                         cwd=os.path.abspath(lib_src_path),
   217                         cwd=os.path.abspath(lib_src_path),
   218                         filter_stdout=filter_python_develop,
   218                         filter_stdout=filter_python_develop,
   219                         show_stdout=True)
   219                         show_stdout=True)
   220     
   220 
   221         logger.notify(lib_name + "make install in " + lib_src_path)
   221         logger.notify(lib_name + "make install in " + lib_src_path)
   222         call_subprocess(['make', 'install'],
   222         call_subprocess(['make', 'install'],
   223                         cwd=os.path.abspath(lib_src_path),
   223                         cwd=os.path.abspath(lib_src_path),
   224                         filter_stdout=filter_python_develop,
   224                         filter_stdout=filter_python_develop,
   225                         show_stdout=True)
   225                         show_stdout=True)
   226     return install_lib
   226     return install_lib
   227 
   227 
   228 install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared'])
   228 install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared'])
   229 install_zlib = gen_install_comp_lib("zlib", "ZLIB", [])
   229 install_zlib = gen_install_comp_lib("zlib", "ZLIB", [])
   230     
   230 
   231 
   231 
   232 def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
   232 def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
   233     
   233 
   234     all_urls = URLS.copy()
   234     all_urls = URLS.copy()
   235     if urls is not None:
   235     if urls is not None:
   236         all_urls.update(urls)
   236         all_urls.update(urls)
   237         
   237 
   238     res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs)
   238     res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs)
   239 
   239 
   240     def filter_python_develop(line):
   240     def filter_python_develop(line):
   241         if not line.strip():
   241         if not line.strip():
   242             return Logger.DEBUG
   242             return Logger.DEBUG
   244                        'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
   244                        'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
   245                        'creating ', 'Copying ']:
   245                        'creating ', 'Copying ']:
   246             if line.startswith(prefix):
   246             if line.startswith(prefix):
   247                 return Logger.DEBUG
   247                 return Logger.DEBUG
   248         return Logger.NOTIFY
   248         return Logger.NOTIFY
   249     
   249 
   250     
   250 
   251     def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
   251     def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
   252         logger.notify("Install %s from %s with %s" % (key,res_path,method))
   252         logger.notify("Install %s from %s with %s" % (key,res_path,method))
   253         if method == 'pip':
   253         if method == 'pip':
   254             if sys.platform == 'win32':
   254             if sys.platform == 'win32':
   255                 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path]
   255                 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path]
   299                 args.insert(1,option_str)
   299                 args.insert(1,option_str)
   300             call_subprocess(args,
   300             call_subprocess(args,
   301                     cwd=os.path.abspath(tmp_dir),
   301                     cwd=os.path.abspath(tmp_dir),
   302                     filter_stdout=filter_python_develop,
   302                     filter_stdout=filter_python_develop,
   303                     show_stdout=True,
   303                     show_stdout=True,
   304                     extra_env=extra_env)            
   304                     extra_env=extra_env)
   305  
   305 
   306     
   306 
   307     def after_install(options, home_dir):
   307     def after_install(options, home_dir):
   308         
   308 
   309         global logger
   309         global logger
   310         
   310 
   311         verbosity = options.verbose - options.quiet
   311         verbosity = options.verbose - options.quiet
   312         logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
   312         logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
   313 
   313 
   314         
   314 
   315         home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
   315         home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
   316         base_dir = os.path.dirname(home_dir)
   316         base_dir = os.path.dirname(home_dir)
   317         src_dir = os.path.join(home_dir, 'src')
   317         src_dir = os.path.join(home_dir, 'src')
   318         tmp_dir = os.path.join(home_dir, 'tmp')
   318         tmp_dir = os.path.join(home_dir, 'tmp')
   319         ensure_dir(src_dir, logger)
   319         ensure_dir(src_dir, logger)
   320         ensure_dir(tmp_dir, logger)
   320         ensure_dir(tmp_dir, logger)
   321         system_str = platform.system()
   321         system_str = platform.system()
   322                 
   322 
   323         res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
   323         res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
   324         if res_source_key is None:
   324         if res_source_key is None:
   325             res_source_key = 'local'
   325             res_source_key = 'local'
   326         
   326 
   327         ignore_packages = []
   327         ignore_packages = []
   328         
   328 
   329         if system_str == 'Windows':
   329         if system_str == 'Windows':
   330             default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}}
   330             default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}}
   331         else:
   331         else:
   332             default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}}
   332             default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}}
   333             
   333 
   334         if options.ignore_packages :
   334         if options.ignore_packages :
   335             ignore_packages = options.ignore_packages.split(",")
   335             ignore_packages = options.ignore_packages.split(",")
   336         
   336 
   337         logger.indent += 2
   337         logger.indent += 2
   338         try:    
   338         try:
   339             for key in res_env.NORMAL_INSTALL:
   339             for key in res_env.NORMAL_INSTALL:
   340                 install_options = None
   340                 install_options = None
   341                 if isinstance(key, dict):
   341                 if isinstance(key, dict):
   342                     install_options = key.get('install', default_install_options)
   342                     install_options = key.get('install', default_install_options)
   343                     install_options['method'] = 'pip-req'
   343                     install_options['method'] = 'pip-req'
   352                 method = install_options.get('method', default_install_options['method'])
   352                 method = install_options.get('method', default_install_options['method'])
   353                 option_str = install_options.get('option_str', default_install_options['option_str'])
   353                 option_str = install_options.get('option_str', default_install_options['option_str'])
   354                 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
   354                 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
   355                 if not extra_env:
   355                 if not extra_env:
   356                     extra_env = {}
   356                     extra_env = {}
   357                     
   357 
   358                 if 'TMPDIR' not in extra_env:
   358                 if 'TMPDIR' not in extra_env:
   359                     extra_env['TMPDIR'] = os.path.abspath(tmp_dir)          
   359                     extra_env['TMPDIR'] = os.path.abspath(tmp_dir)
   360                 #isinstance(lst, (list, tuple))
   360                 #isinstance(lst, (list, tuple))
   361                 if key not in ignore_packages:
   361                 if key not in ignore_packages:
   362                     logger.notify("install %s with method %s" % (key, repr(method)))
   362                     logger.notify("install %s with method %s" % (key, repr(method)))
   363                     if callable(method):
   363                     if callable(method):
   364                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   364                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   365                     elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:  
   365                     elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:
   366                         globals()[method](option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   366                         globals()[method](option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   367                     else:
   367                     else:
   368                         normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
   368                         normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
   369                             
   369 
   370             logger.notify("Clear source dir")
   370             logger.notify("Clear source dir")
   371             shutil.rmtree(src_dir)
   371             shutil.rmtree(src_dir)
   372     
   372 
   373         finally:
   373         finally:
   374             logger.indent -= 2
   374             logger.indent -= 2
   375         script_dir = join(base_dir, bin_dir)
   375         script_dir = join(base_dir, bin_dir)
   376         logger.notify('Run "%s Package" to install new packages that provide builds'
   376         logger.notify('Run "%s Package" to install new packages that provide builds'
   377                       % join(script_dir, 'easy_install'))
   377                       % join(script_dir, 'easy_install'))
   378     
   378 
   379     def adjust_options(options, args):
   379     def adjust_options(options, args):
   380         if not options_to_add:
   380         if not options_to_add:
   381             return
   381             return
   382         for opt in options_to_add:
   382         for opt in options_to_add:
   383             test_opt = opt.split('=',1)[0]
   383             test_opt = opt.split('=',1)[0]