本文整理汇总了Python中uos.stat方法的典型用法代码示例。如果您正苦于以下问题:Python uos.stat方法的具体用法?Python uos.stat怎么用?Python uos.stat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uos
的用法示例。
在下文中一共展示了uos.stat方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_description
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def make_description(self, path, fname, full):
global _month_name
if full:
stat = uos.stat(self.get_absolute_path(path, fname))
file_permissions = ("drwxr-xr-x"
if (stat[0] & 0o170000 == 0o040000)
else "-rw-r--r--")
file_size = stat[6]
tm = localtime(stat[7])
if tm[0] != localtime()[0]:
description = "{} 1 owner group {:>10} {} {:2} {:>5} {}\r\n".\
format(file_permissions, file_size,
_month_name[tm[1]], tm[2], tm[0], fname)
else:
description = "{} 1 owner group {:>10} {} {:2} {:02}:{:02} {}\r\n".\
format(file_permissions, file_size,
_month_name[tm[1]], tm[2], tm[3], tm[4], fname)
else:
description = fname + "\r\n"
return description
示例2: filesize
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def filesize(fname):
if isfile(fname):
return os.stat(fname)[6]
else:
return None
示例3: startup
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def startup(timer=None):
conf = Config('global')
for app in uos.listdir('/apps'):
try:
uos.stat('/apps/{}/boot.py'.format(app))
except OSError:
pass
else:
execfile('/apps/{}/boot.py'.format(app))
gc.collect()
del conf
gc.collect()
示例4: download_file
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def download_file(url, filename=None):
if filename is None:
filename = url.split('/')[-1]
print('Downloading file from {}.'.format(url))
print('It will be saved as \'{}\''.format(filename))
try:
st = uos.stat(filename)
raise Exception('Already exist file')
except OSError:
pass
if not wait_network(5):
raise Exception('Not connected: check your internet')
gc.collect()
s = upip.url_open(url)
s.setblocking(False)
with open(filename, 'w') as f:
BUF_LEN = 256
try:
while True:
data = s.read(BUF_LEN)
print('.',end='')
# print(data,end='')
if data is None or len(data) < BUF_LEN:
break
f.write(data)
except Exception as e:
s.close()
f.close()
raise e
s.close()
print('')
示例5: save
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def save(self):
# Create config_dir if do not exists
try:
uos.stat(self.config_dir)
except OSError:
uos.mkdir(self.config_dir)
with open('{}/{}.json'.format(self.config_dir, self.name), 'w') as fp:
json.dump(self.data, fp)
示例6: make_description
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def make_description(self, path, fname, full):
if full:
stat = uos.stat(self.get_absolute_path(path,fname))
file_permissions = "drwxr-xr-x" if (stat[0] & 0o170000 == 0o040000) else "-rw-r--r--"
file_size = stat[6]
description = "{} 1 owner group {:>10} Jan 1 2000 {}\r\n".format(
file_permissions, file_size, fname)
else:
description = fname + "\r\n"
return description
示例7: exists
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def exists(path):
try:
uos.stat(path)
return True
except OSError:
return False
示例8: file_size
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def file_size(path):
return uos.stat(path)[6]
示例9: make_description
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def make_description(path, fname, full):
if full:
stat = uos.stat(get_absolute_path(path, fname))
file_permissions = ("drwxr-xr-x"
if (stat[0] & 0o170000 == 0o040000)
else "-rw-r--r--")
file_size = stat[6]
description = "{} 1 owner group {:>10} Jan 1 2000 {}\r\n".format(
file_permissions, file_size, fname)
else:
description = fname + "\r\n"
return description
示例10: make_description
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def make_description(path, fname, full):
if full:
stat = uos.stat(get_absolute_path(path, fname))
file_permissions = "drwxr-xr-x"\
if (stat[0] & 0o170000 == 0o040000)\
else "-rw-r--r--"
file_size = stat[6]
description = "{} 1 owner group {:>10} Jan 1 2000 {}\r\n".format(
file_permissions, file_size, fname)
else:
description = fname + "\r\n"
return description
示例11: send_file
# 需要导入模块: import uos [as 别名]
# 或者: from uos import stat [as 别名]
def send_file(self, filename, content_type=None, content_encoding=None, max_age=2592000):
"""Send local file as HTTP response.
This function is generator.
Arguments:
filename - Name of file which exists in local filesystem
Keyword arguments:
content_type - Filetype. By default - None means auto-detect.
max_age - Cache control. How long browser can keep this file on disk.
By default - 30 days
Set to 0 - to disable caching.
Example 1: Default use case:
await resp.send_file('images/cat.jpg')
Example 2: Disable caching:
await resp.send_file('static/index.html', max_age=0)
Example 3: Override content type:
await resp.send_file('static/file.bin', content_type='application/octet-stream')
"""
try:
# Get file size
stat = os.stat(filename)
slen = str(stat[6])
self.add_header('Content-Length', slen)
# Find content type
if content_type:
self.add_header('Content-Type', content_type)
# Add content-encoding, if any
if content_encoding:
self.add_header('Content-Encoding', content_encoding)
# Since this is static content is totally make sense
# to tell browser to cache it, however, you can always
# override it by setting max_age to zero
self.add_header('Cache-Control', 'max-age={}, public'.format(max_age))
with open(filename) as f:
await self._send_headers()
gc.collect()
buf = bytearray(128)
while True:
size = f.readinto(buf)
if size == 0:
break
await self.send(buf, sz=size)
except OSError as e:
# special handling for ENOENT / EACCESS
if e.args[0] in (errno.ENOENT, errno.EACCES):
raise HTTPException(404)
else:
raise