__setuptools_hack__.py
changeset 6522 c46b3b3291e8
parent 6515 6e998b1be7fd
parent 6521 8c8529db5f83
child 6523 67bff8734a5b
equal deleted inserted replaced
6515:6e998b1be7fd 6522:c46b3b3291e8
     1 from os import path as osp
       
     2 import sys
       
     3 import os
       
     4 
       
     5 def in_egg(path):
       
     6     head, tail = osp.split(path)
       
     7     while tail:
       
     8         if tail.endswith('.egg'):
       
     9             return True
       
    10         head, tail = osp.split(head)
       
    11     return False
       
    12 
       
    13 if in_egg(__file__):
       
    14     from cubicweb.cwconfig import _find_prefix
       
    15     INSTALL_PREFIX = _find_prefix()
       
    16     if not osp.exists(osp.join(INSTALL_PREFIX, 'share', 'cubicweb', 'migration')):
       
    17         print >> sys.stderr, 'copying cubicweb content to the expected location'
       
    18         from shutil import copytree
       
    19         import tarfile
       
    20         import tempfile
       
    21         from pkg_resources import Requirement, resource_filename
       
    22         from functools import partial
       
    23         file_path = partial(resource_filename, Requirement.parse("cubicweb"))
       
    24         for df in ('share', 'lib'):
       
    25             # Tar are used to merge with destination directory
       
    26             tmp_file = tempfile.NamedTemporaryFile(suffix='.tar')
       
    27             tmp_tar  = tarfile.TarFile(tmp_file.name, mode='w')
       
    28             tmp_tar.add(file_path(df), arcname=df)
       
    29             tmp_tar  = tarfile.TarFile(tmp_file.name, mode='r')
       
    30             tmp_tar.extractall(path=INSTALL_PREFIX)