<commit_before>#!/usr/bin/env python
from __future__ import print_function
import os
import glob
import stat
import logging
import sys
import string
import random
import webbrowser
import threading 

# import gevent
# import gevent.monkey
# from gevent.pywsgi import WSGIServer
# gevent.monkey.patch_all()

from flask import Flask, request, Response, redirect, send_from_directory


usage = '''
STASIS
======
A simple static web-site server.
 - adds trailing / to directories
 - adds implied .html to clean urls
 - has a site regeneration hook 
 - monitors modfiications in directories 

usage: stasis.py static_web_dir
'''


app = Flask(__name__)
handler = logging.StreamHandler(stream=sys.stdout)
handler.setLevel(logging.INFO)
app.logger.addHandler(handler)  


def is_something_changed():
  if app.regenerate is None:
    return False
  if app.monitor_dirs:
    checksum = 0
    for check_dir in app.monitor_dirs:
      for root, dirs, files in os.walk(check_dir + '/'):
        fnames = [os.path.join(root, f) for f in files]
        checksum += sum(map(os.path.getmtime, fnames))
    # no changes in directories:
    if app.checksum == None:
      app.checksum = checksum
    if checksum == app.checksum:
      return False
    app.checksum = checksum
  return True


def regenerate_site_if_changed():
  if is_something_changed():
    app.regenerate()


# def event_stream():
#     count = 0
#     while True:
#         gevent.sleep(2)
#         if is_something_changed():
#           app.regenerate()
#           yield 'data: %s\n\n' % count
#         count += 1


# @app.route('/my_event_source')
# def sse_request():
#     return Response(
#             event_stream(),
#             mimetype='text/event-stream')


def send_fname(fname):
  app.logger.info('FETCHING: {0}'.format(fname))
  if fname.endswith('.html'):
    regenerate_site_if_changed()
  return send_from_directory(*os.path.split(fname))

<commit_msg>deleting sse stuff<commit_after>#!/usr/bin/env python
from __future__ import print_function
import os
import glob
import stat
import logging
import sys
import string
import random
import webbrowser
import threading 

# import gevent
# import gevent.monkey
# from gevent.pywsgi import WSGIServer
# gevent.monkey.patch_all()

from flask import Flask, request, Response, redirect, send_from_directory


usage = '''
STASIS
======
A simple static web-site server.
 - adds trailing / to directories
 - adds implied .html to clean urls
 - has a site regeneration hook 
 - monitors modfiications in directories 

usage: stasis.py static_web_dir
'''


app = Flask(__name__)
handler = logging.StreamHandler(stream=sys.stdout)
handler.setLevel(logging.INFO)
app.logger.addHandler(handler)  


def is_something_changed():
  if app.regenerate is None:
    return False
  if app.monitor_dirs:
    checksum = 0
    for check_dir in app.monitor_dirs:
      for root, dirs, files in os.walk(check_dir + '/'):
        fnames = [os.path.join(root, f) for f in files]
        checksum += sum(map(os.path.getmtime, fnames))
    # no changes in directories:
    if app.checksum == None:
      app.checksum = checksum
    if checksum == app.checksum:
      return False
    app.checksum = checksum
  return True


def regenerate_site_if_changed():
  if is_something_changed():
    app.regenerate()


def send_fname(fname):
  app.logger.info('FETCHING: {0}'.format(fname))
  if fname.endswith('.html'):
    regenerate_site_if_changed()
  return send_from_directory(*os.path.split(fname))


{'fraction_non_alphanumeric': 0.10372492836676218, 'fraction_numerical': 0.0020057306590257878, 'mean_word_length': 3.569371727748691, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3262880', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1110, 'n_words': 305}