def _check_folders(self, path): # The goal is to find out if there was a modification if self.modified: return # Recursive check the last modified date for local_path in listdir(path): local_file = f'{path}/{local_path}' if isdir(local_file): # If there is no last backup if not self.last_date: self.modified = True return modified_date = datetime.utcfromtimestamp(getmtime(local_file)) if modified_date > self.last_date: self.modified = True return # print(local_file) self._check_folders(local_file) # If there is no last backup if not self.last_date: self.modified = True
def test_time(self): f = open(support.TESTFN, "wb") try: f.write(b"foo") f.close() f = open(support.TESTFN, "ab") f.write(b"bar") f.close() f = open(support.TESTFN, "rb") d = f.read() f.close() self.assertEqual(d, b"foobar") self.assertLessEqual(posixpath.getctime(support.TESTFN), posixpath.getmtime(support.TESTFN)) finally: if not f.closed: f.close()
def test_time(self): f = open(test_support.TESTFN, "wb") try: f.write("foo") f.close() f = open(test_support.TESTFN, "ab") f.write("bar") f.close() f = open(test_support.TESTFN, "rb") d = f.read() f.close() self.assertEqual(d, "foobar") self.assert_(posixpath.getctime(test_support.TESTFN) <= posixpath.getmtime(test_support.TESTFN)) finally: if not f.closed: f.close() os.remove(test_support.TESTFN)
def test_time(self): f = open(test_support.TESTFN, "wb") try: f.write("foo") f.close() f = open(test_support.TESTFN, "ab") f.write("bar") f.close() f = open(test_support.TESTFN, "rb") d = f.read() f.close() self.assertEqual(d, "foobar") self.assert_( posixpath.getctime(test_support.TESTFN) <= posixpath.getmtime( test_support.TESTFN)) finally: if not f.closed: f.close() os.remove(test_support.TESTFN)
def test_time(self): f = open(support.TESTFN, "wb") try: f.write(b"foo") f.close() f = open(support.TESTFN, "ab") f.write(b"bar") f.close() f = open(support.TESTFN, "rb") d = f.read() f.close() self.assertEqual(d, b"foobar") self.assertLessEqual( posixpath.getctime(support.TESTFN), posixpath.getmtime(support.TESTFN) ) finally: if not f.closed: f.close()
def get_source(self, environment, template): filename = f'templates/{template}/template.html' f = open_if_exists(filename) if f: try: contents = f.read().decode('utf-8') finally: f.close() mtime = posixpath.getmtime(filename) def uptodate(): try: return posixpath.getmtime(filename) == mtime except OSError: return False return contents, filename, uptodate raise TemplateNotFound(template)
def process_sources(sources, ext, fs_root, combined=False, timestamp=False): """Use utilities to combine and/or minify two or more files together. For more info see :func:`base_link`. :param sources: Paths of source files (strings or dicts) :param ext: Type of files :param fs_root: Root of file (normally public dir) :param combined: Filename of the combined files :param timestamp: Should the timestamp be added to the link :type sources: string :type ext: js or css :type fs_root: string :type filename: string :type timestamp: bool :returns: List of paths to processed sources """ if not sources: return [] if len(sources) == 1 and isinstance(sources, (str, unicode)): # We have a single file which doesn't even have to be minified return sources base = '/' # Get the file names and modification dates first for i in range(len(sources)): source = sources[i] # if it's a bare string then we don't want this file to be minified if isinstance(source, (str, unicode)): source = sources[i] = dict(file=source) if not combined and source.get('minify') and not source.get('dest'): raise ValueError( 'Either "combined" must be specified or "dest" for every file') source['file_path'] = path.join(fs_root, source['file'].lstrip('/')) if source.get('dest'): source['dest_path'] = path.join(fs_root, source['dest'].lstrip('/')) source['dest_link'] = path.join(base, source['dest'].lstrip('/')) else: source['dest_link'] = source['file'] source['modts'] = path.getmtime(source['file_path']) if combined: fname = combined.lstrip('/') fpath = path.join(fs_root, fname) refresh_needed = False if path.exists(fpath): last_mod = path.getmtime(fpath) refresh_needed = last_mod < max([s['modts'] for s in sources]) else: refresh_needed = True buffer = StringIO.StringIO() else: refresh_needed = True buffer = None if refresh_needed: for source in sources: # build a master file with all contents dest = buffer if not dest: # or separate files dest = source.get('dest_path') if not dest or (path.exists(dest) and \ source['modts'] <= path.getmtime(dest)): # The file should not be touched or was not modified since # the last processing. Skip continue dirs = path.dirname(dest) try: os.makedirs(dirs, 0755) except OSError: pass dest = open(dest, 'w') if 'js' in ext: f = open(source['file_path'], 'r') if source.get('minify') == 'minify': # stream is auto-closed inside js_minify.minify(f, dest) else: dest.write(f.read()) f.close() elif 'css' in ext: if source.get('minify') == 'minify': sheet = cssutils.parseFile(source['file_path']) sheet.setSerializer(CSSUtilsMinificationSerializer()) cssutils.ser.prefs.useMinified() dest.write(sheet.cssText) elif source.get('minify') == 'strip': f = open(source['file_path'], 'r') dest.write(css_strip(f.read())) f.close() else: f = open(source['file_path'], 'r') dest.write(f.read()) f.close() else: raise ValueError('Source type unknown: %s' % ext) if buffer: buffer.write('\n') else: dest.close() if buffer: dirs = path.dirname(fpath) try: os.makedirs(dirs, 0755) except OSError: pass # write the combined file f = open(fpath, 'w') f.write(buffer.getvalue()) f.close() if buffer: last_mod = path.getmtime(fpath) link = path.join(base, fname) if timestamp: timestamp = int(last_mod) link = '%s?t=%s' % (link, timestamp) return [link] else: links = [] for s in sources: # If the dest file not set we take the source file mod tstamp last_mod = path.getmtime(s.get('dest_path', s['file_path'])) link = s['dest_link'] if timestamp: timestamp = int(last_mod) link = '%s?t=%s' % (link, timestamp) links.append(link) return links
def modified_timestamp(path): return int(posixpath.getmtime(path))
def uptodate(): try: return posixpath.getmtime(filename) == mtime except OSError: return False
def update_event(self, inp=-1): self.set_output_val(0, posixpath.getmtime(self.input(0)))