<s> from __future__ import absolute_import , print_function <EOL> import os <EOL> import shutil <EOL> import sys <EOL> import tempfile <EOL> import tarfile <EOL> if sys . version_info . major > <NUM_LIT:2> : <EOL> from urllib . request import urlretrieve <EOL> else : <EOL> from urllib import urlretrieve <EOL> ARCHIVE_URL = '<STR_LIT>' <EOL> def copy_indexes ( archive ) : <EOL> extract_dir = os . path . dirname ( archive ) <EOL> src_dir = os . path . join ( extract_dir , '<STR_LIT>' ) <EOL> dst_dir = os . path . expanduser ( '<STR_LIT>' ) <EOL> with tarfile . open ( archive , '<STR_LIT>' ) as tf : <EOL> tf . extractall ( extract_dir ) <EOL> if not os . path . exists ( dst_dir ) : <EOL> os . makedirs ( dst_dir ) <EOL> for name in os . listdir ( src_dir ) : <EOL> if name . endswith ( '<STR_LIT>' ) : <EOL> src = os . path . join ( src_dir , name ) <EOL> dst = os . path . join ( dst_dir , name ) <EOL> copy = True <EOL> if os . path . exists ( dst ) : <EOL> copy = _prompt_overwrite ( dst ) <EOL> if copy : <EOL> shutil . copy ( src , dst ) <EOL> def download_cinspect_data_archive ( url = None ) : <EOL> if url is None : <EOL> url = ARCHIVE_URL <EOL> t = tempfile . mkdtemp ( ) <EOL> print ( '<STR_LIT>' , t ) <EOL> filename = os . path . join ( t , '<STR_LIT>' ) <EOL> reporthook = lambda x , y , z : _spin ( <NUM_LIT:5> ) <EOL> urlretrieve ( url , filename , reporthook ) <EOL> print ( '<STR_LIT>' , filename ) <EOL> return filename <EOL> def _prompt_overwrite ( path ) : <EOL> if sys . version_info . major > <NUM_LIT:2> : <EOL> ask = input <EOL> else : <EOL> ask = raw_input <EOL> answer = ask ( '<STR_LIT>' % path ) <EOL> return True if answer . strip ( ) . lower ( ) [ : <NUM_LIT:1> ] == '<STR_LIT:y>' else False <EOL> def _spin ( every , state = [ '<STR_LIT:|>' , <NUM_LIT:0> ] ) : <EOL> if state [ <NUM_LIT:1> ] >= every : <EOL> state [ <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> if state [ <NUM_LIT:1> ] == <NUM_LIT:0> : <EOL> sigils = '<STR_LIT>' <EOL> state [ <NUM_LIT:0> ] = sigils [ ( sigils . index ( state [ <NUM_LIT:0> ] ) + <NUM_LIT:1> ) % <NUM_LIT:4> ] <EOL> sys . stderr . write ( '<STR_LIT:\r>' + state [ <NUM_LIT:0> ] ) <EOL> sys . stderr . flush ( ) <EOL> state [ <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> def main ( ) : <EOL> copy_indexes ( download_cinspect_data_archive ( ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
