virtualenv/res/lib/lib_create_env.py
changeset 295 bd0742dc064f
parent 283 d6bc9a2cc131
equal deleted inserted replaced
294:1b883014f45a 295:bd0742dc064f
    31     'WSGIREF' : {'setup':'wsgiref', 'url':'http://pypi.python.org/packages/source/w/wsgiref/wsgiref-0.1.2.zip', 'local': 'wsgiref-0.1.2.zip', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    31     'WSGIREF' : {'setup':'wsgiref', 'url':'http://pypi.python.org/packages/source/w/wsgiref/wsgiref-0.1.2.zip', 'local': 'wsgiref-0.1.2.zip', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    32     'SIMPLEJSON': {'setup': 'simplejson', 'url':'https://github.com/simplejson/simplejson/archive/v3.3.3.tar.gz', 'local':"simplejson-3.3.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    32     'SIMPLEJSON': {'setup': 'simplejson', 'url':'https://github.com/simplejson/simplejson/archive/v3.3.3.tar.gz', 'local':"simplejson-3.3.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    33     'PYTZ' : {'setup': 'pytz', 'url':'https://pypi.python.org/packages/source/p/pytz/pytz-2014.2.tar.gz', 'local' : 'pytz-2014.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    33     'PYTZ' : {'setup': 'pytz', 'url':'https://pypi.python.org/packages/source/p/pytz/pytz-2014.2.tar.gz', 'local' : 'pytz-2014.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    34     # dependencies for Tastypie : mimeparse>=0.1.3, python-dateutil>=2.1, lxml, PyYAML (not necessary but we never know), python-digest
    34     # dependencies for Tastypie : mimeparse>=0.1.3, python-dateutil>=2.1, lxml, PyYAML (not necessary but we never know), python-digest
    35     'MIMEPARSE' : {'setup':'mimeparse', 'url':'https://pypi.python.org/packages/source/p/python-mimeparse/python-mimeparse-0.1.4.tar.gz', 'local': 'python-mimeparse-0.1.4.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    35     'MIMEPARSE' : {'setup':'mimeparse', 'url':'https://pypi.python.org/packages/source/p/python-mimeparse/python-mimeparse-0.1.4.tar.gz', 'local': 'python-mimeparse-0.1.4.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    36     'SIX' : {'setup':'six', 'url':'https://pypi.python.org/packages/source/s/six/six-1.6.1.tar.gz', 'local': 'six-1.6.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},    
    36     'SIX' : {'setup':'six', 'url':'https://pypi.python.org/packages/source/s/six/six-1.6.1.tar.gz', 'local': 'six-1.6.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    37     'PYTHON-DATEUTIL' : {'setup':'python-dateutil', 'url':'https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.2.tar.gz', 'local': 'python-dateutil-2.2.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    37     'PYTHON-DATEUTIL' : {'setup':'python-dateutil', 'url':'https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.2.tar.gz', 'local': 'python-dateutil-2.2.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    38     'PYYAML' : {'setup':'pyyaml', 'url':'http://pyyaml.org/download/pyyaml/PyYAML-3.11.tar.gz', 'local': 'PyYAML-3.11.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    38     'PYYAML' : {'setup':'pyyaml', 'url':'http://pyyaml.org/download/pyyaml/PyYAML-3.11.tar.gz', 'local': 'PyYAML-3.11.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    39     'PYTHON-DIGEST' : {'setup':'python-digest', 'url':'http://pypi.python.org/packages/source/p/python-digest/python-digest-1.7.tar.gz', 'local': 'python-digest-1.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    39     'PYTHON-DIGEST' : {'setup':'python-digest', 'url':'http://pypi.python.org/packages/source/p/python-digest/python-digest-1.7.tar.gz', 'local': 'python-digest-1.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    40     'DJANGO-TASTYPIE' : {'setup':'django-tastypie', 'url':'https://github.com/toastdriven/django-tastypie/archive/v0.11.0.tar.gz', 'local': 'django-tastypie-0.11.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    40     'DJANGO-TASTYPIE' : {'setup':'django-tastypie', 'url':'https://github.com/toastdriven/django-tastypie/archive/v0.11.0.tar.gz', 'local': 'django-tastypie-0.11.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    41     'ISODATE' : {'setup': 'isodate', 'url': 'https://github.com/gweis/isodate/archive/0.5.0.tar.gz', 'local': 'isodate-0.5.0.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, 
    41     'ISODATE' : {'setup': 'isodate', 'url': 'https://github.com/gweis/isodate/archive/0.5.0.tar.gz', 'local': 'isodate-0.5.0.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    42     'HTML5LIB' : {'setup': 'html5lib', 'url': 'https://github.com/html5lib/html5lib-python/archive/0.999.tar.gz', 'local': 'html5lib-0.999.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    42     'HTML5LIB' : {'setup': 'html5lib', 'url': 'https://github.com/html5lib/html5lib-python/archive/0.999.tar.gz', 'local': 'html5lib-0.999.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    43     'PYPARSING' : {'setup': 'pyparsing', 'url': 'https://pypi.python.org/packages/source/p/pyparsing/pyparsing-2.0.1.tar.gz', 'local': 'pyparsing-2.0.1.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    43     'PYPARSING' : {'setup': 'pyparsing', 'url': 'https://pypi.python.org/packages/source/p/pyparsing/pyparsing-2.0.1.tar.gz', 'local': 'pyparsing-2.0.1.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    44     #SPARQLWRAPPER : the file SPARQLWrapper-1.5.2.tar.gz is needed in the folder to soleve RDFLIB dependencies. It will be installed when resolving the dependencies.graph.
    44     #SPARQLWRAPPER : the file SPARQLWrapper-1.5.2.tar.gz is needed in the folder to soleve RDFLIB dependencies. It will be installed when resolving the dependencies.graph.
    45     'RDFLIB' : {'setup': 'rdflib', 'url': 'https://github.com/RDFLib/rdflib/archive/4.1.1.tar.gz', 'local': 'rdflib-4.1.1.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    45     'RDFLIB' : {'setup': 'rdflib', 'url': 'https://github.com/RDFLib/rdflib/archive/4.1.1.tar.gz', 'local': 'rdflib-4.1.1.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    46     'PYCRYPTO' : {'setup': 'pycrypto', 'url': 'http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.1.tar.gz', 'local': 'pycrypto-2.6.1.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    46     'PYCRYPTO' : {'setup': 'pycrypto', 'url': 'http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.1.tar.gz', 'local': 'pycrypto-2.6.1.tar.gz', 'install': {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    52         '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}},
    52         '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}},
    53     })
    53     })
    54 else:
    54 else:
    55     URLS.update({
    55     URLS.update({
    56         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.2.tar.gz', 'local':"psycopg2-2.5.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    56         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.2.tar.gz', 'local':"psycopg2-2.5.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    57         'PIL': {'setup': 'pil', 'url': 'https://github.com/python-imaging/Pillow/archive/2.3.1.tar.gz', 'local':"Pillow-2.3.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    57         'PIL': {'setup': 'pil', 'url': 'https://github.com/python-imaging/Pillow/archive/2.8.1.tar.gz', 'local':"Pillow-2.8.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    58     })
    58     })
    59     
    59 
    60 
    60 
    61 class ResourcesEnv(object):
    61 class ResourcesEnv(object):
    62 
    62 
    63     def __init__(self, src_base, run_base, urls, normal_installs):
    63     def __init__(self, src_base, run_base, urls, normal_installs):
    64         self.src_base = src_base
    64         self.src_base = src_base
    69 
    69 
    70     def get_src_base_path(self, fpath):
    70     def get_src_base_path(self, fpath):
    71         return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
    71         return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
    72 
    72 
    73     def get_run_res_base_path(self, fpath):
    73     def get_run_res_base_path(self, fpath):
    74         return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/")    
    74         return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/")
    75     
    75 
    76     def __add_package_def(self, key, dict):
    76     def __add_package_def(self, key, dict):
    77         self.URLS[key] = dict
    77         self.URLS[key] = dict
    78         
    78 
    79     def __init_url(self, urls):
    79     def __init_url(self, urls):
    80         for key, url_dict in urls.items():
    80         for key, url_dict in urls.items():
    81             url_dict_copy = url_dict.copy()
    81             url_dict_copy = url_dict.copy()
    82             if url_dict.get('install', {}).get('method','pip') == 'pip-req':
    82             if url_dict.get('install', {}).get('method','pip') == 'pip-req':
    83                 get_base_path = self.get_run_res_base_path
    83                 get_base_path = self.get_run_res_base_path
    93     logger.notify('Check directory %s' % dir)
    93     logger.notify('Check directory %s' % dir)
    94     if not os.path.exists(dir):
    94     if not os.path.exists(dir):
    95         logger.notify('Creating directory %s' % dir)
    95         logger.notify('Creating directory %s' % dir)
    96         os.makedirs(dir)
    96         os.makedirs(dir)
    97 
    97 
    98 def extend_parser(parser):    
    98 def extend_parser(parser):
    99     parser.add_option(
    99     parser.add_option(
   100         '--index-url',
   100         '--index-url',
   101         metavar='INDEX_URL',
   101         metavar='INDEX_URL',
   102         dest='index_url',
   102         dest='index_url',
   103         default='http://pypi.python.org/simple/',
   103         default='http://pypi.python.org/simple/',
   110     parser.add_option(
   110     parser.add_option(
   111         '--ignore-packages',
   111         '--ignore-packages',
   112         metavar='ignore_packages',
   112         metavar='ignore_packages',
   113         dest='ignore_packages',
   113         dest='ignore_packages',
   114         default=None,
   114         default=None,
   115         help='list of comma separated keys for package to ignore')    
   115         help='list of comma separated keys for package to ignore')
   116 
   116 
   117 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):
   117 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):
   118     psycopg2_src = os.path.join(src_dir,"psycopg2.zip")
   118     psycopg2_src = os.path.join(src_dir,"psycopg2.zip")
   119     shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src)
   119     shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src)
   120     #extract psycopg2
   120     #extract psycopg2
   121     zf = zipfile.ZipFile(psycopg2_src)
   121     zf = zipfile.ZipFile(psycopg2_src)
   122     psycopg2_base_path = os.path.join(src_dir,"psycopg2")
   122     psycopg2_base_path = os.path.join(src_dir,"psycopg2")
   123     zf.extractall(psycopg2_base_path)
   123     zf.extractall(psycopg2_base_path)
   124     zf.close()
   124     zf.close()
   125     
   125 
   126     psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
   126     psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
   127     shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
   127     shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
   128     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')))
   128     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')))
   129     
   129 
   130 
   130 
   131 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):
   131 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):
   132     
   132 
   133     args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]                
   133     args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]
   134     if option_str :
   134     if option_str :
   135         args.insert(4,option_str)
   135         args.insert(4,option_str)
   136     call_subprocess(args,
   136     call_subprocess(args,
   137             cwd=os.path.abspath(tmp_dir),
   137             cwd=os.path.abspath(tmp_dir),
   138             filter_stdout=filter_python_develop,
   138             filter_stdout=filter_python_develop,
   139             show_stdout=True,
   139             show_stdout=True,
   140             extra_env=extra_env)
   140             extra_env=extra_env)
   141 
   141 
   142     mysqlconfig_output = []
   142     mysqlconfig_output = []
   143     
   143 
   144     call_subprocess(['mysql_config', '--libmysqld-libs'],
   144     call_subprocess(['mysql_config', '--libmysqld-libs'],
   145         cwd=os.path.abspath(tmp_dir),
   145         cwd=os.path.abspath(tmp_dir),
   146         filter_stdout=lambda line: mysqlconfig_output.append(line),
   146         filter_stdout=lambda line: mysqlconfig_output.append(line),
   147         show_stdout=True)
   147         show_stdout=True)
   148         
   148 
   149     mysqlconfig_output = "".join(mysqlconfig_output)
   149     mysqlconfig_output = "".join(mysqlconfig_output)
   150     m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
   150     m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
   151     if m:
   151     if m:
   152         repdylibpath = m.group(1)
   152         repdylibpath = m.group(1)
   153     else:
   153     else:
   154         repdylibpath = '/usr/local/mysql/lib'
   154         repdylibpath = '/usr/local/mysql/lib'
   155         
   155 
   156     dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
   156     dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
   157     def key_func(s):
   157     def key_func(s):
   158         m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
   158         m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
   159         if m:
   159         if m:
   160             return int(m.group(1))
   160             return int(m.group(1))
   161         else:
   161         else:
   162             return sys.maxint
   162             return sys.maxint
   163     dyliblist.sort(key=key_func)
   163     dyliblist.sort(key=key_func)
   164     
   164 
   165     if dyliblist:
   165     if dyliblist:
   166         dylibpath = dyliblist[0]
   166         dylibpath = dyliblist[0]
   167     else:
   167     else:
   168         dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
   168         dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
   169         
   169 
   170     dylibname = os.path.basename(dylibpath)    
   170     dylibname = os.path.basename(dylibpath)
   171     sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
   171     sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
   172     
   172 
   173     call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
   173     call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
   174         cwd=os.path.abspath(tmp_dir),
   174         cwd=os.path.abspath(tmp_dir),
   175         filter_stdout=filter_python_develop,
   175         filter_stdout=filter_python_develop,
   176         show_stdout=True)
   176         show_stdout=True)
   177 
   177 
   178 
   178 
   179 def gen_install_comp_lib(lib_name, lib_key, configure_options=[]):
   179 def gen_install_comp_lib(lib_name, lib_key, configure_options=[]):
   180     
   180 
   181     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):
   181     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):
   182         lib_src = os.path.join(src_dir,lib_name+".tar.gz")
   182         lib_src = os.path.join(src_dir,lib_name+".tar.gz")
   183         logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src))
   183         logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src))
   184         shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
   184         shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
   185         tf = tarfile.open(lib_src,'r:gz')
   185         tf = tarfile.open(lib_src,'r:gz')
   186         lib_base_path = os.path.join(src_dir, lib_name) 
   186         lib_base_path = os.path.join(src_dir, lib_name)
   187         logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
   187         logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
   188         tf.extractall(lib_base_path)
   188         tf.extractall(lib_base_path)
   189         tf.close()
   189         tf.close()
   190         
   190 
   191         lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
   191         lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
   192     
   192 
   193         logger.notify(lib_name + " configure in " + lib_src_path)
   193         logger.notify(lib_name + " configure in " + lib_src_path)
   194         call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options,
   194         call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options,
   195                         cwd=os.path.abspath(lib_src_path),
   195                         cwd=os.path.abspath(lib_src_path),
   196                         filter_stdout=filter_python_develop,
   196                         filter_stdout=filter_python_develop,
   197                         show_stdout=True)
   197                         show_stdout=True)
   198         
   198 
   199         logger.notify(lib_name + " make in " + lib_src_path)
   199         logger.notify(lib_name + " make in " + lib_src_path)
   200         call_subprocess(['make'],
   200         call_subprocess(['make'],
   201                         cwd=os.path.abspath(lib_src_path),
   201                         cwd=os.path.abspath(lib_src_path),
   202                         filter_stdout=filter_python_develop,
   202                         filter_stdout=filter_python_develop,
   203                         show_stdout=True)
   203                         show_stdout=True)
   204     
   204 
   205         logger.notify(lib_name + "make install in " + lib_src_path)
   205         logger.notify(lib_name + "make install in " + lib_src_path)
   206         call_subprocess(['make', 'install'],
   206         call_subprocess(['make', 'install'],
   207                         cwd=os.path.abspath(lib_src_path),
   207                         cwd=os.path.abspath(lib_src_path),
   208                         filter_stdout=filter_python_develop,
   208                         filter_stdout=filter_python_develop,
   209                         show_stdout=True)
   209                         show_stdout=True)
   214 
   214 
   215 osx_extra_env = {'ARCHFLAGS': '-Wno-error=unused-command-line-argument-hard-error-in-future', 'CFLAGS': '-Qunused-arguments', 'CPPFLAGS': '-Qunused-arguments'}
   215 osx_extra_env = {'ARCHFLAGS': '-Wno-error=unused-command-line-argument-hard-error-in-future', 'CFLAGS': '-Qunused-arguments', 'CPPFLAGS': '-Qunused-arguments'}
   216 
   216 
   217 
   217 
   218 def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
   218 def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
   219     
   219 
   220     all_urls = URLS.copy()
   220     all_urls = URLS.copy()
   221     if urls is not None:
   221     if urls is not None:
   222         all_urls.update(urls)
   222         all_urls.update(urls)
   223         
   223 
   224     res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs)
   224     res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs)
   225 
   225 
   226     def filter_python_develop(line):
   226     def filter_python_develop(line):
   227         if not line.strip():
   227         if not line.strip():
   228             return Logger.DEBUG
   228             return Logger.DEBUG
   230                        'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
   230                        'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
   231                        'creating ', 'Copying ']:
   231                        'creating ', 'Copying ']:
   232             if line.startswith(prefix):
   232             if line.startswith(prefix):
   233                 return Logger.DEBUG
   233                 return Logger.DEBUG
   234         return Logger.NOTIFY
   234         return Logger.NOTIFY
   235     
   235 
   236     
   236 
   237     def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
   237     def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
   238         logger.notify("Install %s from %s with %s" % (key,res_path,method))
   238         logger.notify("Install %s from %s with %s" % (key,res_path,method))
   239         if method == 'pip':
   239         if method == 'pip':
   240             if sys.platform == 'win32':
   240             if sys.platform == 'win32':
   241                 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path]
   241                 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path]
   285                 args.insert(1,option_str)
   285                 args.insert(1,option_str)
   286             call_subprocess(args,
   286             call_subprocess(args,
   287                     cwd=os.path.abspath(tmp_dir),
   287                     cwd=os.path.abspath(tmp_dir),
   288                     filter_stdout=filter_python_develop,
   288                     filter_stdout=filter_python_develop,
   289                     show_stdout=True,
   289                     show_stdout=True,
   290                     extra_env=extra_env)            
   290                     extra_env=extra_env)
   291  
   291 
   292     
   292 
   293     def after_install(options, home_dir):
   293     def after_install(options, home_dir):
   294         
   294 
   295         global logger
   295         global logger
   296         
   296 
   297         verbosity = options.verbose - options.quiet
   297         verbosity = options.verbose - options.quiet
   298         logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
   298         logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
   299 
   299 
   300         
   300 
   301         home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
   301         home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
   302         base_dir = os.path.dirname(home_dir)
   302         base_dir = os.path.dirname(home_dir)
   303         src_dir = os.path.join(home_dir, 'src')
   303         src_dir = os.path.join(home_dir, 'src')
   304         tmp_dir = os.path.join(home_dir, 'tmp')
   304         tmp_dir = os.path.join(home_dir, 'tmp')
   305         ensure_dir(src_dir, logger)
   305         ensure_dir(src_dir, logger)
   306         ensure_dir(tmp_dir, logger)
   306         ensure_dir(tmp_dir, logger)
   307         system_str = platform.system()
   307         system_str = platform.system()
   308                 
   308 
   309         res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
   309         res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
   310         if res_source_key is None:
   310         if res_source_key is None:
   311             res_source_key = 'local'
   311             res_source_key = 'local'
   312         
   312 
   313         ignore_packages = []
   313         ignore_packages = []
   314         
   314 
   315         if system_str == 'Windows':
   315         if system_str == 'Windows':
   316             default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}}
   316             default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}}
   317         else:
   317         else:
   318             default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}}
   318             default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}}
   319             
   319 
   320         if options.ignore_packages :
   320         if options.ignore_packages :
   321             ignore_packages = options.ignore_packages.split(",")
   321             ignore_packages = options.ignore_packages.split(",")
   322         
   322 
   323         logger.indent += 2
   323         logger.indent += 2
   324         try:    
   324         try:
   325             for key in res_env.NORMAL_INSTALL:
   325             for key in res_env.NORMAL_INSTALL:
   326                 install_options = None
   326                 install_options = None
   327                 if isinstance(key, dict):
   327                 if isinstance(key, dict):
   328                     install_options = key.get('install', default_install_options)
   328                     install_options = key.get('install', default_install_options)
   329                     install_options['method'] = 'pip-req'
   329                     install_options['method'] = 'pip-req'
   338                 method = install_options.get('method', default_install_options['method'])
   338                 method = install_options.get('method', default_install_options['method'])
   339                 option_str = install_options.get('option_str', default_install_options['option_str'])
   339                 option_str = install_options.get('option_str', default_install_options['option_str'])
   340                 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
   340                 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
   341                 if not extra_env:
   341                 if not extra_env:
   342                     extra_env = {}
   342                     extra_env = {}
   343                     
   343 
   344                 if 'TMPDIR' not in extra_env:
   344                 if 'TMPDIR' not in extra_env:
   345                     extra_env['TMPDIR'] = os.path.abspath(tmp_dir)
   345                     extra_env['TMPDIR'] = os.path.abspath(tmp_dir)
   346                 if system_str == 'Darwin':
   346                 if system_str == 'Darwin':
   347                     for flag_key, flag_value in iter(osx_extra_env.items()):
   347                     for flag_key, flag_value in iter(osx_extra_env.items()):
   348                         flags = extra_env.get(flag_key, '')
   348                         flags = extra_env.get(flag_key, '')
   349                         if flag_value not in flags:
   349                         if flag_value not in flags:
   350                             flags += " -Wno-error=unused-command-line-argument-hard-error-in-future"
   350                             flags += " -Wno-error=unused-command-line-argument-hard-error-in-future"
   351                             extra_env[flag_key] = flags.strip()
   351                             extra_env[flag_key] = flags.strip()
   352                     
   352 
   353                 #isinstance(lst, (list, tuple))
   353                 #isinstance(lst, (list, tuple))
   354                 if key not in ignore_packages:
   354                 if key not in ignore_packages:
   355                     logger.notify("install %s with method %s" % (key, repr(method)))
   355                     logger.notify("install %s with method %s" % (key, repr(method)))
   356                     if callable(method):
   356                     if callable(method):
   357                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   357                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   358                     elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:  
   358                     elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:
   359                         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)
   359                         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)
   360                     else:
   360                     else:
   361                         normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
   361                         normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
   362                             
   362 
   363             logger.notify("Clear source dir")
   363             logger.notify("Clear source dir")
   364             shutil.rmtree(src_dir)
   364             shutil.rmtree(src_dir)
   365     
   365 
   366         finally:
   366         finally:
   367             logger.indent -= 2
   367             logger.indent -= 2
   368         script_dir = join(base_dir, bin_dir)
   368         script_dir = join(base_dir, bin_dir)
   369         logger.notify('Run "%s Package" to install new packages that provide builds'
   369         logger.notify('Run "%s Package" to install new packages that provide builds'
   370                       % join(script_dir, 'easy_install'))
   370                       % join(script_dir, 'easy_install'))
   371     
   371 
   372     def adjust_options(options, args):
   372     def adjust_options(options, args):
   373         if not options_to_add:
   373         if not options_to_add:
   374             return
   374             return
   375         for opt in options_to_add:
   375         for opt in options_to_add:
   376             test_opt = opt.split('=',1)[0]
   376             test_opt = opt.split('=',1)[0]
   377             #if not hasattr(options,test_opt) or getattr(options, test_opt) is None:
   377             #if not hasattr(options,test_opt) or getattr(options, test_opt) is None:
   378             setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True)
   378             setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True)
   379 
   379 
   380     return adjust_options, extend_parser, after_install
   380     return adjust_options, extend_parser, after_install
   381