mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-05 07:20:58 +00:00
Use locale.format() and os.path.getsize()
This commit is contained in:
parent
42a17cbb98
commit
45a4bbdaa9
2 changed files with 11 additions and 16 deletions
|
|
@ -138,16 +138,10 @@ class Buffer (object):
|
|||
return data
|
||||
|
||||
|
||||
@memoized
|
||||
def get_stat(filename):
|
||||
"""Return stat(2) data for given filename. Kan raise os.error"""
|
||||
return os.stat(filename)
|
||||
|
||||
|
||||
def get_mtime (filename):
|
||||
"""Return modification time of filename or zero on errors."""
|
||||
try:
|
||||
return get_stat(filename)[stat.ST_MTIME]
|
||||
return os.path.getmtime(filename)
|
||||
except os.error:
|
||||
return 0
|
||||
|
||||
|
|
@ -155,7 +149,7 @@ def get_mtime (filename):
|
|||
def get_size (filename):
|
||||
"""Return file size in Bytes, or -1 on error."""
|
||||
try:
|
||||
return get_stat(filename)[stat.ST_SIZE]
|
||||
return os.path.getsize(filename)
|
||||
except os.error:
|
||||
return -1
|
||||
|
||||
|
|
@ -274,7 +268,7 @@ def is_readable(filename):
|
|||
|
||||
def is_accessable_by_others(filename):
|
||||
"""Check if file is group or world accessable."""
|
||||
mode = get_stat(filename)[stat.ST_MODE]
|
||||
mode = os.stat(filename)[stat.ST_MODE]
|
||||
return mode & (stat.S_IRWXG | stat.S_IRWXO)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import os
|
|||
import math
|
||||
import time
|
||||
import urlparse
|
||||
import locale
|
||||
import pydoc
|
||||
from . import i18n
|
||||
|
||||
|
|
@ -184,18 +185,18 @@ def strsize (b):
|
|||
if b < 0:
|
||||
raise ValueError("Invalid negative byte number")
|
||||
if b < 1024:
|
||||
return u"%dB" % b
|
||||
return u"%sB" % locale.format("%d", b, True)
|
||||
if b < 1024 * 10:
|
||||
return u"%dKB" % (b // 1024)
|
||||
return u"%sKB" % locale.format("%d", (b // 1024), True)
|
||||
if b < 1024 * 1024:
|
||||
return u"%.2fKB" % (float(b) / 1024)
|
||||
return u"%sKB" % locale.format("%.2f", (float(b) / 1024), True)
|
||||
if b < 1024 * 1024 * 10:
|
||||
return u"%.2fMB" % (float(b) / (1024*1024))
|
||||
return u"%sMB" % locale.format("%.2f", (float(b) / (1024*1024)), True)
|
||||
if b < 1024 * 1024 * 1024:
|
||||
return u"%.1fMB" % (float(b) / (1024*1024))
|
||||
return u"%sMB" % locale.format("%.1f", (float(b) / (1024*1024)), True)
|
||||
if b < 1024 * 1024 * 1024 * 10:
|
||||
return u"%.2fGB" % (float(b) / (1024*1024*1024))
|
||||
return u"%.1fGB" % (float(b) / (1024*1024*1024))
|
||||
return u"%sGB" % locale.format("%.2f", (float(b) / (1024*1024*1024)), True)
|
||||
return u"%sGB" % locale.format("%.1f", (float(b) / (1024*1024*1024)), True)
|
||||
|
||||
|
||||
def strtime (t):
|
||||
|
|
|
|||
Loading…
Reference in a new issue