virtualenv/res/lib/lib_create_env.py
changeset 308 23f5e267cd1e
parent 274 e34d988f37a7
child 322 3a80a07f1300
equal deleted inserted replaced
307:696f02ba0853 308:23f5e267cd1e
    30     'SOCIAL_AUTH': {'setup':'social_auth', 'url':'https://github.com/omab/python-social-auth/archive/v0.2.7.tar.gz', 'local':"python-social-auth-0.2.7.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    30     'SOCIAL_AUTH': {'setup':'social_auth', 'url':'https://github.com/omab/python-social-auth/archive/v0.2.7.tar.gz', 'local':"python-social-auth-0.2.7.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    31     'DJANGO_GUARDIAN' : { 'setup': 'django-guardian', 'url':'https://github.com/lukaszb/django-guardian/archive/v1.3.tar.gz', 'local':"django-guardian-1.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    31     'DJANGO_GUARDIAN' : { 'setup': 'django-guardian', 'url':'https://github.com/lukaszb/django-guardian/archive/v1.3.tar.gz', 'local':"django-guardian-1.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    32     'SORL_THUMBNAIL' : { 'setup': 'sorl-thumbnail', 'url':'https://github.com/mariocesar/sorl-thumbnail/archive/master.tar.gz', 'local':"sorl-thumbnail-12.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    32     'SORL_THUMBNAIL' : { 'setup': 'sorl-thumbnail', 'url':'https://github.com/mariocesar/sorl-thumbnail/archive/master.tar.gz', 'local':"sorl-thumbnail-12.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    33     'LIBJPEG': {'setup': None, 'url':'jpegsrc.v9.tar.gz', 'local':'jpegsrc.v9.tar.gz', 'install': {'method': 'install_libjpeg', 'option_str': None, 'dict_extra_env': None}},
    33     'LIBJPEG': {'setup': None, 'url':'jpegsrc.v9.tar.gz', 'local':'jpegsrc.v9.tar.gz', 'install': {'method': 'install_libjpeg', 'option_str': None, 'dict_extra_env': None}},
    34     'ZLIB': {'setup': None, 'url':'zlib-1.2.8.tar.gz', 'local':'zlib-1.2.8.tar.gz', 'install': {'method': 'install_zlib', 'option_str': None, 'dict_extra_env': None}},
    34     'ZLIB': {'setup': None, 'url':'zlib-1.2.8.tar.gz', 'local':'zlib-1.2.8.tar.gz', 'install': {'method': 'install_zlib', 'option_str': None, 'dict_extra_env': None}},
    35     'HAYSTACK': {'setup': 'django-haystack', 'url': 'https://github.com/django-haystack/django-haystack/archive/v2.4.0.tar.gz', 'local': 'django-haystack-2.4.0.tar.gz', 'install':{'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    35     'HAYSTACK': {'setup': 'django-haystack', 'url': 'https://github.com/django-haystack/django-haystack/archive/v2.4.1.tar.gz', 'local': 'django-haystack-2.4.1.tar.gz', 'install':{'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    36     'REQUESTS': {'setup': 'requests', 'url':'https://github.com/kennethreitz/requests/archive/v2.7.0.tar.gz', 'local':'requests-2.7.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    36     'REQUESTS': {'setup': 'requests', 'url':'https://github.com/kennethreitz/requests/archive/v2.7.0.tar.gz', 'local':'requests-2.7.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    37     'ELASTICSEARCH': {'setup': 'elasticsearch', 'url':'https://github.com/elastic/elasticsearch-py/archive/1.4.0.tar.gz', 'local':'elasticsearch-1.4.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    37     'ELASTICSEARCH': {'setup': 'elasticsearch', 'url':'https://pypi.python.org/packages/source/e/elasticsearch/elasticsearch-2.3.0.tar.gz', 'local':'elasticsearch-2.3.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    38     'PYELASTICSEARCH': {'setup': 'pyelasticsearch', 'url':'https://pypi.python.org/packages/source/p/pyelasticsearch/pyelasticsearch-1.2.3.tar.gz', 'local':'pyelasticsearch-1.2.3.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
       
    39     'WHOOSH': {'setup': 'whoosh', 'url':'https://bitbucket.org/mchaput/whoosh/get/2.7.0.tar.gz', 'local':'whoosh-2.7.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    38     'WHOOSH': {'setup': 'whoosh', 'url':'https://bitbucket.org/mchaput/whoosh/get/2.7.0.tar.gz', 'local':'whoosh-2.7.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    40     'SETUPTOOLS_HG' : {'setup':'setuptools_hg', 'url':'https://bitbucket.org/jezdez/setuptools_hg/get/v0.4.tar.gz', 'local': 'setuptools_hg-0.4.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    39     'SETUPTOOLS_HG' : {'setup':'setuptools_hg', 'url':'https://bitbucket.org/jezdez/setuptools_hg/get/v0.4.tar.gz', 'local': 'setuptools_hg-0.4.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    41     # dependencies for Tastypie : mimeparse>=0.1.3, python-dateutil>=2.1, lxml, PyYAML (not necessary but we never know), python-digest, defusedxml
    40     # dependencies for Tastypie : mimeparse>=0.1.3, python-dateutil>=2.1, lxml, PyYAML (not necessary but we never know), python-digest, defusedxml
    42     'MIMEPARSE' : {'setup':'mimeparse', 'url':'http://pypi.python.org/packages/source/m/mimeparse/mimeparse-0.1.3.tar.gz', 'local': 'mimeparse-0.1.3.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    41     'MIMEPARSE' : {'setup':'mimeparse', 'url':'http://pypi.python.org/packages/source/m/mimeparse/mimeparse-0.1.3.tar.gz', 'local': 'mimeparse-0.1.3.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    43     'SIX' : {'setup':'six', 'url':'https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz', 'local': 'six-1.9.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    42     'SIX' : {'setup':'six', 'url':'https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz', 'local': 'six-1.9.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    47     'DEFUSEDXML' : {'setup':'defusedxml', 'url':'https://pypi.python.org/packages/source/d/defusedxml/defusedxml-0.4.1.tar.gz', 'local': 'defusedxml-0.4.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    46     'DEFUSEDXML' : {'setup':'defusedxml', 'url':'https://pypi.python.org/packages/source/d/defusedxml/defusedxml-0.4.1.tar.gz', 'local': 'defusedxml-0.4.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    48     'DJANGO-TASTYPIE' : {'setup':'django-tastypie', 'url':'https://github.com/django-tastypie/django-tastypie/archive/v0.12.2.tar.gz', 'local': 'django-tastypie-0.12.2.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    47     'DJANGO-TASTYPIE' : {'setup':'django-tastypie', 'url':'https://github.com/django-tastypie/django-tastypie/archive/v0.12.2.tar.gz', 'local': 'django-tastypie-0.12.2.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    49     'DJANGO-CORS-HEADERS' : {'setup':'django-cors-headers', 'url':'https://github.com/ottoyiu/django-cors-headers/archive/1.1.0.tar.gz', 'local': 'django-cors-headers-1.1.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    48     'DJANGO-CORS-HEADERS' : {'setup':'django-cors-headers', 'url':'https://github.com/ottoyiu/django-cors-headers/archive/1.1.0.tar.gz', 'local': 'django-cors-headers-1.1.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    50     'DJANGO-CHUNCKED-UPLOADS' : {'setup': 'django-chuncked-uploads', 'url':'https://github.com/IRI-Research/django-chunked-uploads/archive/v0.7.tar.gz', 'local':'django-chunked-uploads-0.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    49     'DJANGO-CHUNCKED-UPLOADS' : {'setup': 'django-chuncked-uploads', 'url':'https://github.com/IRI-Research/django-chunked-uploads/archive/v0.7.tar.gz', 'local':'django-chunked-uploads-0.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
    51     'OAUTHLIB': { 'setup': 'oauthlib', 'url':"https://github.com/idan/oauthlib/archive/0.7.2.tar.gz", 'local':"oauthlib-0.7.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    50     'OAUTHLIB': { 'setup': 'oauthlib', 'url':"https://github.com/idan/oauthlib/archive/0.7.2.tar.gz", 'local':"oauthlib-0.7.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    52     'URLLIB3': { 'setup': 'urllib3', 'url':'https://github.com/shazow/urllib3/archive/1.10.4.tar.gz', 'local':"urllib3-1.10.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    51     'URLLIB3': { 'setup': 'urllib3', 'url':'https://github.com/shazow/urllib3/archive/1.14.tar.gz', 'local':"urllib3-1.14.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    53     'SIMPLEJSON' : { 'setup': 'simplejson', 'url': 'https://github.com/simplejson/simplejson/archive/v3.6.5.tar.gz', 'local' : 'simplejson-3.6.5.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    52     'SIMPLEJSON' : { 'setup': 'simplejson', 'url': 'https://github.com/simplejson/simplejson/archive/v3.6.5.tar.gz', 'local' : 'simplejson-3.6.5.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    54     'PYJWT' : { 'setup': 'pyjwt', 'url': 'https://github.com/jpadilla/pyjwt/archive/1.1.0.tar.gz', 'local' : 'pyjwt-1.1.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    53     'PYJWT' : { 'setup': 'pyjwt', 'url': 'https://github.com/jpadilla/pyjwt/archive/1.1.0.tar.gz', 'local' : 'pyjwt-1.1.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    55     'PYTHON-MIMEPARSE': { 'setup': 'python-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}},
    54     'PYTHON-MIMEPARSE': { 'setup': 'python-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}},
    56     'REQUESTS-OAUTHLIB': { 'setup': 'requests-oauthlib', 'url': 'https://github.com/requests/requests-oauthlib/archive/v0.5.0.tar.gz', 'local' : 'requests-oauthlib-0.5.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    55     'REQUESTS-OAUTHLIB': { 'setup': 'requests-oauthlib', 'url': 'https://github.com/requests/requests-oauthlib/archive/v0.5.0.tar.gz', 'local' : 'requests-oauthlib-0.5.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    57 }
    56 }
    58 
    57 
    59 if system_str == 'Windows':
    58 if system_str == 'Windows':
    60     
    59 
    61     size = 8 * struct.calcsize("P")
    60     size = 8 * struct.calcsize("P")
    62     if size==32:
    61     if size==32:
    63         mysqlres = "MySQL-python-1.2.3.win32-py2.7.exe"
    62         mysqlres = "MySQL-python-1.2.3.win32-py2.7.exe"
    64     else:
    63     else:
    65         mysqlres = "MySQL-python-1.2.3.win-amd64-py2.7.exe"
    64         mysqlres = "MySQL-python-1.2.3.win-amd64-py2.7.exe"
    66     
    65 
    67     URLS.update({
    66     URLS.update({
    68         '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}},
    67         '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}},
    69         '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}},
    68         '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}},
    70         '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}},
    69         '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}},
    71         'MYSQL': { 'setup': 'mysql-python', 'url': mysqlres, 'local': mysqlres, 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    70         'MYSQL': { 'setup': 'mysql-python', 'url': mysqlres, 'local': mysqlres, 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    86         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.tar.gz', 'local':"psycopg2-2.6.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    85         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.tar.gz', 'local':"psycopg2-2.6.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    87         'PIL': {'setup': 'pillow', 'url': 'https://github.com/python-pillow/Pillow/archive/2.9.0.tar.gz', 'local':"Pillow-2.9.0.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    86         'PIL': {'setup': 'pillow', 'url': 'https://github.com/python-pillow/Pillow/archive/2.9.0.tar.gz', 'local':"Pillow-2.9.0.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    88         'LXML': {'setup': 'lxml', 'url': 'lxml-3.2.1.tar.bz2', 'local': 'lxml-3.2.1.tar.bz2', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': lxml_options}},
    87         'LXML': {'setup': 'lxml', 'url': 'lxml-3.2.1.tar.bz2', 'local': 'lxml-3.2.1.tar.bz2', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': lxml_options}},
    89         '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}},
    88         '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}},
    90     })
    89     })
    91     
    90 
    92 
    91 
    93 class ResourcesEnv(object):
    92 class ResourcesEnv(object):
    94 
    93 
    95     def __init__(self, src_base, run_base, urls, normal_installs):
    94     def __init__(self, src_base, run_base, urls, normal_installs):
    96         self.src_base = src_base
    95         self.src_base = src_base
   101 
   100 
   102     def get_src_base_path(self, fpath):
   101     def get_src_base_path(self, fpath):
   103         return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
   102         return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
   104 
   103 
   105     def get_run_res_base_path(self, fpath):
   104     def get_run_res_base_path(self, fpath):
   106         return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/")    
   105         return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/")
   107     
   106 
   108     def __add_package_def(self, key, dict):
   107     def __add_package_def(self, key, dict):
   109         self.URLS[key] = dict
   108         self.URLS[key] = dict
   110         
   109 
   111     def __init_url(self, urls):
   110     def __init_url(self, urls):
   112         for key, url_dict in urls.items():
   111         for key, url_dict in urls.items():
   113             url_dict_copy = url_dict.copy()
   112             url_dict_copy = url_dict.copy()
   114             if url_dict.get('install', {}).get('method','pip') == 'pip-req':
   113             if url_dict.get('install', {}).get('method','pip') == 'pip-req':
   115                 get_base_path = self.get_run_res_base_path
   114                 get_base_path = self.get_run_res_base_path
   125     logger.notify('Check directory %s' % dir)
   124     logger.notify('Check directory %s' % dir)
   126     if not os.path.exists(dir):
   125     if not os.path.exists(dir):
   127         logger.notify('Creating directory %s' % dir)
   126         logger.notify('Creating directory %s' % dir)
   128         os.makedirs(dir)
   127         os.makedirs(dir)
   129 
   128 
   130 def extend_parser(parser):    
   129 def extend_parser(parser):
   131     parser.add_option(
   130     parser.add_option(
   132         '--index-url',
   131         '--index-url',
   133         metavar='INDEX_URL',
   132         metavar='INDEX_URL',
   134         dest='index_url',
   133         dest='index_url',
   135         default='http://pypi.python.org/simple/',
   134         default='http://pypi.python.org/simple/',
   161     #extract psycopg2
   160     #extract psycopg2
   162     zf = zipfile.ZipFile(psycopg2_src)
   161     zf = zipfile.ZipFile(psycopg2_src)
   163     psycopg2_base_path = os.path.join(src_dir,"psycopg2")
   162     psycopg2_base_path = os.path.join(src_dir,"psycopg2")
   164     zf.extractall(psycopg2_base_path)
   163     zf.extractall(psycopg2_base_path)
   165     zf.close()
   164     zf.close()
   166     
   165 
   167     psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
   166     psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
   168     shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
   167     shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
   169     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')))
   168     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')))
   170     
   169 
   171 
   170 
   172 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):
   171 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):
   173     
   172 
   174     args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]                
   173     args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]
   175     if option_str :
   174     if option_str :
   176         args.insert(4,option_str)
   175         args.insert(4,option_str)
   177     call_subprocess(args,
   176     call_subprocess(args,
   178             cwd=os.path.abspath(tmp_dir),
   177             cwd=os.path.abspath(tmp_dir),
   179             filter_stdout=filter_python_develop,
   178             filter_stdout=filter_python_develop,
   180             show_stdout=True,
   179             show_stdout=True,
   181             extra_env=extra_env)
   180             extra_env=extra_env)
   182 
   181 
   183     mysqlconfig_output = []
   182     mysqlconfig_output = []
   184     
   183 
   185     call_subprocess(['mysql_config', '--libmysqld-libs'],
   184     call_subprocess(['mysql_config', '--libmysqld-libs'],
   186         cwd=os.path.abspath(tmp_dir),
   185         cwd=os.path.abspath(tmp_dir),
   187         filter_stdout=lambda line: mysqlconfig_output.append(line),
   186         filter_stdout=lambda line: mysqlconfig_output.append(line),
   188         show_stdout=True)
   187         show_stdout=True)
   189         
   188 
   190     mysqlconfig_output = "".join(mysqlconfig_output)
   189     mysqlconfig_output = "".join(mysqlconfig_output)
   191     m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
   190     m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
   192     if m:
   191     if m:
   193         repdylibpath = m.group(1)
   192         repdylibpath = m.group(1)
   194     else:
   193     else:
   195         repdylibpath = '/usr/local/mysql/lib'
   194         repdylibpath = '/usr/local/mysql/lib'
   196         
   195 
   197     dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
   196     dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
   198     def key_func(s):
   197     def key_func(s):
   199         m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
   198         m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
   200         if m:
   199         if m:
   201             return int(m.group(1))
   200             return int(m.group(1))
   202         else:
   201         else:
   203             return sys.maxint
   202             return sys.maxint
   204     dyliblist.sort(key=key_func)
   203     dyliblist.sort(key=key_func)
   205     
   204 
   206     if dyliblist:
   205     if dyliblist:
   207         dylibpath = dyliblist[0]
   206         dylibpath = dyliblist[0]
   208     else:
   207     else:
   209         dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
   208         dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
   210         
   209 
   211     dylibname = os.path.basename(dylibpath)    
   210     dylibname = os.path.basename(dylibpath)
   212     sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
   211     sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
   213     
   212 
   214     call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
   213     call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
   215         cwd=os.path.abspath(tmp_dir),
   214         cwd=os.path.abspath(tmp_dir),
   216         filter_stdout=filter_python_develop,
   215         filter_stdout=filter_python_develop,
   217         show_stdout=True)
   216         show_stdout=True)
   218 
   217 
   219 
   218 
   220 def gen_install_comp_lib(lib_name, lib_key, configure_options=[], configure_env={}):
   219 def gen_install_comp_lib(lib_name, lib_key, configure_options=[], configure_env={}):
   221     
   220 
   222     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):
   221     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):
   223         lib_src = os.path.join(src_dir,lib_name+".tar.gz")
   222         lib_src = os.path.join(src_dir,lib_name+".tar.gz")
   224         logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src))
   223         logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src))
   225         shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
   224         shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
   226         tf = tarfile.open(lib_src,'r:gz')
   225         tf = tarfile.open(lib_src,'r:gz')
   227         lib_base_path = os.path.join(src_dir, lib_name) 
   226         lib_base_path = os.path.join(src_dir, lib_name)
   228         logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
   227         logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
   229         tf.extractall(lib_base_path)
   228         tf.extractall(lib_base_path)
   230         tf.close()
   229         tf.close()
   231         
   230 
   232         lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
   231         lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
   233         
   232 
   234         
   233 
   235         context_map = {
   234         context_map = {
   236             'option_str' : option_str,
   235             'option_str' : option_str,
   237             'home_dir': os.path.abspath(home_dir),
   236             'home_dir': os.path.abspath(home_dir),
   238             'lib_dir': os.path.abspath(lib_dir),
   237             'lib_dir': os.path.abspath(lib_dir),
   239             'tmp_dir': os.path.abspath(tmp_dir),
   238             'tmp_dir': os.path.abspath(tmp_dir),
   240             'src_dir': os.path.abspath(src_dir),
   239             'src_dir': os.path.abspath(src_dir),
   241         }
   240         }
   242         
   241 
   243         configure_options_trans = map(lambda s: s % context_map, configure_options)
   242         configure_options_trans = map(lambda s: s % context_map, configure_options)
   244         configure_env_trans = {k: s % context_map for k,s in configure_env.items()}
   243         configure_env_trans = {k: s % context_map for k,s in configure_env.items()}
   245     
   244 
   246         logger.notify(lib_name + " configure in " + lib_src_path)
   245         logger.notify(lib_name + " configure in " + lib_src_path)
   247         call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options_trans,
   246         call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options_trans,
   248                         cwd=os.path.abspath(lib_src_path),
   247                         cwd=os.path.abspath(lib_src_path),
   249                         filter_stdout=filter_python_develop,
   248                         filter_stdout=filter_python_develop,
   250                         show_stdout=True,
   249                         show_stdout=True,
   254         logger.notify(lib_name + " make in " + lib_src_path)
   253         logger.notify(lib_name + " make in " + lib_src_path)
   255         call_subprocess(['make'],
   254         call_subprocess(['make'],
   256                         cwd=os.path.abspath(lib_src_path),
   255                         cwd=os.path.abspath(lib_src_path),
   257                         filter_stdout=filter_python_develop,
   256                         filter_stdout=filter_python_develop,
   258                         show_stdout=True)
   257                         show_stdout=True)
   259     
   258 
   260         logger.notify(lib_name + "make install in " + lib_src_path)
   259         logger.notify(lib_name + "make install in " + lib_src_path)
   261         call_subprocess(['make', 'install'],
   260         call_subprocess(['make', 'install'],
   262                         cwd=os.path.abspath(lib_src_path),
   261                         cwd=os.path.abspath(lib_src_path),
   263                         filter_stdout=filter_python_develop,
   262                         filter_stdout=filter_python_develop,
   264                         show_stdout=True)
   263                         show_stdout=True)
   269 
   268 
   270 #osx_extra_env = {'ARCHFLAGS': '-Wno-error=unused-command-line-argument-hard-error-in-future', 'CFLAGS': '-Qunused-arguments', 'CPPFLAGS': '-Qunused-arguments'}
   269 #osx_extra_env = {'ARCHFLAGS': '-Wno-error=unused-command-line-argument-hard-error-in-future', 'CFLAGS': '-Qunused-arguments', 'CPPFLAGS': '-Qunused-arguments'}
   271 osx_extra_env = {}
   270 osx_extra_env = {}
   272 
   271 
   273 def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
   272 def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
   274     
   273 
   275     all_urls = URLS.copy()
   274     all_urls = URLS.copy()
   276     if urls is not None:
   275     if urls is not None:
   277         all_urls.update(urls)
   276         all_urls.update(urls)
   278         
   277 
   279     res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs)
   278     res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs)
   280 
   279 
   281     def filter_python_develop(line):
   280     def filter_python_develop(line):
   282         if not line.strip():
   281         if not line.strip():
   283             return Logger.DEBUG
   282             return Logger.DEBUG
   285                        'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
   284                        'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
   286                        'creating ', 'Copying ']:
   285                        'creating ', 'Copying ']:
   287             if line.startswith(prefix):
   286             if line.startswith(prefix):
   288                 return Logger.DEBUG
   287                 return Logger.DEBUG
   289         return Logger.NOTIFY
   288         return Logger.NOTIFY
   290     
   289 
   291     
   290 
   292     def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
   291     def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
   293         logger.notify("Install %s from %s with %s" % (key,res_path,method))
   292         logger.notify("Install %s from %s with %s" % (key,res_path,method))
   294         if method == 'pip':
   293         if method == 'pip':
   295             if sys.platform == 'win32':
   294             if sys.platform == 'win32':
   296                 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path]
   295                 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path]
   341             call_subprocess(args,
   340             call_subprocess(args,
   342                     cwd=os.path.abspath(tmp_dir),
   341                     cwd=os.path.abspath(tmp_dir),
   343                     filter_stdout=filter_python_develop,
   342                     filter_stdout=filter_python_develop,
   344                     show_stdout=True,
   343                     show_stdout=True,
   345                     extra_env=extra_env)
   344                     extra_env=extra_env)
   346  
   345 
   347     
   346 
   348     def after_install(options, home_dir):
   347     def after_install(options, home_dir):
   349         
   348 
   350         global logger
   349         global logger
   351         
   350 
   352         verbosity = options.verbose - options.quiet
   351         verbosity = options.verbose - options.quiet
   353         logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
   352         logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
   354 
   353 
   355         
   354 
   356         home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
   355         home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
   357         base_dir = os.path.dirname(home_dir)
   356         base_dir = os.path.dirname(home_dir)
   358         src_dir = os.path.join(home_dir, 'src')
   357         src_dir = os.path.join(home_dir, 'src')
   359         tmp_dir = os.path.join(home_dir, 'tmp')
   358         tmp_dir = os.path.join(home_dir, 'tmp')
   360         ensure_dir(src_dir, logger)
   359         ensure_dir(src_dir, logger)
   361         ensure_dir(tmp_dir, logger)
   360         ensure_dir(tmp_dir, logger)
   362         system_str = platform.system()
   361         system_str = platform.system()
   363                 
   362 
   364         res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
   363         res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
   365         if res_source_key is None:
   364         if res_source_key is None:
   366             res_source_key = 'local'
   365             res_source_key = 'local'
   367         
   366 
   368         ignore_packages = []
   367         ignore_packages = []
   369         
   368 
   370         if system_str == 'Windows':
   369         if system_str == 'Windows':
   371             default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}}
   370             default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}}
   372         else:
   371         else:
   373             default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}}
   372             default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}}
   374             
   373 
   375         if options.ignore_packages :
   374         if options.ignore_packages :
   376             ignore_packages = options.ignore_packages.split(",")
   375             ignore_packages = options.ignore_packages.split(",")
   377         
   376 
   378         logger.indent += 2
   377         logger.indent += 2
   379         try:    
   378         try:
   380             for key in res_env.NORMAL_INSTALL:
   379             for key in res_env.NORMAL_INSTALL:
   381                 install_options = None
   380                 install_options = None
   382                 if isinstance(key, dict):
   381                 if isinstance(key, dict):
   383                     install_options = key.get('install', default_install_options)
   382                     install_options = key.get('install', default_install_options)
   384                     install_options['method'] = 'pip-req'
   383                     install_options['method'] = 'pip-req'
   393                 method = install_options.get('method', default_install_options['method'])
   392                 method = install_options.get('method', default_install_options['method'])
   394                 option_str = install_options.get('option_str', default_install_options['option_str'])
   393                 option_str = install_options.get('option_str', default_install_options['option_str'])
   395                 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
   394                 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
   396                 if not extra_env:
   395                 if not extra_env:
   397                     extra_env = {}
   396                     extra_env = {}
   398                     
   397 
   399                 if 'TMPDIR' not in extra_env:
   398                 if 'TMPDIR' not in extra_env:
   400                     extra_env['TMPDIR'] = os.path.abspath(tmp_dir)
   399                     extra_env['TMPDIR'] = os.path.abspath(tmp_dir)
   401                 if system_str == 'Darwin':
   400                 if system_str == 'Darwin':
   402                     for flag_key, flag_value in iter(osx_extra_env.items()):
   401                     for flag_key, flag_value in iter(osx_extra_env.items()):
   403                         flags = extra_env.get(flag_key, '')
   402                         flags = extra_env.get(flag_key, '')
   404                         if flag_value not in flags:
   403                         if flag_value not in flags:
   405                             #flags += " -Wno-error=unused-command-line-argument-hard-error-in-future"
   404                             #flags += " -Wno-error=unused-command-line-argument-hard-error-in-future"
   406                             flags += " "+flag_value
   405                             flags += " "+flag_value
   407                             extra_env[flag_key] = flags.strip()
   406                             extra_env[flag_key] = flags.strip()
   408                     
   407 
   409                 #isinstance(lst, (list, tuple))
   408                 #isinstance(lst, (list, tuple))
   410                 if key not in ignore_packages:
   409                 if key not in ignore_packages:
   411                     logger.notify("install %s with method %s" % (key, repr(method)))
   410                     logger.notify("install %s with method %s" % (key, repr(method)))
   412                     if callable(method):
   411                     if callable(method):
   413                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   412                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   414                     elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:  
   413                     elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:
   415                         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)
   414                         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)
   416                     else:
   415                     else:
   417                         normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
   416                         normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
   418                             
   417 
   419             logger.notify("Clear source dir")
   418             logger.notify("Clear source dir")
   420             shutil.rmtree(src_dir)
   419             shutil.rmtree(src_dir)
   421     
   420 
   422         finally:
   421         finally:
   423             logger.indent -= 2
   422             logger.indent -= 2
   424         script_dir = join(base_dir, bin_dir)
   423         script_dir = join(base_dir, bin_dir)
   425         logger.notify('Run "%s Package" to install new packages that provide builds'
   424         logger.notify('Run "%s Package" to install new packages that provide builds'
   426                       % join(script_dir, 'easy_install'))
   425                       % join(script_dir, 'easy_install'))
   427     
   426 
   428     def adjust_options(options, args):
   427     def adjust_options(options, args):
   429         if not options_to_add:
   428         if not options_to_add:
   430             return
   429             return
   431         for opt,opt_val in options_to_add.items():
   430         for opt,opt_val in options_to_add.items():
   432             #if not hasattr(options,test_opt) or getattr(options, test_opt) is None:
   431             #if not hasattr(options,test_opt) or getattr(options, test_opt) is None:
   433             setattr(options, opt, opt_val)
   432             setattr(options, opt, opt_val)
   434 
   433 
   435     return adjust_options, extend_parser, after_install
   434     return adjust_options, extend_parser, after_install
   436