def untar_file(filename, location):
if not os.path.exists(location):<EOL><INDENT>os.makedirs(location)<EOL><DEDENT>if filename.lower().endswith('<STR_LIT>') or filename.lower().endswith('<STR_LIT>'):<EOL><INDENT>mode = '<STR_LIT>'<EOL><DEDENT>elif (filename.lower().endswith('<STR_LIT>')<EOL>or filename.lower().endswith('<STR_LIT>')):<EOL><INDENT>mode = '<STR_LIT>'<EOL><DEDENT>elif filename.lower().endswith('<STR_LIT>'):<EOL><INDENT>mode = '<STR_LIT:r>'<EOL><DEDENT>else:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>', filename,<EOL>)<EOL>mode = '<STR_LIT>'<EOL><DEDENT>tar = tarfile.open(filename, mode)<EOL>try:<EOL><INDENT>leading = has_leading_dir([<EOL>member.name for member in tar.getmembers()<EOL>if member.name != '<STR_LIT>'<EOL>])<EOL>for member in tar.getmembers():<EOL><INDENT>fn = member.name<EOL>if fn == '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>if leading:<EOL><INDENT>fn = split_leading_dir(fn)[<NUM_LIT:1>]<EOL><DEDENT>path = os.path.join(location, fn)<EOL>if member.isdir():<EOL><INDENT>if not os.path.exists(path):<EOL><INDENT>os.makedirs(path)<EOL><DEDENT><DEDENT>elif member.issym():<EOL><INDENT>try:<EOL><INDENT>tar._extract_member(member, path)<EOL><DEDENT>except Exception as exc:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>filename, member.name, exc,<EOL>)<EOL>continue<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>fp = tar.extractfile(member)<EOL><DEDENT>except (KeyError, AttributeError) as exc:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>',<EOL>filename, member.name, exc,<EOL>)<EOL>continue<EOL><DEDENT>if not os.path.exists(os.path.dirname(path)):<EOL><INDENT>os.makedirs(os.path.dirname(path))<EOL><DEDENT>destfp = open(path, '<STR_LIT:wb>')<EOL>try:<EOL><INDENT>shutil.copyfileobj(fp, destfp)<EOL><DEDENT>finally:<EOL><INDENT>destfp.close()<EOL><DEDENT>fp.close()<EOL>if member.mode & <NUM_LIT>:<EOL><INDENT>os.chmod(path, (<NUM_LIT> - current_umask() | <NUM_LIT>))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>tar.close()<EOL><DEDENT>
Untar the file (with path `filename`) to the destination `location`.
All files are written based on system defaults and umask (i.e. permissions
are not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written.  Note that for windows, any execute changes using os.chmod are
no-ops per the python docs.