Exemplo n.º 1
0
def getRunningBlockingApps(appnames):
    """Given a list of app names, return a list of friendly names
    for apps in the list that are running"""
    proc_list = getRunningProcesses()
    running_apps = []
    filemanager = NSFileManager.alloc().init()
    for appname in appnames:
        matching_items = []
        if appname.startswith('/'):
            # search by exact path
            matching_items = [item for item in proc_list
                              if item == appname]
        elif appname.endswith('.app'):
            # search by filename
            matching_items = [item for item in proc_list
                              if '/'+ appname + '/Contents/MacOS/' in item]
        else:
            # check executable name
            matching_items = [item for item in proc_list
                              if item.endswith('/' + appname)]

        if not matching_items:
            # try adding '.app' to the name and check again
            matching_items = [item for item in proc_list
                              if '/' + appname + '.app/Contents/MacOS/' in item]

        matching_items = set(matching_items)
        for path in matching_items:
            while '/Contents/' in path or path.endswith('/Contents'):
                path = os.path.dirname(path)
            # ask NSFileManager for localized name since end-users
            # will see this name
            running_apps.append(filemanager.displayNameAtPath_(path))

    return list(set(running_apps))
Exemplo n.º 2
0
def getRunningBlockingApps(appnames):
    """Given a list of app names, return a list of dicts for apps in the list
    that are running. Each dict contains username, pathname, display_name"""
    proc_list = getRunningProcessesWithUsers()
    running_apps = []
    filemanager = NSFileManager.alloc().init()
    for appname in appnames:
        matching_items = []
        if appname.startswith("/"):
            # search by exact path
            matching_items = [item for item in proc_list if item["pathname"] == appname]
        elif appname.endswith(".app"):
            # search by filename
            matching_items = [item for item in proc_list if "/" + appname + "/Contents/MacOS/" in item["pathname"]]
        else:
            # check executable name
            matching_items = [item for item in proc_list if item["pathname"].endswith("/" + appname)]

        if not matching_items:
            # try adding '.app' to the name and check again
            matching_items = [item for item in proc_list if "/" + appname + ".app/Contents/MacOS/" in item["pathname"]]

        # matching_items = set(matching_items)
        for item in matching_items:
            path = item["pathname"]
            while "/Contents/" in path or path.endswith("/Contents"):
                path = os.path.dirname(path)
            # ask NSFileManager for localized name since end-users
            # will see this name
            item["display_name"] = filemanager.displayNameAtPath_(path)
            running_apps.append(item)

    return running_apps
Exemplo n.º 3
0
def getRunningBlockingApps(appnames):
    """Given a list of app names, return a list of friendly names
    for apps in the list that are running"""
    proc_list = getRunningProcesses()
    running_apps = []
    filemanager = NSFileManager.alloc().init()
    for appname in appnames:
        matching_items = []
        if appname.endswith('.app'):
            # search by filename
            matching_items = [item for item in proc_list
                              if '/'+ appname + '/' in item]
        else:
            # check executable name
            matching_items = [item for item in proc_list
                              if item.endswith('/' + appname)]

        if not matching_items:
            # try adding '.app' to the name and check again
            matching_items = [item for item in proc_list
                              if '/' + appname + '.app/' in item]

        matching_items = set(matching_items)
        for path in matching_items:
            while '/Contents/' in path or path.endswith('/Contents'):
                path = os.path.dirname(path)
            # ask NSFileManager for localized name since end-users
            # will see this name
            running_apps.append(filemanager.displayNameAtPath_(path))

    return list(set(running_apps))
Exemplo n.º 4
0
def get_mounted_network_volumes():
    '''Uses Foundation.NSFileManager to get mounted volumes. is_network_volume() is called
        to filter out volumes that are not of type "smbfs"'''
    #pylint: disable=C0103
    fm = NSFileManager.alloc().init()
    mounts = fm.mountedVolumeURLsIncludingResourceValuesForKeys_options_(
        None, 0)
    mount_paths = []
    for mount in mounts:
        mount_path = mount.fileSystemRepresentation()
        if is_network_volume(mount_path):
            mount_paths.append(mount_path)
    return mount_paths
Exemplo n.º 5
0
def getRunningBlockingApps(appnames):
    """Given a list of app names, return a list of dicts for apps in the list
    that are running. Each dict contains username, pathname, display_name"""
    proc_list = getRunningProcessesWithUsers()
    running_apps = []
    filemanager = NSFileManager.alloc().init()
    for appname in appnames:
        matching_items = []
        if appname.startswith('/'):
            # search by exact path
            matching_items = [
                item for item in proc_list if item['pathname'] == appname
            ]
        elif appname.endswith('.app'):
            # search by filename
            matching_items = [
                item for item in proc_list
                if '/' + appname + '/Contents/MacOS/' in item['pathname']
            ]
        else:
            # check executable name
            matching_items = [
                item for item in proc_list
                if item['pathname'].endswith('/' + appname)
            ]

        if not matching_items:
            # try adding '.app' to the name and check again
            matching_items = [
                item for item in proc_list
                if '/' + appname + '.app/Contents/MacOS/' in item['pathname']
            ]

        #matching_items = set(matching_items)
        for item in matching_items:
            path = item['pathname']
            while '/Contents/' in path or path.endswith('/Contents'):
                path = os.path.dirname(path)
            # ask NSFileManager for localized name since end-users
            # will see this name
            item['display_name'] = filemanager.displayNameAtPath_(path)
            running_apps.append(item)

    return running_apps