Esempio n. 1
0
def _brotli_html(html, filepath, url):
    while True:
        original_ts = os.stat(filepath).st_mtime
        original_size = os.stat(filepath).st_size
        t0 = time.time()
        new_filepath = brotli_file(filepath)
        t1 = time.time()
        if new_filepath:
            new_size = os.stat(new_filepath).st_size
            if not new_size:
                print(
                    "WARNING! {} became 0 bytes after brotli".format(filepath))
                os.remove(new_filepath)
                continue
            if new_size > original_size:
                print(
                    "WARNING! {} became larger after brotli".format(filepath))
                # XXX delete it?

            print("Generated {} ({} bytes, originally {} bytes) Took {:.2f}s".
                  format(
                      new_filepath,
                      format(new_size, ","),
                      format(original_size, ","),
                      t1 - t0,
                  ))
            if original_ts != os.stat(filepath).st_mtime:
                print("WARNING! The file {} changed during the "
                      "brotli process.".format(filepath))
                continue
            break
Esempio n. 2
0
def _brotli(filepath):
    while True:
        original_ts = os.stat(filepath).st_mtime
        t0 = time.time()
        new_filepath = brotli_file(filepath)
        t1 = time.time()
        if new_filepath:
            print("Generated {} ({} bytes, originally {} bytes) Took {:.2f}s".
                  format(
                      new_filepath,
                      format(os.stat(new_filepath).st_size, ","),
                      format(os.stat(filepath).st_size, ","),
                      t1 - t0,
                  ))
            if original_ts != os.stat(filepath).st_mtime:
                print("WARNING! The file {} changed during the "
                      "brotli process.".format(filepath))
                continue
            break
Esempio n. 3
0
def _brotli_html(html, filepath, url):
    for _ in range(5):
        try:
            original_ts = os.stat(filepath).st_mtime
            original_size = os.stat(filepath).st_size
        except FileNotFoundError:
            # Try again in a second.
            time.sleep(1)
            continue
        t0 = time.time()
        new_filepath = brotli_file(filepath)
        t1 = time.time()
        if new_filepath:
            try:
                new_size = os.stat(new_filepath).st_size
            except FileNotFoundError:
                # Race conditions probably
                print("WARNING! {} is now gone".format(filepath))
                continue
            if not new_size:
                print("WARNING! {} became 0 bytes after brotli".format(filepath))
                os.remove(new_filepath)
                continue
            if new_size > original_size:
                print("WARNING! {} became larger after brotli".format(filepath))
                # XXX delete it?

            print(
                "Generated {} ({} bytes, originally {} bytes) Took {:.2f}s".format(
                    new_filepath,
                    format(new_size, ","),
                    format(original_size, ","),
                    t1 - t0,
                )
            )
            if original_ts != os.stat(filepath).st_mtime:
                print(
                    "WARNING! The file {} changed during the "
                    "brotli process.".format(filepath)
                )
                continue
            break
Esempio n. 4
0
def _brotli_html(html, filepath, url):
    for _ in range(5):
        try:
            original_ts = os.stat(filepath).st_mtime
            original_size = os.stat(filepath).st_size
        except FileNotFoundError:
            # Try again in a second.
            time.sleep(1)
            continue
        t0 = time.time()
        new_filepath = brotli_file(filepath)
        t1 = time.time()
        if new_filepath:
            try:
                new_size = os.stat(new_filepath).st_size
            except FileNotFoundError:
                # Race conditions probably
                print("WARNING! {} is now gone".format(filepath))
                continue
            if not new_size:
                print(
                    "WARNING! {} became 0 bytes after brotli".format(filepath))
                os.remove(new_filepath)
                continue
            if new_size > original_size:
                print(
                    "WARNING! {} became larger after brotli".format(filepath))
                # XXX delete it?

            print("Generated {} ({} bytes, originally {} bytes) Took {:.2f}s".
                  format(
                      new_filepath,
                      format(new_size, ","),
                      format(original_size, ","),
                      t1 - t0,
                  ))
            if original_ts != os.stat(filepath).st_mtime:
                print("WARNING! The file {} changed during the "
                      "brotli process.".format(filepath))
                continue
            break
def _brotli(filepath):
    while True:
        original_ts = os.stat(filepath).st_mtime
        t0 = time.time()
        new_filepath = brotli_file(filepath)
        t1 = time.time()
        if new_filepath:
            print(
                "Generated {} ({} bytes, originally {} bytes) Took {:.2f}s".format(
                    new_filepath,
                    format(os.stat(new_filepath).st_size, ","),
                    format(os.stat(filepath).st_size, ","),
                    t1 - t0,
                )
            )
            if original_ts != os.stat(filepath).st_mtime:
                print(
                    "WARNING! The file {} changed during the "
                    "brotli process.".format(filepath)
                )
                continue
            break