diff options
-rw-r--r-- | machammer/__init__.py (renamed from __init__.py) | 0 | ||||
-rw-r--r-- | machammer/functions.py (renamed from functions.py) | 18 | ||||
-rw-r--r-- | machammer/printers.py (renamed from printers.py) | 0 | ||||
-rw-r--r-- | machammer/system_profiler.py (renamed from system_profiler.py) | 0 | ||||
-rwxr-xr-x | machammer/tests.py (renamed from tests.py) | 0 |
5 files changed, 14 insertions, 4 deletions
diff --git a/__init__.py b/machammer/__init__.py index 645ecea..645ecea 100644 --- a/__init__.py +++ b/machammer/__init__.py diff --git a/functions.py b/machammer/functions.py index bf176ba..b7f13b1 100644 --- a/functions.py +++ b/machammer/functions.py @@ -6,13 +6,14 @@ import subprocess import sys import tempfile +from xml.parsers.expat import ExpatError from system_profiler import SystemProfile SERVICEDIR = '/Library/Services' -def call(**args): +def call(*args): """Shorthand for subprocess.call. > call('ls', '/Users') @@ -33,18 +34,22 @@ def display_notification(msg, title='', subtitle=''): msg = msg.replace('"', '\\"') title = title.replace('"', '\\"') subtitle = subtitle.replace('"', '\\"') - osascript('display notification "{0}" with title "{1}" subtitle "{2}"'.format(msg, title, subtitle)) + cmd = 'display notification "{0}" with title "{1}" subtitle "{2}"' + osascript(cmd.format(msg, title, subtitle)) def ditto(src, dst): + """Shortcut for ditto.""" subprocess.call(['/usr/bin/ditto', src, dst]) def rsync(src, dst, flags='auE'): + """Shortcut for rsync.""" subprocess.call(['/usr/bin/rsync', '-' + flags, src, dst]) def dscl(domain='.', *args): + """Shortcut for dscl.""" subprocess.call(['/usr/bin/dscl', domain] + args) @@ -114,7 +119,7 @@ def hide_user(username, hide_home=True): subprocess.call(['dscl', '.', 'create', path, 'IsHidden', '1']) if hide_home: - subprocess.call(['chflags', 'hidden', path]) + subprocess.call(['/usr/bin/chflags', 'hidden', path]) def delete_user(username, delete_home=True): @@ -157,7 +162,12 @@ def is_desktop(): def mount_image(dmg): """Mount disk image and return path to mountpoint.""" r = subprocess.check_output(['/usr/bin/hdiutil', 'mount', '-plist', '-nobrowse', dmg]) - plist = plistlib.readPlistFromString(r) + + try: + plist = plistlib.readPlistFromString(r) + except ExpatError: # probably a EULA-image, return None instead of breaking + return None + for p in [p.get('mount-point') for p in plist.get('system-entities')]: if p and os.path.exists(p): return p diff --git a/printers.py b/machammer/printers.py index d3c7539..d3c7539 100644 --- a/printers.py +++ b/machammer/printers.py diff --git a/system_profiler.py b/machammer/system_profiler.py index 81dfb69..81dfb69 100644 --- a/system_profiler.py +++ b/machammer/system_profiler.py diff --git a/tests.py b/machammer/tests.py index 6e9b28e..6e9b28e 100755 --- a/tests.py +++ b/machammer/tests.py |