Example #1
0
 def load_growl(self):
     if self.loaded_growl.isSet():
         return
     try:
         TRACE('Loading Growl...')
         pool = NSAutoreleasePool.alloc().init()
         if self.GrowlApplicationBridge is None:
             bundle_path = '%s/Growl.framework' % get_frameworks_dir()
             env = {}
             objc.loadBundle('GrowlApplicationBridge', env, bundle_path=bundle_path)
             self.GrowlApplicationBridge = env['GrowlApplicationBridge']
             installed = self.GrowlApplicationBridge.isGrowlInstalled()
             running = self.GrowlApplicationBridge.isGrowlRunning()
             TRACE('Growl is installed? %r; Growl is running? %r', installed, running)
         if running:
             TRACE('Initializing Growl Delegate')
             self.GrowlApplicationBridge.setGrowlDelegate_(self)
         else:
             return
     except Exception:
         unhandled_exc_handler()
         self.growl_had_problems = True
         TRACE('Growl had problems, tossing ability to notify out the window')
     else:
         self.growl_had_problems = False
         self.growlIsReady()
Example #2
0
def natural_basename_sort_cmp(bn1, bn2):
    pool = NSAutoreleasePool.alloc().init()
    try:
        return NSString.compare_options_(bn1, bn2, NSCaseInsensitiveSearch | NSNumericSearch)
    except Exception:
        unhandled_exc_handler()
        return natural_sort_cmp(bn1, bn2)
    finally:
        del pool
Example #3
0
 def do_bubble(self, message, caption, ctx_ref):
     TRACE('DropboxGrowlBridge: Bubbling: %s', message)
     pool = NSAutoreleasePool.alloc().init()
     try:
         if ctx_ref is not None:
             ctx_ref = NSNumber.numberWithInt_(ctx_ref)
         self.GrowlApplicationBridge.notifyWithTitle_description_notificationName_iconData_priority_isSticky_clickContext_(unicode(caption), unicode(message), u'File Updates', None, 0, False, ctx_ref)
     finally:
         del pool
Example #4
0
def dialog():
    from AppKit import NSApplication, NSAutoreleasePool, NSOpenPanel

    app = NSApplication.sharedApplication()
    assert app
    pool = NSAutoreleasePool.alloc().init()
    assert pool
    panel = NSOpenPanel.openPanel()
    panel.setCanChooseFiles_(True)
    if panel.runModal():
        return panel.URL().path()
    return None
Example #5
0
def dialog():
    from AppKit import NSApplication, NSAutoreleasePool, NSOpenPanel

    app = NSApplication.sharedApplication()
    assert app
    pool = NSAutoreleasePool.alloc().init()
    assert pool
    panel = NSOpenPanel.openPanel()
    panel.setCanChooseFiles_(True)
    if panel.runModal():
        return panel.URL().path()
    return None
Example #6
0
    def get_text(self):
        result = None

        pool = NSAutoreleasePool.alloc().init()
        new_count = self.pasteboard.changeCount()

        if self.current_count != new_count:
            self.current_count = new_count
            result = self.pasteboard.stringForType_(NSStringPboardType)

        del pool

        return result
Example #7
0
def decide_dmg_action(curr_instance_path, default_app_folder_path, give_us_permissions_cb, kill_other_instances = None, skip_mount_point_check = False):
    TRACE('starting decide_dmg_action %s, %s, %s, %s', curr_instance_path, default_app_folder_path, give_us_permissions_cb, kill_other_instances)
    curr_instance_path = curr_instance_path.rstrip('/')
    if not skip_mount_point_check:
        if not is_on_installer(curr_instance_path):
            return
    prev_installation = find_previous_installation()
    if prev_installation and not is_on_installer(prev_installation):
        app_folder_path = prev_installation
    else:
        app_folder_path = default_app_folder_path
    TRACE('find_previous_installation() returned %r, installing into %r', prev_installation, app_folder_path)
    app_target = os.path.join(app_folder_path, u'%s.app' % (BUILD_KEY,))
    launch_exe = os.path.join(app_target, u'Contents', u'MacOS', BUILD_KEY)
    launch_args = [launch_exe, u'/firstrunupdatemanual' if os.path.exists(app_target) else u'/firstrun']
    if kill_other_instances:
        kill_other_instances()
    did_exist_previously = os.path.exists(app_target)
    handle, temp_file_path = tempfile.mkstemp()
    try:
        os.close(handle)
    except Exception:
        unhandled_exc_handler()

    noqtn = '--noqtn' if MAC_VERSION >= LEOPARD else ''
    try:
        with open(temp_file_path, 'w') as temp_file:
            script = u'#!/bin/bash\n/bin/rm -rf %(app_target)s\n[ ! -e %(app_target)s ] && /usr/bin/ditto %(noqtn)s %(curr_instance_path)s %(app_target)s\n'
            script %= dict(app_target=shell_quote(app_target), curr_instance_path=shell_quote(curr_instance_path), noqtn=noqtn)
            script = script.encode('utf-8')
            temp_file.write(script)
        success = False
        try:
            proc = subprocess.Popen(['/bin/sh', temp_file_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
            stdout, stderr = proc.communicate()
            returncode = proc.returncode
            if stdout:
                TRACE('installer script stdout: %s' % (stdout,))
            if stderr:
                TRACE('installer script stderr: %s' % (stderr,))
            proc.stdout.close()
            proc.stderr.close()
            TRACE('installer script returncode: %s', returncode)
            success = _plist_identical(curr_instance_path, app_target)
        except OSError as e:
            if did_exist_previously and not os.path.exists(app_target):
                report_bad_assumption('In first pass, double-click install deleted old installation at %s but failed to install new one', app_target)
            if e.errno != errno.EACCES:
                raise

        if not success:
            try:
                if not give_us_permissions_cb:
                    return
                safe_activate_translation()
                msg = trans(u'Please enter your computer admin password for Dropbox to finish installing.')
                retval, output = give_us_permissions_cb('/bin/sh', [temp_file_path], msg + u'\n\n')
                if output:
                    TRACE('installer script with elevated permissions output: %s', output)
                TRACE('installer script with elevated permissions returned %s', retval)
                if not retval:
                    return
            except Exception:
                unhandled_exc_handler()
                return

    finally:
        try:
            os.unlink(temp_file_path)
        except Exception:
            unhandled_exc_handler()

    pool = NSAutoreleasePool.alloc().init()
    try:
        ws = NSWorkspace.sharedWorkspace()
        ws.noteFileSystemChanged_(app_target)
    except Exception:
        pass
    finally:
        del pool

    return launch_args
Example #8
0
 def pooled_func(*args):
     pool = NSAutoreleasePool.alloc().init()
     data = f(*args)
     del pool
     return data