<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function , unicode_literals <EOL> import os <EOL> import tempfile <EOL> import shutil <EOL> import tarfile <EOL> import sys <EOL> import yaml <EOL> from vcstools . vcs_base import VcsClientBase , VcsError <EOL> from vcstools . common import urlretrieve_netrc , ensure_dir_notexists <EOL> __pychecker__ = '<STR_LIT>' <EOL> _METADATA_FILENAME = "<STR_LIT>" <EOL> class TarClient ( VcsClientBase ) : <EOL> def __init__ ( self , path ) : <EOL> """<STR_LIT>""" <EOL> VcsClientBase . __init__ ( self , '<STR_LIT>' , path ) <EOL> self . metadata_path = os . path . join ( self . _path , _METADATA_FILENAME ) <EOL> @ staticmethod <EOL> def get_environment_metadata ( ) : <EOL> metadict = { } <EOL> metadict [ "<STR_LIT:version>" ] = '<STR_LIT>' % tarfile . version <EOL> return metadict <EOL> def get_url ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . detect_presence ( ) : <EOL> with open ( self . metadata_path , '<STR_LIT:r>' ) as metadata_file : <EOL> metadata = yaml . load ( metadata_file . read ( ) ) <EOL> if '<STR_LIT:url>' in metadata : <EOL> return metadata [ '<STR_LIT:url>' ] <EOL> return None <EOL> @ staticmethod <EOL> def static_detect_presence ( path ) : <EOL> return os . path . isfile ( os . path . join ( path , _METADATA_FILENAME ) ) <EOL> def checkout ( self , url , version = '<STR_LIT>' , verbose = False , <EOL> shallow = False , timeout = None ) : <EOL> """<STR_LIT>""" <EOL> if not ensure_dir_notexists ( self . get_path ( ) ) : <EOL> self . logger . error ( "<STR_LIT>" % self . get_path ( ) ) <EOL> return False <EOL> tempdir = None <EOL> result = False <EOL> try : <EOL> tempdir = tempfile . mkdtemp ( ) <EOL> if os . path . isfile ( url ) : <EOL> filename = url <EOL> else : <EOL> ( filename , _ ) = urlretrieve_netrc ( url ) <EOL> temp_tarfile = tarfile . open ( filename , '<STR_LIT>' ) <EOL> members = None <EOL> if version == '<STR_LIT>' or version is None : <EOL> subdir = tempdir <EOL> self . logger . warn ( "<STR_LIT>" % url ) <EOL> else : <EOL> subdirs = [ ] <EOL> members = [ ] <EOL> for m in temp_tarfile . getmembers ( ) : <EOL> if m . name . startswith ( version + '<STR_LIT:/>' ) : <EOL> members . append ( m ) <EOL> if m . name . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] not in subdirs : <EOL> subdirs . append ( m . name . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] ) <EOL> if not members : <EOL> raise VcsError ( "<STR_LIT>" % ( version , subdirs ) ) <EOL> subdir = os . path . join ( tempdir , version ) <EOL> temp_tarfile . extractall ( path = tempdir , members = members ) <EOL> if not os . path . isdir ( subdir ) : <EOL> raise VcsError ( "<STR_LIT>" % subdir ) <EOL> try : <EOL> shutil . move ( subdir , self . _path ) <EOL> except Exception as ex : <EOL> raise VcsError ( "<STR_LIT>" % ( ex , subdir , self . _path ) ) <EOL> metadata = yaml . dump ( { '<STR_LIT:url>' : url , '<STR_LIT:version>' : version } ) <EOL> with open ( self . metadata_path , '<STR_LIT:w>' ) as mdat : <EOL> mdat . write ( metadata ) <EOL> result = True <EOL> except Exception as exc : <EOL> self . logger . error ( "<STR_LIT>" % str ( exc ) ) <EOL> finally : <EOL> if tempdir is not None and os . path . exists ( tempdir ) : <EOL> shutil . rmtree ( tempdir ) <EOL> return result <EOL> def update ( self , version = '<STR_LIT>' , verbose = False , timeout = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . detect_presence ( ) : <EOL> return False <EOL> if version != self . get_version ( ) : <EOL> sys . stderr . write ( "<STR_LIT>" <EOL> % ( version , self . get_version ( ) ) ) <EOL> return False <EOL> return True <EOL> def get_version ( self , spec = None ) : <EOL> if self . detect_presence ( ) : <EOL> with open ( self . metadata_path , '<STR_LIT:r>' ) as metadata_file : <EOL> metadata = yaml . load ( metadata_file . read ( ) ) <EOL> if '<STR_LIT:version>' in metadata : <EOL> return metadata [ '<STR_LIT:version>' ] <EOL> return None <EOL> def get_current_version_label ( self ) : <EOL> return None <EOL> def get_remote_version ( self , fetch = False ) : <EOL> return None <EOL> def get_diff ( self , basepath = None ) : <EOL> return '<STR_LIT>' <EOL> def get_status ( self , basepath = None , untracked = False ) : <EOL> return '<STR_LIT>' <EOL> def export_repository ( self , version , basepath ) : <EOL> raise VcsError ( '<STR_LIT>' ) <EOL> TARClient = TarClient </s>
