Python stat.ST_MTIME Examples
The following are 30
code examples of stat.ST_MTIME().
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
stat
, or try the search function
.
Example #1
Source File: urllib2.py From jawfish with MIT License | 6 votes |
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')
Example #2
Source File: dep_util.py From BinderFilter with MIT License | 6 votes |
def newer(source, target): """Tells if the target is newer than the source. Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return True return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME]
Example #3
Source File: dep_util.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def newer (source, target): """Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return 1 from stat import ST_MTIME mtime1 = os.stat(source)[ST_MTIME] mtime2 = os.stat(target)[ST_MTIME] return mtime1 > mtime2 # newer ()
Example #4
Source File: dep_util.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def newer (source, target): """Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return 1 from stat import ST_MTIME mtime1 = os.stat(source)[ST_MTIME] mtime2 = os.stat(target)[ST_MTIME] return mtime1 > mtime2 # newer ()
Example #5
Source File: pickleshare.py From Computable with MIT License | 6 votes |
def __getitem__(self,key): """ db['key'] reading """ fil = self.root / key try: mtime = (fil.stat()[stat.ST_MTIME]) except OSError: raise KeyError(key) if fil in self.cache and mtime == self.cache[fil][1]: return self.cache[fil][0] try: # The cached item has expired, need to read with fil.open("rb") as f: obj = pickle.loads(f.read()) except: raise KeyError(key) self.cache[fil] = (obj,mtime) return obj
Example #6
Source File: sphinxy.py From RocketCEA with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: dep_util.py From Imogen with MIT License | 6 votes |
def newer (source, target): """Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return 1 from stat import ST_MTIME mtime1 = os.stat(source)[ST_MTIME] mtime2 = os.stat(target)[ST_MTIME] return mtime1 > mtime2 # newer ()
Example #8
Source File: lookup.py From mako with MIT License | 6 votes |
def _check(self, uri, template): if template.filename is None: return template try: template_stat = os.stat(template.filename) if template.module._modified_time < template_stat[stat.ST_MTIME]: self._collection.pop(uri, None) return self._load(template.filename, uri) else: return template except OSError: self._collection.pop(uri, None) raise exceptions.TemplateLookupException( "Cant locate template for uri %r" % uri )
Example #9
Source File: dep_util.py From ironpython3 with Apache License 2.0 | 6 votes |
def newer (source, target): """Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return 1 from stat import ST_MTIME mtime1 = os.stat(source)[ST_MTIME] mtime2 = os.stat(target)[ST_MTIME] return mtime1 > mtime2 # newer ()
Example #10
Source File: install.py From ironpython2 with Apache License 2.0 | 6 votes |
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,))
Example #11
Source File: test.py From ironpython2 with Apache License 2.0 | 6 votes |
def run(self): last_time = os.stat(self.filename)[stat.ST_MTIME] while 1: try: rc = win32event.WaitForSingleObject(self.handle, win32event.INFINITE) win32file.FindNextChangeNotification(self.handle) except win32event.error, details: # handle closed - thread should terminate. if details[0] != winerror.ERROR_INVALID_HANDLE: raise break this_time = os.stat(self.filename)[stat.ST_MTIME] if this_time != last_time: print "Detected file change - flagging for reload." self.change_detected = True last_time = this_time
Example #12
Source File: advanced.py From ironpython2 with Apache License 2.0 | 6 votes |
def run(self): last_time = os.stat(self.filename)[stat.ST_MTIME] while 1: try: rc = win32event.WaitForSingleObject(self.handle, win32event.INFINITE) win32file.FindNextChangeNotification(self.handle) except win32event.error, details: # handle closed - thread should terminate. if details[0] != winerror.ERROR_INVALID_HANDLE: raise break this_time = os.stat(self.filename)[stat.ST_MTIME] if this_time != last_time: print "Detected file change - flagging for reload." self.change_detected = True last_time = this_time
Example #13
Source File: lookup.py From teleport with Apache License 2.0 | 6 votes |
def _check(self, uri, template): if template.filename is None: return template try: template_stat = os.stat(template.filename) if template.module._modified_time < template_stat[stat.ST_MTIME]: self._collection.pop(uri, None) return self._load(template.filename, uri) else: return template except OSError: self._collection.pop(uri, None) raise exceptions.TemplateLookupException( "Cant locate template for uri %r" % uri )
Example #14
Source File: lookup.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def _check(self, uri, template): if template.filename is None: return template try: template_stat = os.stat(template.filename) if template.module._modified_time < template_stat[stat.ST_MTIME]: self._collection.pop(uri, None) return self._load(template.filename, uri) else: return template except OSError: self._collection.pop(uri, None) raise exceptions.TemplateLookupException( "Cant locate template for uri %r" % uri )
Example #15
Source File: fotobox.py From fotobox with MIT License | 6 votes |
def startViewer(self, Form): self.screen = 4 if(self.isLive): self.isLive=False self.tplImage = "init.png" if not fotoboxCfg['nopi']: self.camera.stop_preview() self.entries = None self.entries = (os.path.join(self.save, fn) for fn in os.listdir(self.save)) self.entries = ((os.stat(path), path) for path in self.entries) self.entries = ((stat[ST_MTIME], path) for stat, path in self.entries if S_ISREG(stat[ST_MODE])) self.entries = list(self.entries) if(len(self.entries) > 0): self.viewerIndex = 0 self.screenViewer(Form) else: print("No images to show") self.screenMain(Form)
Example #16
Source File: lookup.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def _check(self, uri, template): if template.filename is None: return template try: template_stat = os.stat(template.filename) if template.module._modified_time < template_stat[stat.ST_MTIME]: self._collection.pop(uri, None) return self._load(template.filename, uri) else: return template except OSError: self._collection.pop(uri, None) raise exceptions.TemplateLookupException( "Cant locate template for uri %r" % uri )
Example #17
Source File: lookup.py From teleport with Apache License 2.0 | 6 votes |
def _check(self, uri, template): if template.filename is None: return template try: template_stat = os.stat(template.filename) if template.module._modified_time < \ template_stat[stat.ST_MTIME]: self._collection.pop(uri, None) return self._load(template.filename, uri) else: return template except OSError: self._collection.pop(uri, None) raise exceptions.TemplateLookupException( "Cant locate template for uri %r" % uri)
Example #18
Source File: dep_util.py From oss-ftp with MIT License | 6 votes |
def newer(source, target): """Tells if the target is newer than the source. Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return True return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME]
Example #19
Source File: lookup.py From jbox with MIT License | 6 votes |
def _check(self, uri, template): if template.filename is None: return template try: template_stat = os.stat(template.filename) if template.module._modified_time < \ template_stat[stat.ST_MTIME]: self._collection.pop(uri, None) return self._load(template.filename, uri) else: return template except OSError: self._collection.pop(uri, None) raise exceptions.TemplateLookupException( "Cant locate template for uri %r" % uri)
Example #20
Source File: lookup.py From teleport with Apache License 2.0 | 6 votes |
def _check(self, uri, template): if template.filename is None: return template try: template_stat = os.stat(template.filename) if template.module._modified_time < template_stat[stat.ST_MTIME]: self._collection.pop(uri, None) return self._load(template.filename, uri) else: return template except OSError: self._collection.pop(uri, None) raise exceptions.TemplateLookupException( "Cant locate template for uri %r" % uri )
Example #21
Source File: template.py From mako with MIT License | 5 votes |
def _compile_from_file(self, path, filename): if path is not None: util.verify_directory(os.path.dirname(path)) filemtime = os.stat(filename)[stat.ST_MTIME] if ( not os.path.exists(path) or os.stat(path)[stat.ST_MTIME] < filemtime ): data = util.read_file(filename) _compile_module_file( self, data, filename, path, self.module_writer ) module = compat.load_module(self.module_id, path) del sys.modules[self.module_id] if module._magic_number != codegen.MAGIC_NUMBER: data = util.read_file(filename) _compile_module_file( self, data, filename, path, self.module_writer ) module = compat.load_module(self.module_id, path) del sys.modules[self.module_id] ModuleInfo(module, path, self, filename, None, None, None) else: # template filename and no module directory, compile code # in memory data = util.read_file(filename) code, module = _compile_text(self, data, filename) self._source = None self._code = code ModuleInfo(module, None, self, filename, code, None, None) return module
Example #22
Source File: template.py From teleport with Apache License 2.0 | 5 votes |
def _compile_from_file(self, path, filename): if path is not None: util.verify_directory(os.path.dirname(path)) filemtime = os.stat(filename)[stat.ST_MTIME] if ( not os.path.exists(path) or os.stat(path)[stat.ST_MTIME] < filemtime ): data = util.read_file(filename) _compile_module_file( self, data, filename, path, self.module_writer ) module = compat.load_module(self.module_id, path) del sys.modules[self.module_id] if module._magic_number != codegen.MAGIC_NUMBER: data = util.read_file(filename) _compile_module_file( self, data, filename, path, self.module_writer ) module = compat.load_module(self.module_id, path) del sys.modules[self.module_id] ModuleInfo(module, path, self, filename, None, None, None) else: # template filename and no module directory, compile code # in memory data = util.read_file(filename) code, module = _compile_text(self, data, filename) self._source = None self._code = code ModuleInfo(module, None, self, filename, code, None, None) return module
Example #23
Source File: __init__.py From attention-lvcsr with MIT License | 5 votes |
def try_import(): """ Load the cuda_ndarray module if present and up to date. Return True if loaded correctly, otherwise return False. """ cuda_files = ( 'cuda_ndarray.cu', 'cuda_ndarray.cuh', 'conv_full_kernel.cu', 'cnmem.h', 'cnmem.cpp', 'conv_kernel.cu') stat_times = [os.stat(os.path.join(cuda_path, cuda_file))[stat.ST_MTIME] for cuda_file in cuda_files] date = max(stat_times) if os.path.exists(cuda_ndarray_so): if date >= os.stat(cuda_ndarray_so)[stat.ST_MTIME]: return False try: # If we load a previously-compiled version, config.compiledir should # be in sys.path. sys.path[0:0] = [config.compiledir] import cuda_ndarray.cuda_ndarray del sys.path[0] except ImportError: return False return True
Example #24
Source File: treesync.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def mtime(f): st = os.fstat(f.fileno()) return st[stat.ST_MTIME]
Example #25
Source File: MetadataHandler.py From p2ptv-pi with MIT License | 5 votes |
def load_recently_collected_torrents(self, num_recent, num_random): torrent_dir = self.torrent_db.getTorrentDir() join = os.path.join items = [ join(torrent_dir, filename) for filename in os.listdir(torrent_dir) if filename.endswith('.torrent') ] get_stat = os.stat ST_MTIME = stat.ST_MTIME items = [ (get_stat(filename)[ST_MTIME], filename) for filename in items ] items.sort(reverse=True) if len(items) >= num_recent: recent_items = items[:num_recent] random_items = random.sample(items[num_recent:], min(num_random, len(items) - num_recent)) else: recent_items = items random_items = [] append = self.recently_collected_torrents.append load = TorrentDef.load for _, filename in recent_items: try: torrent_def = load(filename) except: print >> sys.stderr, 'MetadataHandler.load_recently_collected_torrents() Invalid .torrent file', filename else: append(torrent_def.get_infohash()) for _, filename in random_items: try: torrent_def = load(filename) except: print >> sys.stderr, 'MetadataHandler.load_recently_collected_torrents() Invalid .torrent file', filename else: append(torrent_def.get_infohash())
Example #26
Source File: cvsfiles.py From datafari with Apache License 2.0 | 5 votes |
def getmtime(filename): try: st = os.stat(filename) except os.error: return 0 return st[stat.ST_MTIME]
Example #27
Source File: template.py From teleport with Apache License 2.0 | 5 votes |
def _compile_from_file(self, path, filename): if path is not None: util.verify_directory(os.path.dirname(path)) filemtime = os.stat(filename)[stat.ST_MTIME] if not os.path.exists(path) or \ os.stat(path)[stat.ST_MTIME] < filemtime: data = util.read_file(filename) _compile_module_file( self, data, filename, path, self.module_writer) module = compat.load_module(self.module_id, path) del sys.modules[self.module_id] if module._magic_number != codegen.MAGIC_NUMBER: data = util.read_file(filename) _compile_module_file( self, data, filename, path, self.module_writer) module = compat.load_module(self.module_id, path) del sys.modules[self.module_id] ModuleInfo(module, path, self, filename, None, None) else: # template filename and no module directory, compile code # in memory data = util.read_file(filename) code, module = _compile_text( self, data, filename) self._source = None self._code = code ModuleInfo(module, None, self, filename, code, None) return module
Example #28
Source File: malpedia_analyzer.py From Cortex-Analyzers with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self): Analyzer.__init__(self) self.baseurl = "https://malpedia.caad.fkie.fraunhofer.de/api/get" self.rulepaths = self.get_param('config.path', None, 'No rulepath provided.') self.user = self.get_param('config.username', None, 'No username provided.') self.pwd = self.get_param('config.password', None, 'No password provided.') self.update_hours = int(self.get_param('config.update_hours', 10)) if not os.path.exists(self.rulepaths): os.makedirs(self.rulepaths) timestamps = [] try: for fn in os.listdir(self.rulepaths): for path in os.path.join(self.rulepaths, fn): if os.path.isfile(path) and path.endswith('.yar'): timestamps.append(datetime.datetime.fromtimestamp(os.stat(path)[ST_MTIME])) newest = max(timestamps) hours = (datetime.datetime.now() - newest).seconds / 3600 except ValueError: hours = self.update_hours + 1 if hours > self.update_hours or len(timestamps) == 0: try: req = requests.get('{}/yara/after/2010-01-01?format=json'.format(self.baseurl), auth=HTTPBasicAuth(self.user, self.pwd)) if req.status_code == requests.codes.ok: rules_json = json.loads(req.text) for color, color_data in rules_json.items(): for rule_name, rule_text in color_data.items(): with io.open(os.path.join(self.rulepaths, rule_name), 'w', encoding='utf-8') as f: f.write(rule_text) else: self.error('Could not download new rules due tue HTTP {}: {}'.format(req.status_code, req.text)) except Exception as e: with io.open('%s' % os.path.join(self.rulepaths, "error.txt"), 'w') as f: f.write('Error: {}\n'.format(e))
Example #29
Source File: reboot_required.py From integrations-extras with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_created_at(self, fname): file_stat = stat(fname) created_at = file_stat[ST_MTIME] return created_at
Example #30
Source File: frm_reader.py From mysql-utilities with GNU General Public License v2.0 | 5 votes |
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