<commit_before>#! /usr/bin/env python
# vim:ai:et:ff=unix:fileencoding=utf-8:sw=4:ts=4:
# conveyor/start.py
#
# conveyor - Printing dispatch engine for 3D objects and their friends.
# Copyright © 2012 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

'''A Python-based startup script for conveyor.'''

from __future__ import (absolute_import, print_function, unicode_literals)

import json
import os
import os.path
import subprocess
import sys

try:
    # The argparse module was added to Python as of version 2.7. However, there
    # is a backport for older versions of Python and we expect that it is
    # installed into the virtualenv.
    import argparse
except ImportError:
    print(
        "conveyor-start: missing required module 'argparse'; is the virtualenv activated?",
        file=sys.stderr)
    sys.exit(1)


def _main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-c',
        '--config',
        action='store',
        default='conveyor-dev.conf',
        type=str,
        required=False,
        help='read configuration from FILE',
        metavar='FILE',
        dest='config_file')
    parsed_args, unparsed_args = parser.parse_known_args(argv[1:])
    try:
        with open(parsed_args.config_file) as fp:
            config = json.load(fp)
    except ValueError:
        pid_file = 'conveyord.pid'
    else:
        pid_file = config.get('common', {}).get('pid_file', 'conveyord.pid')
    if os.path.exists(pid_file):
        print(
            'conveyor-start: pid file exists; is the conveyor service already running?',
            file=sys.stderr)
        return 1
    elif 'VIRTUAL_ENV' not in os.environ:
        print('conveyor-start: virtualenv is not activated', file=sys.stderr)
        return 1
    else:
        path = os.pathsep.join([
            os.path.join('src', 'main', 'python'),
            os.path.join(os.pardir, 's3g'),
            ])
        if 'PYTHONPATH' not in os.environ:
            os.environ['PYTHONPATH'] = path
        else:
            os.environ['PYTHONPATH'] = os.pathsep.join((
                path, os.environ['PYTHONPATH']))
        arguments = [
            'python',
            '-B',
            '-m', 'conveyor.server',
            '-c', parsed_args.config_file,
            ]
        arguments.extend(unparsed_args)
        os.execvp(sys.executable, arguments) # NOTE: this line does not return.


if '__main__' == __name__:
    code = _main(sys.argv)
    if None is code:
        code = 0
    sys.exit(code)<commit_msg>Fix the module path in start.py.<commit_after>#! /usr/bin/env python
# vim:ai:et:ff=unix:fileencoding=utf-8:sw=4:ts=4:
# conveyor/start.py
#
# conveyor - Printing dispatch engine for 3D objects and their friends.
# Copyright © 2012 <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

'''A Python-based startup script for conveyor.'''

from __future__ import (absolute_import, print_function, unicode_literals)

import json
import os
import os.path
import subprocess
import sys

try:
    # The argparse module was added to Python as of version 2.7. However, there
    # is a backport for older versions of Python and we expect that it is
    # installed into the virtualenv.
    import argparse
except ImportError:
    print(
        "conveyor-start: missing required module 'argparse'; is the virtualenv activated?",
        file=sys.stderr)
    sys.exit(1)


def _main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-c',
        '--config',
        action='store',
        type=str,
        required=False,
        help='read configuration from FILE',
        metavar='FILE',
        dest='config_file')
    parsed_args, unparsed_args = parser.parse_known_args(argv[1:])
    if None is parsed_args.config_file:
        parsed_args.config_file = 'conveyor-dev.conf'
    try:
        with open(parsed_args.config_file) as fp:
            config = json.load(fp)
    except ValueError:
        pid_file = 'conveyord.pid'
    else:
        pid_file = config.get('common', {}).get('pid_file', 'conveyord.pid')
    if os.path.exists(pid_file):
        print(
            'conveyor-start: pid file exists; is the conveyor service already running?',
            file=sys.stderr)
        return 1
    elif 'VIRTUAL_ENV' not in os.environ:
        print('conveyor-start: virtualenv is not activated', file=sys.stderr)
        return 1
    else:
        path = os.pathsep.join([
            os.path.join('src', 'main', 'python'),
            os.path.join(os.pardir, 's3g'),
            ])
        if 'PYTHONPATH' not in os.environ:
            os.environ['PYTHONPATH'] = path
        else:
            os.environ['PYTHONPATH'] = os.pathsep.join((
                path, os.environ['PYTHONPATH']))
        arguments = [
            'python',
            '-B',
            os.path.join('src', 'main', 'python', 'conveyor', 'server', '__main__.py'),
            '-c', parsed_args.config_file,
            ]
        if len(unparsed_args) > 0 and '--' == unparsed_args[0]:
            unparsed_args = unparsed_args[1:]
        arguments.extend(unparsed_args)
        os.execvp(sys.executable, arguments) # NOTE: this line does not return.


if '__main__' == __name__:
    code = _main(sys.argv)
    if None is code:
        code = 0
    sys.exit(code)
{'fraction_non_alphanumeric': 0.10689707906407708, 'fraction_numerical': 0.005658357547025539, 'mean_word_length': 2.6454849498327757, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '993607', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1945, 'n_words': 630}