#NEWLINE# def stats( path , hash_type = 'sha256' , follow_symlinks = True ) : #NEWLINE# #INDENT# "\n    Return a dict containing the stats for a given file\n\n    Under Windows, `gid` will equal `uid` and `group` will equal `user`.\n\n    While a file in Windows does have a 'primary group', this rarely used\n    attribute generally has no bearing on permissions unless intentionally\n    configured and is only used to support Unix compatibility features (e.g.\n    Services For Unix, NFS services).\n\n    Salt, therefore, remaps these properties to keep some kind of\n    compatibility with Unix behavior. If the 'primary group' is required, it\n    can be accessed in the `pgroup` and `pgid` properties.\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' file.stats /etc/passwd\n    " #NEWLINE# ret = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( not os . path . exists ( path ) ) : #NEWLINE# #INDENT# return ret #NEWLINE# #UNINDENT# if ( follow_symlinks and ( sys . getwindowsversion ( ) . major >= 6 ) ) : #NEWLINE# #INDENT# path = _resolve_symlink ( path ) #NEWLINE# #UNINDENT# pstat = os . stat ( path ) #NEWLINE# ret [ 'inode' ] = pstat . st_ino #NEWLINE# ret [ 'uid' ] = get_uid ( path , follow_symlinks = False ) #NEWLINE# ret [ 'gid' ] = ret [ 'uid' ] #NEWLINE# ret [ 'user' ] = uid_to_user ( ret [ 'uid' ] ) #NEWLINE# ret [ 'group' ] = ret [ 'user' ] #NEWLINE# ret [ 'pgid' ] = get_pgid ( path , follow_symlinks ) #NEWLINE# ret [ 'pgroup' ] = gid_to_group ( ret [ 'pgid' ] ) #NEWLINE# ret [ 'atime' ] = pstat . st_atime #NEWLINE# ret [ 'mtime' ] = pstat . st_mtime #NEWLINE# ret [ 'ctime' ] = pstat . st_ctime #NEWLINE# ret [ 'size' ] = pstat . st_size #NEWLINE# ret [ 'mode' ] = str ( oct ( stat . S_IMODE ( pstat . st_mode ) ) ) #NEWLINE# if hash_type : #NEWLINE# #INDENT# ret [ 'sum' ] = get_sum ( path , hash_type ) #NEWLINE# #UNINDENT# ret [ 'type' ] = 'file' #NEWLINE# if stat . S_ISDIR ( pstat . st_mode ) : #NEWLINE# #INDENT# ret [ 'type' ] = 'dir' #NEWLINE# #UNINDENT# if stat . S_ISCHR ( pstat . st_mode ) : #NEWLINE# #INDENT# ret [ 'type' ] = 'char' #NEWLINE# #UNINDENT# if stat . S_ISBLK ( pstat . st_mode ) : #NEWLINE# #INDENT# ret [ 'type' ] = 'block' #NEWLINE# #UNINDENT# if stat . S_ISREG ( pstat . st_mode ) : #NEWLINE# #INDENT# ret [ 'type' ] = 'file' #NEWLINE# #UNINDENT# if stat . S_ISLNK ( pstat . st_mode ) : #NEWLINE# #INDENT# ret [ 'type' ] = 'link' #NEWLINE# #UNINDENT# if stat . S_ISFIFO ( pstat . st_mode ) : #NEWLINE# #INDENT# ret [ 'type' ] = 'pipe' #NEWLINE# #UNINDENT# if stat . S_ISSOCK ( pstat . st_mode ) : #NEWLINE# #INDENT# ret [ 'type' ] = 'socket' #NEWLINE# #UNINDENT# ret [ 'target' ] = os . path . realpath ( path ) #NEWLINE# return ret