def append_key(path, key, nstype, value): ''' Append an item to an array within a property list file. path An absolute path to a property list (.plist) file, including the extension key The specification of the key to append an element to. A list of keys separated by a colon. .. code-block:: bash salt '*' plist.append_key <path> <key> <nstype> <value> ''' log.debug('Reading original plist for modification at path: %s' % path) root = _read_plist(path) log.debug('Deriving key hierarchy from colon separated string') keys = key.split(':') if type(keys) is str: keys = list(keys) if root is None: raise salt.exceptions.SaltInvocationError( 'Tried to append to non existing file, not currently supported.') log.debug('Performing string to NSObject conversion') nsval = _value_to_nsobject(value, nstype) log.debug('Setting object value in hierarchy') if len(keys) > 1: parent = _object_for_key_list(root, keys[:-1]) else: parent = root log.debug('Updating or creating object at key: {}'.format(keys[-1])) collection = parent.objectForKey_(keys[-1]) # This is destructive if the key value is already another type if collection is None or type(collection) is not NSMutableArray: collection = NSMutableArray() parent.setObject_forKey_(collection, keys[-1]) collection.addObject_(nsval) log.debug('Writing out plist to original path') from pprint import pprint pprint(root) xml_plist = _generate_plist_string(root, NSPropertyListXMLFormat_v1_0) log.debug(xml_plist) _write_plist(root, path)
def getPasswords(): a = NSMutableArray() for pw in pwd.getpwall(): a.append({ "name": pw.pw_name, "password": pw.pw_passwd, "uid": str(pw.pw_uid), "gid": str(pw.pw_gid), "gecos": pw.pw_gecos, "home_dir": pw.pw_dir, "shell": pw.pw_shell, }) return a
def getPasswords(): a = NSMutableArray() for pw in pwd.getpwall(): a.append({ 'name': pw.pw_name, 'password': pw.pw_passwd, 'uid': str(pw.pw_uid), 'gid': str(pw.pw_gid), 'gecos': pw.pw_gecos, 'home_dir': pw.pw_dir, 'shell': pw.pw_shell, }) return a