Python plistlib.readPlist() Examples

The following are 30 code examples of plistlib.readPlist(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module plistlib , or try the search function .
Example #1
Source File: platform.py    From Computable with MIT License 6 votes vote down vote up
def _mac_ver_xml():
    fn = '/System/Library/CoreServices/SystemVersion.plist'
    if not os.path.exists(fn):
        return None

    try:
        import plistlib
    except ImportError:
        return None

    pl = plistlib.readPlist(fn)
    release = pl['ProductVersion']
    versioninfo=('', '', '')
    machine = os.uname()[4]
    if machine in ('ppc', 'Power Macintosh'):
        # for compatibility with the gestalt based code
        machine = 'PowerPC'

    return release,versioninfo,machine 
Example #2
Source File: platform.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def _mac_ver_xml():
    fn = '/System/Library/CoreServices/SystemVersion.plist'
    if not os.path.exists(fn):
        return None

    try:
        import plistlib
    except ImportError:
        return None

    pl = plistlib.readPlist(fn)
    release = pl['ProductVersion']
    versioninfo=('', '', '')
    machine = os.uname()[4]
    if machine in ('ppc', 'Power Macintosh'):
        # for compatibility with the gestalt based code
        machine = 'PowerPC'

    return release,versioninfo,machine 
Example #3
Source File: pkg_resources.py    From pledgeservice with Apache License 2.0 6 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        import platform
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            import plistlib
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #4
Source File: platform.py    From meddle with MIT License 6 votes vote down vote up
def _mac_ver_xml():
    fn = '/System/Library/CoreServices/SystemVersion.plist'
    if not os.path.exists(fn):
        return None

    try:
        import plistlib
    except ImportError:
        return None

    pl = plistlib.readPlist(fn)
    release = pl['ProductVersion']
    versioninfo=('', '', '')
    machine = os.uname()[4]
    if machine in ('ppc', 'Power Macintosh'):
        # for compatibility with the gestalt based code
        machine = 'PowerPC'

    return release,versioninfo,machine 
Example #5
Source File: platform.py    From oss-ftp with MIT License 6 votes vote down vote up
def _mac_ver_xml():
    fn = '/System/Library/CoreServices/SystemVersion.plist'
    if not os.path.exists(fn):
        return None

    try:
        import plistlib
    except ImportError:
        return None

    pl = plistlib.readPlist(fn)
    release = pl['ProductVersion']
    versioninfo=('', '', '')
    machine = os.uname()[4]
    if machine in ('ppc', 'Power Macintosh'):
        # for compatibility with the gestalt based code
        machine = 'PowerPC'

    return release,versioninfo,machine 
Example #6
Source File: profile.py    From salt-osx with MIT License 6 votes vote down vote up
def items():
    '''
    Retrieve all profiles in full

    CLI Example:

    .. code-block:: bash

        salt '*' profiles.items
    '''
    tmpdir = tempfile.mkdtemp('.profiles')
    tmpfile = os.path.join(tmpdir, 'profiles.plist')

    status = __salt__['cmd.retcode']('/usr/bin/profiles -P -o {}'.format(tmpfile))

    if not status == 0:
        raise salt.exceptions.CommandExecutionError(
            'Failed to read profiles or write to temporary file'
        )

    profiles = plistlib.readPlist(tmpfile)
    os.unlink(tmpfile)
    os.rmdir(tmpdir)

    return profiles 
Example #7
Source File: pkg_resources.py    From oss-ftp with MIT License 6 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        import platform
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            import plistlib
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #8
Source File: gitV3.py    From WebTools.bundle with Mozilla Public License 2.0 6 votes vote down vote up
def getIdentifier(pluginDir):
            try:
                pFile = Core.storage.join_path(
                    self.PLUGIN_DIR, pluginDir, 'Contents', 'Info.plist')
                pl = plistlib.readPlist(pFile)
                createStamp = datetime.datetime.fromtimestamp(
                    os.path.getmtime(pFile)).strftime('%Y-%m-%d %H:%M:%S')
                return (pl['CFBundleIdentifier'], createStamp)
            except Exception, e:
                errMsg = str(e) + '\nfor something in directory: ' + \
                    Core.storage.join_path(self.PLUGIN_DIR, pluginDir)
                errMsg = errMsg + '\nSkipping migration of directory'
                Log.Error('Exception in Migrate/getIdentifier : ' + errMsg)
                pass

        # Main call 
Example #9
Source File: pfm2index.py    From profiledocs with MIT License 6 votes vote down vote up
def generate_item(manifest_path):
    print('processing: {}'.format(manifest_path))
    try:
        p = plistlib.readPlist(manifest_path)
        result = {
            'ManifestPath': manifest_path,
            'PayloadType': p['pfm_domain'],
            'PayloadDisplayName': p.get('pfm_title', None),
            'PayloadDescription': p['pfm_description'],
            'PayloadIOSMinVersion': p.get('pfm_ios_min', None),
            'PayloadIOSMaxVersion': p.get('pfm_ios_max', None),
            'PayloadMacOSMinVersion': p.get('pfm_macos_min', None),
            'PayloadMacOSMaxVersion': p.get('pfm_macos_max', None),
            'PayloadTvOSMinVersion': p.get('pfm_tvos_min', None),
            'PayloadTvOSMaxVersion': p.get('pfm_tvos_max', None),
            'PayloadSingleton': p.get('pfm_unique', False),
            'PayloadSupervisionRequired': p.get('pfm_supervised', False),
        }
    except ValueError as e:
        result = {'ManifestPath': manifest_path, 'error': True, 'errorMessage': e.message}
        print('skipping: {}'.format(manifest_path))
        pass

    return result 
Example #10
Source File: platform.py    From BinderFilter with MIT License 6 votes vote down vote up
def _mac_ver_xml():
    fn = '/System/Library/CoreServices/SystemVersion.plist'
    if not os.path.exists(fn):
        return None

    try:
        import plistlib
    except ImportError:
        return None

    pl = plistlib.readPlist(fn)
    release = pl['ProductVersion']
    versioninfo=('', '', '')
    machine = os.uname()[4]
    if machine in ('ppc', 'Power Macintosh'):
        # for compatibility with the gestalt based code
        machine = 'PowerPC'

    return release,versioninfo,machine 
Example #11
Source File: platform.py    From jawfish with MIT License 6 votes vote down vote up
def _mac_ver_xml():
    fn = '/System/Library/CoreServices/SystemVersion.plist'
    if not os.path.exists(fn):
        return None

    try:
        import plistlib
    except ImportError:
        return None

    pl = plistlib.readPlist(fn)
    release = pl['ProductVersion']
    versioninfo=('', '', '')
    machine = os.uname().machine
    if machine in ('ppc', 'Power Macintosh'):
        # for compatibility with the gestalt based code
        machine = 'PowerPC'

    return release,versioninfo,machine 
Example #12
Source File: __init__.py    From pex with Apache License 2.0 5 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #13
Source File: __init__.py    From pex with Apache License 2.0 5 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #14
Source File: __init__.py    From deepWordBug with Apache License 2.0 5 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #15
Source File: __init__.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #16
Source File: __init__.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #17
Source File: __init__.py    From deepWordBug with Apache License 2.0 5 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #18
Source File: test_device.py    From aeios with MIT License 5 votes vote down vote up
def test_existing_record_updated2(self):
        new = {'deviceName':'iPad', 'firmwareVersion':'12.0',
               'locationID':'0x14100001', 'buildVersion': '15E303'}
        d = device.Device(self.ecid, info=new, path=self.dir)
        
        result = plistlib.readPlist(d.file)
        for k in new.keys():
            self.assertNotEqual(result[k], self.orig[k]) 
Example #19
Source File: test_device.py    From aeios with MIT License 5 votes vote down vote up
def test_existing_record_no_info(self):
        d = device.Device(self.ecid, path=self.dir)
        for key,value in plistlib.readPlist(d.file).items():
            self.assertEquals(self.orig[key], value) 
Example #20
Source File: workflow.py    From Gank-Alfred-Workflow with MIT License 5 votes vote down vote up
def _load_info_plist(self):
        """Load workflow info from ``info.plist``

        """

        self._info = plistlib.readPlist(self._info_plist)
        self._info_loaded = True 
Example #21
Source File: test_device.py    From aeios with MIT License 5 votes vote down vote up
def test_device_record_no_extra_keys(self):
        d = device.Device(self.ecid, info=self.data, path=self.dir)
        result = plistlib.readPlist(d.file)
        for k in result.keys():
            self.assertIsNotNone(self.data.get(k)) 
Example #22
Source File: test_device.py    From aeios with MIT License 5 votes vote down vote up
def test_device_record_has_all_keys(self):
        d = device.Device(self.ecid, info=self.data, path=self.dir)
        result = plistlib.readPlist(d.file)
        self.assertEquals(result, self.data) 
Example #23
Source File: test_device.py    From aeios with MIT License 5 votes vote down vote up
def test_device_record_has_keys(self):
        data = {'UDID': self.udid,
                'ECID': self.ecid, 
                'deviceType': self.devicetype}
        d = device.Device(self.ecid, info=data, path=self.dir)
        for key, value in plistlib.readPlist(d.file).items():
            expected = self.data.get(key)
            self.assertEquals(expected, value) 
Example #24
Source File: config.py    From aeios with MIT License 5 votes vote down vote up
def read(self):
        """
        :returns: data structure (list|dict) as read from disk
        :raises: ConfigError if unable to read
        """
        if not os.path.exists(self.file):
            raise Missing("file missing: {0}".format(self.file))

        try:
            with self.lock.acquire():
                return plistlib.readPlist(self.file)
        except xml.parsers.expat.ExpatError:
            raise ConfigError("corrupted plist: {0}".format(self.file))

    # TYPE SPECIFIC FUNCTIONS 
Example #25
Source File: test_plistlib.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_stringio(self):
        from StringIO import StringIO
        f = StringIO()
        pl = self._create()
        plistlib.writePlist(pl, f)
        pl2 = plistlib.readPlist(StringIO(f.getvalue()))
        self.assertEqual(dict(pl), dict(pl2)) 
Example #26
Source File: test_plistlib.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_io(self):
        pl = self._create()
        plistlib.writePlist(pl, test_support.TESTFN)
        pl2 = plistlib.readPlist(test_support.TESTFN)
        self.assertEqual(dict(pl), dict(pl2)) 
Example #27
Source File: pkg_resources.py    From oss-ftp with MIT License 5 votes vote down vote up
def _macosx_vers(_cache=[]):
    if not _cache:
        version = platform.mac_ver()[0]
        # fallback for MacPorts
        if version == '':
            plist = '/System/Library/CoreServices/SystemVersion.plist'
            if os.path.exists(plist):
                if hasattr(plistlib, 'readPlist'):
                    plist_content = plistlib.readPlist(plist)
                    if 'ProductVersion' in plist_content:
                        version = plist_content['ProductVersion']

        _cache.append(version.split('.'))
    return _cache[0] 
Example #28
Source File: AutoNBI.py    From autonbi with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getosversioninfo(mountpoint):
    """"getosversioninfo will attempt to retrieve the OS X version and build
        from the given mount point by reading /S/L/CS/SystemVersion.plist
        Most of the code comes from COSXIP without changes."""

    # Check for availability of BaseSystem.dmg
    basesystem_dmg = os.path.join(mountpoint, 'BaseSystem.dmg')
    if not os.path.isfile(basesystem_dmg):
        unmountdmg(mountpoint)
        fail('Missing BaseSystem.dmg in %s' % mountpoint)

    # Mount BaseSystem.dmg
    basesystemmountpoints, unused_shadowpath = mountdmg(basesystem_dmg)
    basesystemmountpoint = basesystemmountpoints[0]

    # Read SystemVersion.plist from the mounted BaseSystem.dmg
    system_version_plist = os.path.join(
        basesystemmountpoint,
        'System/Library/CoreServices/SystemVersion.plist')
    # Now parse the .plist file
    try:
        version_info = plistlib.readPlist(system_version_plist)

    # Got errors?
    except (ExpatError, IOError), err:
        unmountdmg(basesystemmountpoint)
        unmountdmg(mountpoint)
        fail('Could not read %s: %s' % (system_version_plist, err))

    # Done, unmount BaseSystem.dmg 
Example #29
Source File: generate-manifest.py    From viewfinder with Apache License 2.0 5 votes vote down vote up
def generate_manifest(self, app_name):
		filename = self.info_plist_filename()
		info_plist_filepath = os.path.join(options.app_bundle, filename)
		info_plist_xml_filename = 'info_plist.xml'
		# Use plutil to ensure that we are dealing with XML rather than the binary format
		subprocess.Popen('plutil -convert xml1 -o ' + info_plist_xml_filename + ' ' + "'" + info_plist_filepath + "'", shell=True).wait()
		info_plist_xml_file = open(info_plist_xml_filename, 'r')
		app_plist = plistlib.readPlist(info_plist_xml_file)
		os.remove(info_plist_xml_filename)
		MANIFEST_FILENAME = 'manifest.plist'
		manifest_plist = {
				'items' : [
					{
						'assets' : [
							{
								'kind' : 'software-package',
								'url' : urlparse.urljoin(options.deployment_address, app_name + '.ipa'),
								}
							],
						'metadata' : {
							'bundle-identifier' : app_plist['CFBundleIdentifier'],
							'bundle-version' : app_plist['CFBundleVersion'],
							'kind' : 'software',
							'title' : app_plist['CFBundleName'],
							}
						}
					]
				}
		plistlib.writePlist(manifest_plist, MANIFEST_FILENAME)
		return MANIFEST_FILENAME 
Example #30
Source File: generate-manifest.py    From viewfinder with Apache License 2.0 5 votes vote down vote up
def generate_manifest(self, app_name):
		filename = self.info_plist_filename()
		info_plist_filepath = os.path.join(options.app_bundle, filename)
		info_plist_xml_filename = 'info_plist.xml'
		# Use plutil to ensure that we are dealing with XML rather than the binary format
		subprocess.Popen('plutil -convert xml1 -o ' + info_plist_xml_filename + ' ' + "'" + info_plist_filepath + "'", shell=True).wait()
		info_plist_xml_file = open(info_plist_xml_filename, 'r')
		app_plist = plistlib.readPlist(info_plist_xml_file)
		os.remove(info_plist_xml_filename)
		MANIFEST_FILENAME = 'manifest.plist'
		manifest_plist = {
				'items' : [
					{
						'assets' : [
							{
								'kind' : 'software-package',
								'url' : urlparse.urljoin(options.deployment_address, app_name + '.ipa'),
								}
							],
						'metadata' : {
							'bundle-identifier' : app_plist['CFBundleIdentifier'],
							'bundle-version' : app_plist['CFBundleVersion'],
							'kind' : 'software',
							'title' : app_plist['CFBundleName'],
							}
						}
					]
				}
		plistlib.writePlist(manifest_plist, MANIFEST_FILENAME)
		return MANIFEST_FILENAME