<commit_before>#!/usr/bin/env python
#
# Copyright 2012, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import daemon
import fcntl
import getopt
import logging
import os
import random
import string
import sys
import traceback

from ConfigParser import ConfigParser
from flask import Flask, jsonify, request

# from roush import backends
from roush.db import models
from roush.db.api import api_from_models
from roush.webapp.ast import FilterBuilder, FilterTokenizer

from roush.webapp.adventures import bp as adventures_bp
from roush.webapp.facts import bp as facts_bp
from roush.webapp.facts_please import bp as facts_please
from roush.webapp.attrs import bp as attrs_bp
from roush.webapp.filters import bp as filters_bp
from roush.webapp.index import bp as index_bp
from roush.webapp.nodes import bp as nodes_bp
# from roush.webapp.nodes_please import bp as nodes_please
from roush.webapp.primitives import bp as primitives_bp
from roush.webapp.tasks import bp as tasks_bp
from roush.webapp.plan import bp as plan_bp


# api = api_from_models()


# Stolen: http://code.activestate.com/recipes/\
#         577911-context-manager-for-a-daemon-pid-file/
class PidFile(object):
    def __init__(self, path):
        self.path = path
        self.pidfile = None

    def __enter__(self):
        self.pidfile = open(self.path, 'a+')
        try:
            fcntl.flock(self.pidfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
        except IOError:
            raise SystemExit('Pid file in use')

        self.pidfile.seek(0)
        self.pidfile.truncate()
        self.pidfile.write(str(os.getpid()))
        self.pidfile.flush()
        self.pidfile.seek(0)
        return self.pidfile

    def __exit__(self, exc_type=None, exc_value=None, exc_tb=None):
        try:
            self.pidfile.close()
        except IOError as err:
            if err.errno != 9:
                raise
        os.remove(self.path)


class Thing(Flask):
    def __init__(self, name, argv=None, configfile=None,
                 confighash=None, debug=False):
        daemonize = False
        self.registered_models = []
        # Define a global transaction_id
        self.trans = {
            'session_key': "".join([random.choice(string.hexdigits)
                                   for n in xrange(30)]),
            'latest': 0,
            'lowest': 0,
            'updates': {0: {'nodes': []}}}
<commit_msg>removing comment<commit_after>#!/usr/bin/env python
#
# Copyright 2012, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import daemon
import fcntl
import getopt
import logging
import os
import random
import string
import sys
import traceback

from ConfigParser import ConfigParser
from flask import Flask, jsonify, request

# from roush import backends
from roush.db import models
from roush.db.api import api_from_models
from roush.webapp.ast import FilterBuilder, FilterTokenizer

from roush.webapp.adventures import bp as adventures_bp
from roush.webapp.facts import bp as facts_bp
from roush.webapp.facts_please import bp as facts_please
from roush.webapp.attrs import bp as attrs_bp
from roush.webapp.filters import bp as filters_bp
from roush.webapp.index import bp as index_bp
from roush.webapp.nodes import bp as nodes_bp
# from roush.webapp.nodes_please import bp as nodes_please
from roush.webapp.primitives import bp as primitives_bp
from roush.webapp.tasks import bp as tasks_bp
from roush.webapp.plan import bp as plan_bp


# api = api_from_models()


# Stolen: http://code.activestate.com/recipes/\
#         577911-context-manager-for-a-daemon-pid-file/
class PidFile(object):
    def __init__(self, path):
        self.path = path
        self.pidfile = None

    def __enter__(self):
        self.pidfile = open(self.path, 'a+')
        try:
            fcntl.flock(self.pidfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
        except IOError:
            raise SystemExit('Pid file in use')

        self.pidfile.seek(0)
        self.pidfile.truncate()
        self.pidfile.write(str(os.getpid()))
        self.pidfile.flush()
        self.pidfile.seek(0)
        return self.pidfile

    def __exit__(self, exc_type=None, exc_value=None, exc_tb=None):
        try:
            self.pidfile.close()
        except IOError as err:
            if err.errno != 9:
                raise
        os.remove(self.path)


class Thing(Flask):
    def __init__(self, name, argv=None, configfile=None,
                 confighash=None, debug=False):
        daemonize = False
        self.registered_models = []
        self.trans = {
            'session_key': "".join([random.choice(string.hexdigits)
                                   for n in xrange(30)]),
            'latest': 0,
            'lowest': 0,
            'updates': {0: {'nodes': []}}}

{'fraction_non_alphanumeric': 0.08844827586206896, 'fraction_numerical': 0.007586206896551724, 'mean_word_length': 2.895903290799194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2098939', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1763, 'n_words': 555}