5151
5252
5353logger = logging .getLogger (__name__ )
54- DEBUG = False
55- DEBUG_DEEP = False
56- # import sys
57- # logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
58- # logger.setLevel(logging.DEBUG)
54+ TRACE = False
55+ TRACE_DEEP = False
56+
57+ if TRACE :
58+ import sys
59+ logging .basicConfig (stream = sys .stdout )
60+ logger .setLevel (logging .DEBUG )
5961
6062
6163
@@ -176,15 +178,16 @@ def get_handlers(location):
176178 mime_matched = handler .mimetypes and any (m in mtype for m in handler .mimetypes )
177179 extension_matched = handler .extensions and location .lower ().endswith (handler .extensions )
178180
179- if DEBUG_DEEP :
180- logger .debug ('get_handlers: %(location)s: ftype: %(ftype)s, mtype: %(mtype)s ' % locals ())
181+ if TRACE_DEEP :
182+ handler_name = handler .name
183+ logger .debug ('get_handlers: considering %(handler_name)r handler for %(location)s: ftype: %(ftype)s, mtype: %(mtype)s ' % locals ())
181184 logger .debug ('get_handlers: %(location)s: matched type: %(type_matched)s, mime: %(mime_matched)s, ext: %(extension_matched)s' % locals ())
182185
183186 if handler .strict and not all ([type_matched , mime_matched , extension_matched ]):
184187 continue
185188
186189 if type_matched or mime_matched or extension_matched :
187- if DEBUG_DEEP :
190+ if TRACE_DEEP :
188191 logger .debug ('get_handlers: %(location)s: matched type: %(type_matched)s, mime: %(mime_matched)s, ext: %(extension_matched)s' % locals ())
189192 logger .debug ('get_handlers: %(location)s: handler: %(handler)r' % locals ())
190193 yield handler , type_matched , mime_matched , extension_matched
@@ -300,7 +303,7 @@ def extract_twice(location, target_dir, extractor1, extractor2):
300303 # extract first the intermediate payload to a temp dir
301304 temp_target = unicode (fileutils .get_temp_dir ('extract' ))
302305 warnings = extractor1 (abs_location , temp_target )
303- if DEBUG :
306+ if TRACE :
304307 logger .debug ('extract_twice: temp_target: %(temp_target)r' % locals ())
305308
306309 # extract this intermediate payload to the final target_dir
@@ -310,7 +313,7 @@ def extract_twice(location, target_dir, extractor1, extractor2):
310313 warnings .append (location + ': No files found in archive.' )
311314 else :
312315 for extracted1_loc in inner_archives :
313- if DEBUG :
316+ if TRACE :
314317 logger .debug ('extract_twice: extractor2: %(extracted1_loc)r' % locals ())
315318 warnings .extend (extractor2 (extracted1_loc , abs_target_dir ))
316319 finally :
@@ -334,14 +337,14 @@ def extract_with_fallback(location, target_dir, extractor1, extractor2):
334337 temp_target1 = unicode (fileutils .get_temp_dir ('extract1' ))
335338 try :
336339 warnings = extractor1 (abs_location , temp_target1 )
337- if DEBUG :
340+ if TRACE :
338341 logger .debug ('extract_with_fallback: temp_target1: %(temp_target1)r' % locals ())
339342 fileutils .copytree (temp_target1 , abs_target_dir )
340343 except :
341344 try :
342345 temp_target2 = unicode (fileutils .get_temp_dir ('extract2' ))
343346 warnings = extractor2 (abs_location , temp_target2 )
344- if DEBUG :
347+ if TRACE :
345348 logger .debug ('extract_with_fallback: temp_target2: %(temp_target2)r' % locals ())
346349 fileutils .copytree (temp_target2 , abs_target_dir )
347350 finally :
@@ -375,6 +378,7 @@ def extract_with_fallback(location, target_dir, extractor1, extractor2):
375378extract_nsis = sevenzip .extract
376379extract_ishield = sevenzip .extract
377380extract_Z = sevenzip .extract
381+ extract_xarpkg = sevenzip .extract
378382
379383
380384# Archive handlers.
@@ -799,6 +803,26 @@ def extract_with_fallback(location, target_dir, extractor1, extractor2):
799803 strict = True
800804)
801805
806+ ApplePkgHandler = Handler (
807+ name = 'Apple pkg or mpkg package installer' ,
808+ filetypes = ('xar archive' ,),
809+ mimetypes = ('application/octet-stream' ,),
810+ extensions = ('.pkg' , '.mpkg' ,),
811+ kind = package ,
812+ extractors = [extract_xarpkg ],
813+ strict = True
814+ )
815+
816+ XarHandler = Handler (
817+ name = 'Xar archive v1' ,
818+ filetypes = ('xar archive' ,),
819+ mimetypes = ('application/octet-stream' ,),
820+ extensions = ('.xar' ,),
821+ kind = package ,
822+ extractors = [extract_xarpkg ],
823+ strict = True
824+ )
825+
802826IsoImageHandler = Handler (
803827 name = 'ISO CD image' ,
804828 filetypes = ('iso 9660 cd-rom' , 'high sierra cd-rom' ,),
@@ -858,6 +882,8 @@ def extract_with_fallback(location, target_dir, extractor1, extractor2):
858882 RarHandler ,
859883 CabHandler ,
860884 MsiInstallerHandler ,
885+ ApplePkgHandler ,
886+ XarHandler ,
861887 # notes: this may catch all exe and fails too often
862888 InstallShieldHandler ,
863889 NSISInstallerHandler ,
0 commit comments