virtualenv/res/lib/lib_create_env.py
author cavaliet
Thu, 17 Jul 2014 15:39:28 +0200
changeset 295 af29252631ac
parent 292 f6742c41d7a3
child 345 7bc38c7d6cf9
permissions -rw-r--r--
renkan object with thumbnail
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import sys
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import os
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import os.path
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import shutil
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import tarfile
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
import zipfile
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import urllib
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import platform
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
import patch
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    10
import struct
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    11
import glob
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    12
import re
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
join = os.path.join
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
system_str = platform.system()
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
URLS = {
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    #'': {'setup': '', 'url':'', 'local':''},
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    19
    'DISTRIBUTE': {'setup': 'distribute', 'url':'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.24.tar.gz', 'local':"distribute-0.6.24.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
271
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    20
    'DJANGO': {'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.6.5/tarball/', 'local':"Django-1.6.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    21
    'DJANGO-EXTENSIONS': { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/tarball/1.3.7', 'local':"django-extensions-1.3.7.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
292
f6742c41d7a3 user form management with django registration
cavaliet
parents: 272
diff changeset
    22
    'REGISTRATION': { 'setup': 'registration', 'url':'https://bitbucket.org/LinnTroll/django-registration-1.5/get/c71d5b8e2735.zip', 'local':"django-registration-1.5-c71d5b8e2735.zip", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    23
    'HTTPLIB2': { 'setup': 'python-httplib2', 'url':'http://code.google.com/p/httplib2/downloads/detail?name=httplib2-0.7.4.tar.gz&can=2&q=', 'local':"httplib2-0.7.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
271
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    24
    'SOUTH': { 'setup': 'South', 'url':'http://www.aeracode.org/releases/south/south-0.8.4.tar.gz', 'local':"south-0.8.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    25
    'PYCRYPTO': {'setup': 'pycrypto', 'url':'https://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz', 'local':'pycrypto-2.6.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    26
    'SSH': {'setup': 'ssh', 'url':'http://pypi.python.org/packages/source/s/ssh/ssh-1.7.14.tar.gz#md5=4cdd0549ef4699bd67b96264d3b21427', 'local':'ssh-1.7.14.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    27
    'FABRIC': {'setup': 'fabric', 'url':'https://github.com/fabric/fabric/tarball/1.4.2', 'local':'fabric-1.4.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    28
    'MERCURIAL': {'setup': 'mercurial', 'url':'http://mercurial.selenic.com/release/mercurial-2.2.3.tar.gz', 'local':'mercurial-2.2.3.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
271
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    29
    'HAYSTACK': {'setup': 'django-haystack', 'url': 'https://github.com/toastdriven/django-haystack/archive/v2.1.0.tar.gz', 'local': 'django-haystack-2.1.0.tar.gz', 'install':{'method':'pip', 'option_str': None, 'dict_extra_env': None}},
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    30
    'WHOOSH': {'setup': 'whoosh', 'url':'https://pypi.python.org/packages/source/W/Whoosh/Whoosh-2.5.7.tar.gz', 'local':'whoosh-2.5.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    31
    'WIKITOOLS' : { 'setup': 'wikitools', 'url': 'wikitools.tar.bz2', 'local': 'wikitools.tar.bz2', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    32
    'ISODATE' : {'setup': 'isodate', 'url': 'http://pypi.python.org/packages/source/i/isodate/isodate-0.4.8.tar.gz', 'local': 'isodate-0.4.8.tar.gz', 'install' : {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    33
    'RDFLIB' : { 'setup': 'rdflib', 'url': 'http://rdflib.googlecode.com/files/rdflib-3.2.0.tar.gz', 'local': 'rdflib-3.2.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    34
    'SPARQLWRAPPER' : { 'setup': 'SPARQLWrapper', 'url': 'http://downloads.sourceforge.net/project/sparql-wrapper/sparql-wrapper-python/1.5.0/SPARQLWrapper-1.5.0.tar.gz', 'local' : 'SPARQLWrapper-1.5.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},    
271
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    35
    'REQUESTS' : { 'setup': 'requests', 'url': 'https://github.com/kennethreitz/requests/archive/v2.3.0.tar.gz', 'local' : 'requests-2.3.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},    
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    36
    'PYELASTICSEARCH' : { 'setup': 'pyelasticsearch', 'url': 'https://github.com/rhec/pyelasticsearch/archive/0.6.1.tar.gz', 'local' : 'pyelasticsearch-0.6.1.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},    
295
af29252631ac renkan object with thumbnail
cavaliet
parents: 292
diff changeset
    37
    'PIL' : { 'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local' : 'Imaging-1.1.7.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},    
af29252631ac renkan object with thumbnail
cavaliet
parents: 292
diff changeset
    38
    'EASYTHUMBNAIL' : { 'setup': 'easythumbnail', 'url': 'https://github.com/SmileyChris/easy-thumbnails/archive/2.0.1.tar.gz', 'local' : 'easy-thumbnails-2.0.1.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},    
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
}
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
if system_str == 'Windows':
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    42
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    43
    size = 8 * struct.calcsize("P")
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    44
    if size==32:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    45
        mysqlres = "MySQL-python-1.2.3.win32-py2.7.exe"
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    46
    else:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    47
        mysqlres = "MySQL-python-1.2.3.win-amd64-py2.7.exe"
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    48
    
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    URLS.update({
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    50
        'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip', 'local':"psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip", 'install': {'method': 'install_psycopg2', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    51
        'PIL': {'setup': 'pil', 'url': 'http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.6.exe', 'local':"PIL-1.1.7.win32-py2.6.exe", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    52
        'LXML': {'setup': 'lxml', 'url': 'http://pypi.python.org/packages/2.6/l/lxml/lxml-2.2.2-py2.6-win32.egg', 'local':"lxml-2.2.2-py2.6-win32.egg", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    53
        'PYYAML' : { 'setup': 'PyYAML', 'url': 'http://pyyaml.org/download/pyyaml/PyYAML-3.09.win32-py2.6.exe', 'local': 'PyYAML-3.09.win32-py2.6.exe', 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
10
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
    54
        'PYSTEMMER' : { 'setup': 'pystemmer', 'url': 'PyStemmer_compiled_for_pc.zip', 'local': 'PyStemmer_compiled_for_pc.zip'},
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
    })
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
else:
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    57
    if system_str == "Darwin":        
271
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    58
        lxml_options = {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.9.1', 'LIBXSLT_VERSION': '1.1.28', 'LIBICONV_VERSION': '1.14'}
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    59
        lxml_method = 'easy_install'
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    60
        mysql_method = 'install_mysql'
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    61
    else:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    62
        lxml_options = None
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    63
        lxml_method = 'pip'
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    64
        mysql_method = 'pip'
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    65
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
    URLS.update({
271
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    67
        'PSYCOPG2': {'setup': 'psycopg2','url': 'https://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.5.3.tar.gz', 'local':"psycopg2-2.5.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    68
        'PIL': {'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local':"Imaging-1.1.7.tar.gz", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
271
8f77cf71ab02 commit the venv update (django and dependancies) in the good head
cavaliet
parents: 258
diff changeset
    69
        '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}},
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    70
        'PYYAML' : { 'setup': 'PyYAML', 'url': 'http://pyyaml.org/download/pyyaml/PyYAML-3.09.tar.gz', 'local': 'PyYAML-3.09.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    })
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    72
    
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
class ResourcesEnv(object):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    def __init__(self, src_base, urls, normal_installs):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
        self.src_base = src_base
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
        self.URLS = {}
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
        self.__init_url(urls)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
        self.NORMAL_INSTALL = normal_installs
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
    def get_src_base_path(self, fpath):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
        return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
    
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    85
    def __add_package_def(self, key, dict):
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    86
        self.URLS[key] = dict
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    87
        
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    def __init_url(self, urls):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
        for key, url_dict in urls.items():
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    90
            url_dict_copy = url_dict.copy()
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    91
            if not url_dict['url'].startswith("http://"):
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    92
                url_dict_copy['url'] = self.get_src_base_path(url_dict['url'])
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    93
            url_dict_copy['local'] = self.get_src_base_path(url_dict['local'])            
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    94
            
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
    95
            self.__add_package_def(key, url_dict_copy )
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
def ensure_dir(dir, logger):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
    if not os.path.exists(dir):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
        logger.notify('Creating directory %s' % dir)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        os.makedirs(dir)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
def extend_parser(parser):    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
    parser.add_option(
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
        '--index-url',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        metavar='INDEX_URL',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
        dest='index_url',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
        default='http://pypi.python.org/simple/',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
        help='base URL of Python Package Index')
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    parser.add_option(
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
        '--type-install',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
        metavar='type_install',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
        dest='type_install',
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   113
        help='type install : local, url, setup - default : local')
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
    parser.add_option(
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
        '--ignore-packages',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
        metavar='ignore_packages',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
        dest='ignore_packages',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
        default=None,
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   119
        help='list of comma separated keys for package to ignore')    
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
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):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
    psycopg2_src = os.path.join(src_dir,"psycopg2.zip")
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
    shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
    #extract psycopg2
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
    zf = zipfile.ZipFile(psycopg2_src)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
    psycopg2_base_path = os.path.join(src_dir,"psycopg2")
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
    zf.extractall(psycopg2_base_path)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
    zf.close()
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
    psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
    shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   132
    shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.0.14-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'site-packages')))
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   133
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   134
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   135
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):
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   136
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   137
    args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]                
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   138
    if option_str :
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   139
        args.insert(4,option_str)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   140
    call_subprocess(args,
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   141
            cwd=os.path.abspath(tmp_dir),
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   142
            filter_stdout=filter_python_develop,
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   143
            show_stdout=True,
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   144
            extra_env=extra_env)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   145
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   146
    mysqlconfig_output = []
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   147
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   148
    call_subprocess(['mysql_config', '--libmysqld-libs'],
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   149
        cwd=os.path.abspath(tmp_dir),
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   150
        filter_stdout=lambda line: mysqlconfig_output.append(line),
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   151
        show_stdout=True)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   152
        
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   153
    mysqlconfig_output = "".join(mysqlconfig_output)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   154
    m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   155
    if m:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   156
        repdylibpath = m.group(1)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   157
    else:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   158
        repdylibpath = '/usr/local/mysql/lib'
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   159
        
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   160
    dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   161
    def key_func(s):
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   162
        m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   163
        if m:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   164
            return int(m.group(1))
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   165
        else:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   166
            return sys.maxint
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   167
    dyliblist.sort(key=key_func)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   168
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   169
    if dyliblist:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   170
        dylibpath = dyliblist[0]
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   171
    else:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   172
        dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   173
        
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   174
    dylibname = os.path.basename(dylibpath)    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   175
    sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   176
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   177
    call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   178
        cwd=os.path.abspath(tmp_dir),
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   179
        filter_stdout=filter_python_develop,
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   180
        show_stdout=True)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   181
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   182
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   183
def gen_install_comp_lib(lib_name, lib_key, configure_options=[]):
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   184
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   185
    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):
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   186
        lib_src = os.path.join(src_dir,lib_name+".tar.gz")
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   187
        shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   188
        tf = tarfile.open(lib_src,'r:gz')
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   189
        lib_base_path = os.path.join(src_dir, lib_name) 
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   190
        logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   191
        tf.extractall(lib_base_path)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   192
        tf.close()
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   193
        
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   194
        lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   195
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   196
        logger.notify(libname + " configure")
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   197
        call_subprocess(['configure', '--prefix='+os.path.abspath(home_dir)] + configure_options,
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   198
                        cwd=os.path.abspath(lib_src_path),
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   199
                        filter_stdout=filter_python_develop,
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   200
                        show_stdout=True)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   201
        
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   202
        logger.notify(libname + " make")
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   203
        call_subprocess(['make'],
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   204
                        cwd=os.path.abspath(lib_src_path),
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   205
                        filter_stdout=filter_python_develop,
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   206
                        show_stdout=True)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   207
    
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   208
        logger.notify(libname + "make install")
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   209
        call_subprocess(['make', 'install'],
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   210
                        cwd=os.path.abspath(lib_src_path),
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   211
                        filter_stdout=filter_python_develop,
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   212
                        show_stdout=True)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   213
        return install_lib
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   214
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   215
install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared'])
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   216
install_zlib = gen_install_comp_lib("zlib", "ZLIB", [])
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
10
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   218
def install_pystemmer(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   219
    print "install PYSTEMMER from " + res_env.URLS['PYSTEMMER'][res_source_key]
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   220
    pystemmer_src = os.path.join(src_dir,"pystemmer.zip")
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   221
    shutil.copy(res_env.URLS['PYSTEMMER'][res_source_key], pystemmer_src)
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   222
    #extract pystemmer
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   223
    zf = zipfile.ZipFile(pystemmer_src)
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   224
    pystemmer_base_path = os.path.join(src_dir,"pystemmer")
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   225
    zf.extractall(pystemmer_base_path)
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   226
    zf.close()
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   227
    
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   228
    shutil.copy(os.path.join(pystemmer_base_path, 'Stemmer.pyd'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages')))
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   229
    shutil.copy(os.path.join(pystemmer_base_path, 'PyStemmer-1.0.1-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages')))
9ea5f8ba8e71 Update create env for PyStemmer on PC.
cavaliet
parents: 2
diff changeset
   230
    
2
b380dc74b590 add import csv command + first test
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   232
def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
    all_urls = URLS.copy()
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
    if urls is not None:
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
        all_urls.update(urls)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
        
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
    res_env = ResourcesEnv(src_base, all_urls, normal_installs)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
    def filter_python_develop(line):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
        if not line.strip():
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
            return Logger.DEBUG
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
        for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
                       'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
                       'creating ', 'Copying ']:
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
            if line.startswith(prefix):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
                return Logger.DEBUG
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
        return Logger.NOTIFY
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
    def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
        logger.notify("Install %s from %s with %s" % (key,res_env.URLS[key][res_source_key],method))
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
        if method == 'pip':
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
            if sys.platform == 'win32':
141
444108d080bc correct virtualenv creation script
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   255
                args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_env.URLS[key][res_source_key]]
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
            else:
141
444108d080bc correct virtualenv creation script
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   257
                args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS[key][res_source_key]]
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
            if option_str :
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
                args.insert(4,option_str)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
            call_subprocess(args,
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
                    cwd=os.path.abspath(tmp_dir),
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
                    filter_stdout=filter_python_develop,
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
                    show_stdout=True,
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
                    extra_env=extra_env)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
        else:
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
            if sys.platform == 'win32':
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
                args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_env.URLS[key][res_source_key]]
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
            else:
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
                args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_env.URLS[key][res_source_key]]
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
            if option_str :
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
                args.insert(1,option_str)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
            call_subprocess(args,
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
                    cwd=os.path.abspath(tmp_dir),
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
                    filter_stdout=filter_python_develop,
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
                    show_stdout=True,
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
                    extra_env=extra_env)            
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
    def after_install(options, home_dir):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
        
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
        global logger
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
        
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
        verbosity = options.verbose - options.quiet
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
        logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
        
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
        home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
        base_dir = os.path.dirname(home_dir)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
        src_dir = os.path.join(home_dir, 'src')
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
        tmp_dir = os.path.join(home_dir, 'tmp')
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
        ensure_dir(src_dir, logger)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
        ensure_dir(tmp_dir, logger)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
        system_str = platform.system()
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   294
                
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   295
        res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   296
        if res_source_key is None:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   297
            res_source_key = local
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
        
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
        ignore_packages = []
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
        
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   301
        if system_str == 'Windows':
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   302
            default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   303
        else:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   304
            default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': None}
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   305
            
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
        if options.ignore_packages :
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
            ignore_packages = options.ignore_packages.split(",")
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
        
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
        logger.indent += 2
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
        try:    
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   311
            for key in res_env.NORMAL_INSTALL:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   312
                if key not in res_env.URLS:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   313
                    logger.notify("%s not found in def : passing" % (key,))
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   314
                install_options = res_env.URLS[key].get('install', None)
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   315
                if install_options is None:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   316
                    install_options = default_install_options
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   317
                method = install_options.get('method', default_install_options['method'])
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   318
                option_str = install_options.get('option_str', default_install_options['option_str'])
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   319
                extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   320
                #isinstance(lst, (list, tuple))
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
                if key not in ignore_packages:
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
                    if callable(method):
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
                        method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   324
                    elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:  
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   325
                        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)
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
                    else:
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
                        normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
                            
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
            logger.notify("Clear source dir")
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
            shutil.rmtree(src_dir)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
    
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
        finally:
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
            logger.indent -= 2
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
        script_dir = join(base_dir, bin_dir)
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
        logger.notify('Run "%s Package" to install new packages that provide builds'
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
                      % join(script_dir, 'easy_install'))
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
    
243
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   338
    def adjust_options(options, args):
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   339
        if not options_to_add:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   340
            pass
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   341
        for opt in options_to_add:
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   342
            test_opt = opt.split('=',1)[0]
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   343
            if not hasattr(options,test_opt) or getattr(options, test_opt) is None:                
1f2840354865 correct filter on tag completion to avoid tags that are not translated
ymh <ymh.work@gmail.com>
parents: 176
diff changeset
   344
                setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True)
0
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
896db0083b76 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
    return adjust_options, extend_parser, after_install