当前位置: 首页>>代码示例>>Python>>正文


Python stat.ST_SIZE属性代码示例

本文整理汇总了Python中stat.ST_SIZE属性的典型用法代码示例。如果您正苦于以下问题:Python stat.ST_SIZE属性的具体用法?Python stat.ST_SIZE怎么用?Python stat.ST_SIZE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在stat的用法示例。


在下文中一共展示了stat.ST_SIZE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open_local_file

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def open_local_file(self, req):
        host = req.get_host()
        file = req.get_selector()
        localfile = url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = rfc822.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        stats = os.stat(localfile)
        headers = mimetools.Message(StringIO(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        if host:
            host, port = splitport(host)
        if not host or \
           (not port and socket.gethostbyname(host) in self.get_names()):
            return addinfourl(open(localfile, 'rb'),
                              headers, 'file:'+file)
        raise URLError('file not on local host') 
开发者ID:war-and-code,项目名称:jawfish,代码行数:21,代码来源:urllib2.py

示例2: check_if_remote_is_newer

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def check_if_remote_is_newer(self, localfile, remote_size, remote_modify):
        """
        Overrides check_if_remote_is_newer in Source class

        :param localfile: str file path
        :param remote_size: str bytes
        :param remote_modify: str last modify date in the form 20160705042714
        :return: boolean True if remote file is newer else False
        """
        is_remote_newer = False
        status = os.stat(localfile)
        LOG.info(
            "\nLocal file size: %i"
            "\nLocal Timestamp: %s",
            status[ST_SIZE], datetime.fromtimestamp(status.st_mtime))
        remote_dt = Bgee._convert_ftp_time_to_iso(remote_modify)

        if remote_dt != datetime.fromtimestamp(status.st_mtime) or \
                status[ST_SIZE] != int(remote_size):
            is_remote_newer = True
            LOG.info(
                "Object on server is has different size %i and/or date %s",
                remote_size, remote_dt)

        return is_remote_newer 
开发者ID:monarch-initiative,项目名称:dipper,代码行数:27,代码来源:Bgee.py

示例3: CheckLoaderModule

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def CheckLoaderModule(dll_name):
    suffix = ""
    if is_debug_build: suffix = "_d"
    template = os.path.join(this_dir,
                            "PyISAPI_loader" + suffix + ".dll")
    if not os.path.isfile(template):
        raise ConfigurationError(
              "Template loader '%s' does not exist" % (template,))
    # We can't do a simple "is newer" check, as the DLL is specific to the
    # Python version.  So we check the date-time and size are identical,
    # and skip the copy in that case.
    src_stat = os.stat(template)
    try:
        dest_stat = os.stat(dll_name)
    except os.error:
        same = 0
    else:
        same = src_stat[stat.ST_SIZE]==dest_stat[stat.ST_SIZE] and \
               src_stat[stat.ST_MTIME]==dest_stat[stat.ST_MTIME]
    if not same:
        log(2, "Updating %s->%s" % (template, dll_name))
        shutil.copyfile(template, dll_name)
        shutil.copystat(template, dll_name)
    else:
        log(2, "%s is up to date." % (dll_name,)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:install.py

示例4: GetItemData

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def GetItemData(self, colid, colData):
        fmt_id, pid = colid
        fmt_id==self._reg_clsid_
        flags, attr, reserved, ext, name = colData
        if ext.lower() not in [".py", ".pyw"]:
            return None
        if pid==0:
            ext = ".pyc"
        else:
            ext = ".pyo"
        check_file = os.path.splitext(name)[0] + ext
        try:
            st = os.stat(check_file)
            return st[stat.ST_SIZE]
        except OSError:
            # No file
            return None 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:column_provider.py

示例5: _read_write_test

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def _read_write_test(self, path):
        """
        Verify that ``rand.write_file`` and ``rand.load_file`` can be used.
        """
        # Create the file so cleanup is more straightforward
        with open(path, "w"):
            pass

        try:
            # Write random bytes to a file
            rand.write_file(path)

            # Verify length of written file
            size = os.stat(path)[stat.ST_SIZE]
            self.assertEqual(1024, size)

            # Read random bytes from file
            rand.load_file(path)
            rand.load_file(path, 4)  # specify a length
        finally:
            # Cleanup
            os.unlink(path) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:24,代码来源:test_rand.py

示例6: checksum_directory

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def checksum_directory(directory, touch_first=False):
    """
    Walk directory structure and return simple checksum based on
    file size and modified time.
    """
    file_checksums = []
    fileL = glob.glob( os.path.join(directory,'*.rst') )
    
    for source_path in fileL:
    
        if touch_first: # 
            os.utime(source_path, None)
            
        try:
            stats = os.stat(source_path)
        except OSError:
            # ignore temp files and files we don't
            # have perms to access
            continue
        file_checksums.append(
            stats[stat.ST_SIZE] + stats[stat.ST_MTIME])
    return sum(file_checksums) 
开发者ID:sonofeft,项目名称:RocketCEA,代码行数:24,代码来源:sphinxy.py

示例7: setUp

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def setUp(self):
        if os.path.exists(TESTFN):
            mode = 'r+b'
        else:
            mode = 'w+b'

        with self.open(TESTFN, mode) as f:
            current_size = os.fstat(f.fileno())[stat.ST_SIZE]
            if current_size == size+1:
                return

            if current_size == 0:
                f.write(b'z')

            f.seek(0)
            f.seek(size)
            f.write(b'a')
            f.flush()
            self.assertEqual(os.fstat(f.fileno())[stat.ST_SIZE], size+1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_largefile.py

示例8: walker

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def walker(arg, dirname, fnames):
    d = os.getcwd()
    os.chdir(dirname)
    try:
        fnames.remove('Thumbs')
    except ValueError:
        pass        
    for f in fnames:
        if not os.path.isfile(f):
            continue
        size = os.stat(f)[stat.ST_SIZE]
        if size < 100:
            continue
        if filesBySize.has_key(size):
            a = filesBySize[size]
        else:
            a = []
            filesBySize[size] = a
        a.append(os.path.join(dirname, f))
    os.chdir(d) 
开发者ID:ActiveState,项目名称:code,代码行数:22,代码来源:recipe-362459.py

示例9: show_statistics

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def show_statistics(self):
        """Show general file and table statistics
        """

        print "# File Statistics:"
        file_stats = os.stat(self.frm_path)
        file_info = {
            'Size': file_stats[stat.ST_SIZE],
            'Last Modified': time.ctime(file_stats[stat.ST_MTIME]),
            'Last Accessed': time.ctime(file_stats[stat.ST_ATIME]),
            'Creation Time': time.ctime(file_stats[stat.ST_CTIME]),
            'Mode': file_stats[stat.ST_MODE],
        }
        for value, data in file_info.iteritems():
            print "#%22s : %s" % (value, data)
        print

        # Fail if we cannot read the file
        try:
            self.frm_file = open(self.frm_path, "rb")
        except Exception, error:
            raise UtilError("The file %s cannot be read.\n%s" %
                            (self.frm_path, error))

        # Read the file type 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:27,代码来源:frm_reader.py

示例10: _get_old_package_dict

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def _get_old_package_dict(self):
        if hasattr(self, '_old_package_dict'):
            return self._old_package_dict

        self._old_package_dict = {}
        for d in self.conf.oldpackage_paths:
            for f in self.getFileList(d, '.rpm'):
                fp = d + '/' + f
                fpstat = os.stat(fp)
                if int(fpstat[stat.ST_SIZE]) > self.conf.max_delta_rpm_size:
                    self.callback.log("Skipping %s package " \
                                      "that is > max_delta_rpm_size"  % f)
                    continue
                if not self._old_package_dict.has_key(d):
                    self._old_package_dict[d] = []
                self._old_package_dict[d].append(d + '/' + f)

        return self._old_package_dict 
开发者ID:crohr,项目名称:rpm-s3,代码行数:20,代码来源:__init__.py

示例11: copy_file_if_modified

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def copy_file_if_modified(src_path, dest_path):
    """Only copies the file from the source path to the destination path if it doesn't exist yet or it has
    been modified. Intended to provide something of an optimisation when a project has large trees of assets."""

    # if the destination path is a directory, delete it completely - we assume here we are
    # writing a file to the filesystem
    if os.path.isdir(dest_path):
        shutil.rmtree(dest_path)

    must_copy = False
    if not os.path.exists(dest_path):
        must_copy = True
    else:
        src_stat = os.stat(src_path)
        dest_stat = os.stat(dest_path)

        # if the size or last modified timestamp are different
        if ((src_stat[stat.ST_SIZE] != dest_stat[stat.ST_SIZE]) or
                (src_stat[stat.ST_MTIME] != dest_stat[stat.ST_MTIME])):
            must_copy = True

    if must_copy:
        shutil.copy2(src_path, dest_path) 
开发者ID:thanethomson,项目名称:statik,代码行数:25,代码来源:utils.py

示例12: file_truncate

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def file_truncate(parent,msg):

    # will do this when processing the last chunk
    # whenever that is
    if (not parent.randomize) and (not msg.lastchunk) : return

    try :
             lstat   = os.stat(msg.target_file)
             fsiz    = lstat[stat.ST_SIZE] 

             if fsiz > msg.filesize :
                fp = open(msg.target_file,'r+b')
                fp.truncate(msg.filesize)
                fp.close()

                msg.set_topic(parent.post_topic_prefix,msg.target_relpath)
                msg.set_notice(msg.new_baseurl,msg.target_relpath,msg.pubtime)
                msg.report_publish(205, 'Reset Content :truncated')

    except : pass 
开发者ID:MetPX,项目名称:sarracenia,代码行数:22,代码来源:sr_file.py

示例13: on_file

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def on_file(self, parent ):
          import os,stat

          logger  = parent.logger
          msg     = parent.msg
          path    = msg.new_dir + '/' + msg.new_file
          fsiz    = os.stat(path)[stat.ST_SIZE]
          partstr = '1,%d,1,0,0' % fsiz

          if partstr == msg.partstr : return True

          msg.partstr          = partstr
          msg.headers['parts'] = msg.partstr

          parent.logger.debug("file size repaired in message %s" % partstr)

          return True 
开发者ID:MetPX,项目名称:sarracenia,代码行数:19,代码来源:on_file_repair_size.py

示例14: walker

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def walker(arg, dirname, fnames):
    d = os.getcwd()
    os.chdir(dirname)
    global filesBySize

    try:
        fnames.remove('Thumbs')
    except ValueError:
        pass
    for f in fnames:
        if not os.path.isfile(f):
            continue
        size = os.stat(f)[stat.ST_SIZE]
        # print f + " size: " + str(size)
        if size < 100:
            continue
        if filesBySize.has_key(size):
            a = filesBySize[size]
        else:
            a = []
            filesBySize[size] = a
        a.append(os.path.join(dirname, f))
    os.chdir(d) 
开发者ID:C0D3D3V,项目名称:Moodle-Downloader,代码行数:25,代码来源:moodleCrawler.py

示例15: readData

# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_SIZE [as 别名]
def readData(self, filename, file_index):
        # Open file and read file size
        self.warning("Load input file: %s" % filename)
        data = open(filename, 'rb')
        orig_filesize = fstat(data.fileno())[ST_SIZE]
        if not orig_filesize:
            raise ValueError("Input file (%s) is empty!" % filename)

        # Read bytes
        if self.max_size:
            data = data.read(self.max_size)
        else:
            data = data.read()

        # Display message if input is truncated
        if len(data) < orig_filesize:
            percent = len(data) * 100.0 / orig_filesize
            self.warning("Truncate file to %s bytes (%.2f%% of %s bytes)" \
                % (len(data), percent, orig_filesize))

        # Convert to Python array object
        return array('B', data) 
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:24,代码来源:mangle_agent.py


注:本文中的stat.ST_SIZE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。