Python stat 模块,ST_ATIME 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用stat.ST_ATIME

项目:donkey    作者:wroscoe    | 项目源码 | 文件源码
def clips_of_tub(self, tub_path):
        seqs = [ int(f.split("_")[0]) for f in os.listdir(tub_path) if f.endswith('.jpg') ]
        seqs.sort()

        entries = ((os.stat(self.image_path(tub_path, seq))[ST_ATIME], seq) for seq in seqs)

        (last_ts, seq) = next(entries)
        clips = [[seq]]
        for next_ts, next_seq in entries:
            if next_ts - last_ts > 100:  #greater than 1s apart
                clips.append([next_seq])
            else:
                clips[-1].append(next_seq)
            last_ts = next_ts

        return clips
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def getatime(self):
        st = self.statinfo
        if not st:
            self.restat()
            st = self.statinfo
        return st[ST_ATIME]
项目:locasploit    作者:lightfaith    | 项目源码 | 文件源码
def get_file_info(system, path, verbose=False):
    fullpath = get_fullpath(system, path)
    if fullpath == IO_ERROR:
        return IO_ERROR

    result = {}    
    if system.startswith('/'): # local or sub
        if can_read(system, path):
            # TODO platform-specific
            stats = os.stat(fullpath)
            stm = stats.st_mode
            result['type'] = get_file_type_char(stat.S_IFMT(stm))
            result['permissions'] = '%o' % (stat.S_IMODE(stm))
            result['UID'] = stats[stat.ST_UID]
            result['GID'] = stats[stat.ST_GID]
            result['ATIME'] = stats[stat.ST_ATIME]
            result['MTIME'] = stats[stat.ST_MTIME]
            result['CTIME'] = stats[stat.ST_CTIME] # actually mtime on UNIX, TODO
        else:
            if verbose:
                log.info('File \'%s\' is not accessible.' % (fullpath))
            result['type'] = None
            result['permissions'] =  None
            result['UID'] = None
            result['GID'] = None
            result['ATIME'] = None
            result['MTIME'] = None
            result['CTIME'] = None
        return result

    else: # SSH/FTP/TFTP/HTTP
        # TODO NOT IMPLEMENTED
        return IO_ERROR
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def getatime(self):
        st = self.statinfo
        if not st:
            self.restat()
            st = self.statinfo
        return st[ST_ATIME]
项目:Theano-Deep-learning    作者:GeekLiB    | 项目源码 | 文件源码
def last_access_time(path):
    """
    Return the number of seconds since the epoch of the last access of a
    given file.

    """
    return os.stat(path)[stat.ST_ATIME]
项目:scripts    作者:mbfraga    | 项目源码 | 文件源码
def add_file(self, filepath, misc_prop=None):
        """Manually add files to the files list, and get all its file
        properties.

        Keyword arguments:
        filepath -- path to file
        misc_prop -- add a miscellaneous property
        """
        if not os.path.isfile(filepath):
            print(filepath + " is not a file.")
            return
        fp_rel = filepath[self.__path_len:]

        try:
            stat = os.stat(filepath)
        except:
            return
        file_props = {}
        file_props['size'] = stat[ST_SIZE]
        file_props['adate'] = stat[ST_ATIME]
        file_props['mdate'] = stat[ST_MTIME]
        file_props['cdate'] = stat[ST_CTIME]
        file_props['name'] = fp_rel
        file_props['fullpath'] = filepath
        file_props['misc'] = misc_prop

        self.__files.append(file_props)
        self.__filecount += 1
项目:qn    作者:mbfraga    | 项目源码 | 文件源码
def add_file(self, filepath, misc_prop=None):
        """Add a file to the file repo.

        Keyword arguments:
        filepath -- path to file
        misc_props -- string to add as a 'misc' property to file
        """
        if not path.isfile(filepath):
            print(filepath + " is not a file.")
            exit(1)

        fp_rel = filepath[self.__path_len:]

        try:
            filestat = stat(filepath)
        except:
            return

        file_props = {}
        file_props['size'] = filestat[ST_SIZE]
        file_props['adate'] = filestat[ST_ATIME]
        file_props['mdate'] = filestat[ST_MTIME]
        file_props['cdate'] = filestat[ST_CTIME]
        file_props['name'] = fp_rel
        file_props['fullpath'] = filepath
        file_props['misc'] = misc_prop

        self.__file_list.append(file_props)
        self.__filecount += 1
项目:PYSHA    作者:shafaypro    | 项目源码 | 文件源码
def file_info (self, file_name=""):
        if file_name != "":
            file_stats = os.stat(file_name)
            # create a dictionary to hold file info
            file_info = {
                'fname': file_name,
                'fsize': file_stats[stat.ST_SIZE],
                'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p", time.localtime(file_stats[stat.ST_MTIME])),
                'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p", time.localtime(file_stats[stat.ST_ATIME])),
                'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p", time.localtime(file_stats[stat.ST_CTIME]))
            }
            print
            print("file name = %(fname)s" % file_info)
            print("file size = %(fsize)s bytes" % file_info)
            print("last modified = %(f_lm)s" % file_info)
            print("last accessed = %(f_la)s" % file_info)
            print("creation time = %(f_ct)s" % file_info)
            print
            if stat.S_ISDIR(file_stats[stat.ST_MODE]):
                print("This a directory")
            else:
                print("This is not a directory")
                print
                print("A closer look at the os.stat(%s) tuple:" % file_name)
                print(file_stats)
                print
                print("The above tuple has the following sequence:")
                print("""st_mode (protection bits), st_ino (inode number),
              st_dev (device), st_nlink (number of hard links),
              st_uid (user ID of owner), st_gid (group ID of owner),
              st_size (file size, bytes), st_atime (last access time, seconds since epoch),
              st_mtime (last modification time), st_ctime (time of creation, Windows)""")
        else:
            print("No File Detected , hence Exiting !")
项目:rdiff-backup    作者:sol1    | 项目源码 | 文件源码
def make_file_dict_python(filename):
    """Create the data dictionary using a Python call to os.lstat

    We do this on Windows since Python's implementation is much better
    than the one in cmodule.c    Eventually, we will move to using
    this on all platforms since CPUs have gotten much faster than
    they were when it was necessary to write cmodule.c
    """
    try:
        statblock = os.lstat(filename)
    except os.error:
        return {'type':None}
    data = {}
    mode = statblock[stat.ST_MODE]

    if stat.S_ISREG(mode): type_ = 'reg'
    elif stat.S_ISDIR(mode): type_ = 'dir'
    elif stat.S_ISCHR(mode):
        type_ = 'dev'
        s = statblock.st_rdev
        data['devnums'] = ('c',) + (s >> 8, s & 0xff)
    elif stat.S_ISBLK(mode):
        type_ = 'dev'
        s = statblock.st_rdev
        data['devnums'] = ('b',) + (s >> 8, s & 0xff)
    elif stat.S_ISFIFO(mode): type_ = 'fifo'
    elif stat.S_ISLNK(mode):
        type_ = 'sym'
        data['linkname'] = os.readlink(filename)
    elif stat.S_ISSOCK(mode): type_ = 'sock'
    else: raise C.UnknownFileError(filename)
    data['type'] = type_
    data['size'] = statblock[stat.ST_SIZE]
    data['perms'] = stat.S_IMODE(mode)
    data['uid'] = statblock[stat.ST_UID]
    data['gid'] = statblock[stat.ST_GID]
    data['inode'] = statblock[stat.ST_INO]
    data['devloc'] = statblock[stat.ST_DEV]
    data['nlink'] = statblock[stat.ST_NLINK]

    if os.name == 'nt':
        global type
        if type(filename) == unicode:
            attribs = win32file.GetFileAttributesW(filename)
        else:
            attribs = win32file.GetFileAttributes(filename)
        if attribs & winnt.FILE_ATTRIBUTE_REPARSE_POINT:
            data['type'] = 'sym'
            data['linkname'] = None

    if not (type_ == 'sym' or type_ == 'dev'):
        # mtimes on symlinks and dev files don't work consistently
        data['mtime'] = long(statblock[stat.ST_MTIME])
        data['atime'] = long(statblock[stat.ST_ATIME])
        data['ctime'] = long(statblock[stat.ST_CTIME])
    return data
项目:scripts    作者:mbfraga    | 项目源码 | 文件源码
def scan_files(self, recursive=True):
        """Scans the directory for files and populates the files list and 
        linebs. It is not a particularly fast implementation.

        Keyword arguments:
        recursive -- define whether scan should be recursive or not 
                     (default True)
        """
        self.__filecount = 0
        self.__files = []
        if recursive:
            for root, dirs, files in os.walk(self.__path, topdown=True):
                for name in files:
                    fp = os.path.join(root, name)
                    fp_rel = fp[self.__path_len:]

                    if (fp_rel[0] == '.'):
                        continue
                    try:
                        stat = os.stat(fp)
                    except:
                        continue

                    file_props = {}
                    file_props['size'] = stat[ST_SIZE]
                    file_props['adate'] = stat[ST_ATIME]
                    file_props['mdate'] = stat[ST_MTIME]
                    file_props['cdate'] = stat[ST_CTIME]
                    file_props['name'] = fp_rel
                    file_props['fullpath'] = fp
                    file_props['misc'] = None

                    self.__files.append(file_props)
                    self.__filecount += 1
        else:
            for f in os.scandir(self.__path):

                fp_rel = f.name
                fp = os.path.join(self.__path, fp_rel)
                if (fp_rel[0] == '.'):
                    continue
                if f.is_dir():
                    continue
                #try:
                #    stat = os.stat(fp)
                #except:
                #    continue

                file_props = {}
                file_props['size'] = f.stat()[ST_SIZE]
                file_props['adate'] = f.stat()[ST_ATIME]
                file_props['mdate'] = f.stat()[ST_MTIME]
                file_props['cdate'] = f.stat()[ST_CTIME]
                file_props['name'] = fp_rel
                file_props['fullpath'] = fp
                file_props['misc'] = None

                self.__files.append(file_props)
                self.__filecount += 1
项目:qn    作者:mbfraga    | 项目源码 | 文件源码
def scan_files(self):
        """Scans the directory for files and populates the file list and
        linebs.
        """
        self.__filecount = 0
        self.__pfilecount = 0
        pintot = len(self.__pinned_filenames)
        if pintot != 0:
            temp_pinned_filenames = list(self.__pinned_filenames)
        else:
            temp_pinned_filenames = False

        for root, dirs, files in walk(self.__path, topdown=True):
            for name in files:
                fp = path.join(root, name)
                fp_rel = fp[self.__path_len:]

                if (fp_rel[0] == '.'):
                    continue
                try:
                    filestat = stat(fp)
                except:
                    continue

                file_props = {}
                file_props['size'] = filestat[ST_SIZE]
                file_props['adate'] = filestat[ST_ATIME]
                file_props['mdate'] = filestat[ST_MTIME]
                file_props['cdate'] = filestat[ST_CTIME]
                file_props['name'] = fp_rel
                file_props['fullpath'] = fp
                file_props['misc'] = None
                file_props['tags'] = None

                if temp_pinned_filenames:
                    if name in temp_pinned_filenames:
                        temp_pinned_filenames.remove(name)
                        self.__pfile_list.append(file_props)
                        self.__pfilecount += 1
                        continue

                    self.__file_list.append(file_props)
                    self.__filecount += 1
                    continue

                # if name in self.pinned_filenames:
                #     self.__pfile_list.append(file_props)
                #     self.__pfilecount += 1
                # else:
                #     self.__file_list.append(file_props)
                #     self.__filecount += 1
                self.__file_list.append(file_props)
                self.__filecount += 1