<s> '''<STR_LIT>''' <EOL> import subprocess <EOL> from tempfile import mkdtemp <EOL> import os <EOL> from xml . dom . minidom import parse , parseString <EOL> from hashlib import md5 <EOL> import plistlib <EOL> XAR_PATH = '<STR_LIT>' <EOL> MD5_CHUNK_SIZE = <NUM_LIT> * <NUM_LIT> * <NUM_LIT:10> <EOL> def pkg_signed ( filename ) : <EOL> xar_args = [ XAR_PATH , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> filename ] <EOL> p = subprocess . Popen ( xar_args , stdout = subprocess . PIPE ) <EOL> toc , _ = p . communicate ( ) <EOL> if p . returncode != <NUM_LIT:0> : <EOL> return False <EOL> toc_md = parseString ( toc ) <EOL> return len ( toc_md . getElementsByTagName ( '<STR_LIT>' ) ) > <NUM_LIT:0> <EOL> def get_pkg_bundle_ids ( filename ) : <EOL> '''<STR_LIT>''' <EOL> tmp_dir = mkdtemp ( ) <EOL> print '<STR_LIT>' , tmp_dir <EOL> xar_args = [ XAR_PATH , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:/>' , <EOL> '<STR_LIT>' , tmp_dir , <EOL> '<STR_LIT>' , filename , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> rtn = subprocess . call ( xar_args ) <EOL> tmp_dist_file = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> tmp_pinf_file = os . path . join ( tmp_dir , '<STR_LIT>' ) <EOL> pkgs = [ ] <EOL> bundles = [ ] <EOL> if os . path . exists ( tmp_dist_file ) : <EOL> dist_md = parse ( tmp_dist_file ) <EOL> for i in dist_md . getElementsByTagName ( '<STR_LIT>' ) : <EOL> if i . hasAttribute ( '<STR_LIT:version>' ) : <EOL> pkgs . append ( ( i . getAttribute ( '<STR_LIT:id>' ) , i . getAttribute ( '<STR_LIT:version>' ) ) ) <EOL> for i in dist_md . getElementsByTagName ( '<STR_LIT>' ) : <EOL> bundles . append ( ( i . getAttribute ( '<STR_LIT:id>' ) , i . getAttribute ( '<STR_LIT>' ) ) ) <EOL> print '<STR_LIT>' <EOL> os . unlink ( tmp_dist_file ) <EOL> if os . path . exists ( tmp_pinf_file ) : <EOL> pinf_md = parse ( tmp_pinf_file ) <EOL> for i in pinf_md . getElementsByTagName ( '<STR_LIT>' ) : <EOL> pkgs . append ( ( i . getAttribute ( '<STR_LIT>' ) , i . getAttribute ( '<STR_LIT:version>' ) ) ) <EOL> print '<STR_LIT>' <EOL> os . unlink ( tmp_pinf_file ) <EOL> print '<STR_LIT>' <EOL> os . rmdir ( tmp_dir ) <EOL> return ( pkgs , bundles ) <EOL> def get_chunked_md5 ( filename , chunksize = MD5_CHUNK_SIZE ) : <EOL> h = md5 ( ) <EOL> md5s = [ ] <EOL> total_hash = md5 ( ) <EOL> with open ( filename , '<STR_LIT:rb>' ) as f : <EOL> for chunk in iter ( lambda : f . read ( chunksize ) , b'<STR_LIT>' ) : <EOL> new_hash = md5 ( ) <EOL> new_hash . update ( chunk ) <EOL> total_hash . update ( chunk ) <EOL> md5s . append ( new_hash . hexdigest ( ) ) <EOL> return ( total_hash . hexdigest ( ) , md5s ) </s>
