Skip to content

Instantly share code, notes, and snippets.

@jessepeterson
Created January 24, 2017 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessepeterson/4053def24038a72d72cbfabc3120fc8c to your computer and use it in GitHub Desktop.
Save jessepeterson/4053def24038a72d72cbfabc3120fc8c to your computer and use it in GitHub Desktop.
changed dmgmounter.py behavior
import os
class DmgMounter(object):
"""Base class for Processors that need to mount disk images."""
DMG_EXTENSIONS = ['.dmg', '.iso', '.DMG', '.ISO']
#pylint: disable=invalid-name
def parsePathForDMG(self, pathname):
"""Helper method for working with paths that reference something
inside a disk image"""
for extension in self.DMG_EXTENSIONS:
(dmg_path, dmg, dmg_source_path) = (
pathname.partition(extension + "/"))
if dmg:
dmg_path += extension
return dmg_path, dmg, dmg_source_path
# no disk image in path
return pathname, '', ''
#pylint: enable=invalid-name
#pylint: disable=invalid-name
def parsePathForDMG2(self, pathname):
"""Helper method for working with paths that reference something
inside a disk image"""
dmg_path = os.path.normpath(pathname)
dmg_source_path = ''
while dmg_path != '/':
for extension in self.DMG_EXTENSIONS:
found_ext = os.path.splitext(dmg_path)[1]
if found_ext == extension:
# we return the found extension with a trailing slash
# to match the previous implementation
return dmg_path, found_ext + '/', dmg_source_path
dmg_path, tail = os.path.split(dmg_path)
dmg_source_path = os.path.normpath(os.path.join(
tail, dmg_source_path))
# no disk image in path
return pathname, '', ''
#pylint: enable=invalid-name
x = DmgMounter()
(dmg_path, dmg, dmg_source_path) = x.parsePathForDMG('/tmp/Foo.dmg')
assert dmg == ''
(dmg_path, dmg, dmg_source_path) = x.parsePathForDMG2('/tmp/Foo.dmg')
assert dmg == ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment