Python uos.stat() Examples
The following are 11
code examples of uos.stat().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
uos
, or try the search function
.
Example #1
Source File: uftpd.py From FTP-Server-for-ESP8266-ESP32-and-PYBD with MIT License | 6 votes |
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
Example #2
Source File: utils.py From UIFlow-Code with GNU General Public License v3.0 | 5 votes |
def filesize(fname): if isfile(fname): return os.stat(fname)[6] else: return None
Example #3
Source File: util.py From developer-badge-2018-apps with Apache License 2.0 | 5 votes |
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()
Example #4
Source File: util.py From developer-badge-2018-apps with Apache License 2.0 | 5 votes |
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('')
Example #5
Source File: util.py From developer-badge-2018-apps with Apache License 2.0 | 5 votes |
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)
Example #6
Source File: ftp.py From uPyPortal with Apache License 2.0 | 5 votes |
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
Example #7
Source File: file_handler.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
def exists(path): try: uos.stat(path) return True except OSError: return False
Example #8
Source File: file_handler.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
def file_size(path): return uos.stat(path)[6]
Example #9
Source File: ftp.py From FTP-Server-for-ESP8266-ESP32-and-PYBD with MIT License | 5 votes |
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
Example #10
Source File: ftp_thread.py From FTP-Server-for-ESP8266-ESP32-and-PYBD with MIT License | 5 votes |
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
Example #11
Source File: server.py From tinyweb with MIT License | 4 votes |
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