<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function <EOL> import re <EOL> import tarfile <EOL> import json <EOL> from copy import deepcopy <EOL> from conda . compat import PY3 <EOL> if PY3 : <EOL> from io import StringIO , BytesIO <EOL> else : <EOL> from cStringIO import StringIO <EOL> BytesIO = StringIO <EOL> BAT_PROXY = """<STR_LIT>""" <EOL> libpy_pat = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' ) <EOL> def has_cext ( t , show = False ) : <EOL> matched = False <EOL> for m in t . getmembers ( ) : <EOL> match = libpy_pat . match ( m . path ) <EOL> if match : <EOL> if show : <EOL> x = match . group ( <NUM_LIT:3> ) <EOL> print ( "<STR_LIT>" , x . replace ( '<STR_LIT:/>' , '<STR_LIT:.>' ) ) <EOL> matched = True <EOL> else : <EOL> return True <EOL> return matched <EOL> def has_nonpy_entry_points ( t , unix_to_win = True , show = False , quiet = False ) : <EOL> """<STR_LIT>""" <EOL> if not quiet : <EOL> print ( "<STR_LIT>" ) <EOL> bindir = '<STR_LIT>' if unix_to_win else '<STR_LIT>' <EOL> matched = False <EOL> for m in t . getmembers ( ) : <EOL> if m . path . startswith ( bindir ) : <EOL> if not unix_to_win : <EOL> if show : <EOL> print ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return True <EOL> r = t . extractfile ( m ) . read ( ) <EOL> try : <EOL> r = r . decode ( '<STR_LIT:utf-8>' ) <EOL> except UnicodeDecodeError : <EOL> if show : <EOL> print ( "<STR_LIT>" % m . path ) <EOL> matched = True <EOL> else : <EOL> firstline = r . splitlines ( ) [ <NUM_LIT:0> ] <EOL> if '<STR_LIT>' not in firstline : <EOL> if show : <EOL> print ( "<STR_LIT>" % m . path ) <EOL> matched = True <EOL> else : <EOL> if show : <EOL> print ( "<STR_LIT>" % m . path ) <EOL> return matched <EOL> def tar_update ( source , dest , file_map , verbose = True , quiet = False ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( source , tarfile . TarFile ) : <EOL> s = source <EOL> else : <EOL> if not source . endswith ( ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> s = tarfile . open ( source ) <EOL> if isinstance ( dest , tarfile . TarFile ) : <EOL> t = dest <EOL> else : <EOL> t = tarfile . open ( dest , '<STR_LIT>' ) <EOL> try : <EOL> for m in s . getmembers ( ) : <EOL> p = m . path <EOL> if p in file_map : <EOL> if file_map [ p ] is None : <EOL> if verbose : <EOL> print ( '<STR_LIT>' % p ) <EOL> else : <EOL> if verbose : <EOL> print ( '<STR_LIT>' % ( p , file_map [ p ] ) ) <EOL> if isinstance ( file_map [ p ] , tarfile . TarInfo ) : <EOL> t . addfile ( file_map [ p ] , s . extractfile ( file_map [ p ] ) ) <EOL> elif isinstance ( file_map [ p ] , tuple ) : <EOL> t . addfile ( * file_map [ p ] ) <EOL> else : <EOL> t . add ( file_map [ p ] , p ) <EOL> continue <EOL> if not quiet : <EOL> print ( "<STR_LIT>" % p ) <EOL> t . addfile ( m , s . extractfile ( p ) ) <EOL> s_names_set = set ( m . path for m in s . getmembers ( ) ) <EOL> for p in sorted ( file_map ) : <EOL> if p not in s_names_set : <EOL> if verbose : <EOL> print ( '<STR_LIT>' % ( p , file_map [ p ] ) ) <EOL> if isinstance ( file_map [ p ] , tarfile . TarInfo ) : <EOL> t . addfile ( file_map [ p ] , s . extractfile ( file_map [ p ] ) ) <EOL> elif isinstance ( file_map [ p ] , tuple ) : <EOL> t . addfile ( * file_map [ p ] ) <EOL> else : <EOL> t . add ( file_map [ p ] , p ) <EOL> finally : <EOL> t . close ( ) <EOL> path_mapping_bat_proxy = [ <EOL> ( re . compile ( r'<STR_LIT>' ) , r'<STR_LIT>' ) , <EOL> ( re . compile ( r'<STR_LIT>' ) , r'<STR_LIT>' ) , <EOL> ] <EOL> path_mapping_unix_windows = [ <EOL> ( r'<STR_LIT>' , r'<STR_LIT>' ) , <EOL> ( r'<STR_LIT>' , r'<STR_LIT>' ) , <EOL> ( r'<STR_LIT>' , r'<STR_LIT>' ) , <EOL> ] <EOL> path_mapping_windows_unix = [ <EOL> ( r'<STR_LIT>' , r'<STR_LIT>' ) , <EOL> ( r'<STR_LIT>' , r'<STR_LIT>' ) , <EOL> ] <EOL> pyver_re = re . compile ( r'<STR_LIT>' ) <EOL> def get_pure_py_file_map ( t , platform ) : <EOL> info = json . loads ( t . extractfile ( '<STR_LIT>' ) . read ( ) . decode ( '<STR_LIT:utf-8>' ) ) <EOL> source_plat = info [ '<STR_LIT>' ] <EOL> source_type = '<STR_LIT>' if source_plat in { '<STR_LIT>' , '<STR_LIT>' } else '<STR_LIT>' <EOL> dest_plat , dest_arch = platform . split ( '<STR_LIT:->' ) <EOL> dest_type = '<STR_LIT>' if dest_plat in { '<STR_LIT>' , '<STR_LIT>' } else '<STR_LIT>' <EOL> files = t . extractfile ( '<STR_LIT>' ) . read ( ) . decode ( "<STR_LIT:utf-8>" ) <EOL> if source_type == '<STR_LIT>' and dest_type == '<STR_LIT>' : <EOL> mapping = path_mapping_unix_windows <EOL> elif source_type == '<STR_LIT>' and dest_type == '<STR_LIT>' : <EOL> mapping = path_mapping_windows_unix <EOL> else : <EOL> mapping = [ ] <EOL> newinfo = info . copy ( ) <EOL> newinfo [ '<STR_LIT>' ] = dest_plat <EOL> newinfo [ '<STR_LIT>' ] = '<STR_LIT>' if dest_arch == '<STR_LIT>' else '<STR_LIT>' <EOL> newinfo [ '<STR_LIT>' ] = platform <EOL> pythons = list ( filter ( None , [ pyver_re . match ( p ) for p in info [ '<STR_LIT>' ] ] ) ) <EOL> if len ( pythons ) > <NUM_LIT:1> : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> % t . name ) <EOL> if len ( pythons ) == <NUM_LIT:0> : <EOL> mapping = [ ] <EOL> else : <EOL> pyver = pythons [ <NUM_LIT:0> ] . group ( <NUM_LIT:1> ) <EOL> mapping = [ ( re . compile ( i [ <NUM_LIT:0> ] . format ( pyver = pyver ) ) , <EOL> i [ <NUM_LIT:1> ] . format ( pyver = pyver ) ) for i in mapping ] <EOL> members = t . getmembers ( ) <EOL> file_map = { } <EOL> for member in members : <EOL> if member . path == '<STR_LIT>' : <EOL> newmember = tarfile . TarInfo ( '<STR_LIT>' ) <EOL> if PY3 : <EOL> newbytes = bytes ( json . dumps ( newinfo ) , '<STR_LIT:utf-8>' ) <EOL> else : <EOL> newbytes = json . dumps ( newinfo ) <EOL> newmember . size = len ( newbytes ) <EOL> file_map [ '<STR_LIT>' ] = ( newmember , BytesIO ( newbytes ) ) <EOL> continue <EOL> elif member . path == '<STR_LIT>' : <EOL> filemember = deepcopy ( member ) <EOL> continue <EOL> elif member . path == '<STR_LIT>' : <EOL> if source_type == '<STR_LIT>' and dest_type == '<STR_LIT>' : <EOL> file_map [ '<STR_LIT>' ] = None <EOL> oldpath = member . path <EOL> for old , new in mapping : <EOL> newpath = old . sub ( new , oldpath ) <EOL> if oldpath in file_map : <EOL> break <EOL> if newpath != oldpath : <EOL> newmember = deepcopy ( member ) <EOL> newmember . path = newpath <EOL> assert member . path == oldpath <EOL> file_map [ oldpath ] = None <EOL> file_map [ newpath ] = newmember <EOL> files = files . replace ( oldpath , newpath ) <EOL> batseen = set ( ) <EOL> if source_type == '<STR_LIT>' and dest_type == '<STR_LIT>' : <EOL> for old , new in path_mapping_bat_proxy : <EOL> newpath = old . sub ( new , oldpath ) <EOL> if oldpath in batseen : <EOL> break <EOL> if newpath != oldpath : <EOL> newmember = tarfile . TarInfo ( newpath ) <EOL> if PY3 : <EOL> data = bytes ( BAT_PROXY . replace ( '<STR_LIT:\n>' , '<STR_LIT:\r\n>' ) , '<STR_LIT:ascii>' ) <EOL> else : <EOL> data = BAT_PROXY . replace ( '<STR_LIT:\n>' , '<STR_LIT:\r\n>' ) <EOL> newmember . size = len ( data ) <EOL> file_map [ newpath ] = newmember , BytesIO ( data ) <EOL> batseen . add ( oldpath ) <EOL> files = files + newpath + "<STR_LIT:\n>" <EOL> files = '<STR_LIT:\n>' . join ( sorted ( files . splitlines ( ) ) ) + '<STR_LIT:\n>' <EOL> if PY3 : <EOL> files = bytes ( files , '<STR_LIT:utf-8>' ) <EOL> filemember . size = len ( files ) <EOL> file_map [ '<STR_LIT>' ] = filemember , BytesIO ( files ) <EOL> return file_map </s>
