<commit_before>#!/usr/bin/env python3

import argparse
import os
from tempfile import NamedTemporaryFile
from textwrap import dedent
import shutil

from qlmdm import top_dir
from qlmdm.prompts import get_bool


os.chdir(top_dir)


parser = argparse.ArgumentParser(
    description='Finalize installation of the qlmdm client.',
)
parser.add_argument(
    '--prefix',
    metavar='PATH',
    default='/',
    help='The install prefix.',
)
parser.add_argument(
    '-y',
    '--no-prompt',
    action='store_false',
    dest='prompt',
    help='Do not prompt the user before installing or replacing the crontab',
)

args = parser.parse_args()

cron_file = os.path.join(args.prefix, 'etc/cron.d/qlmdm')
cron_exists = os.path.exists(cron_file)

if args.prompt:
    if cron_exists:
        prompt = 'Do you want to replace the crontab?'
    else:
        prompt = 'Do you want to install the crontab?'

    do_crontab = get_bool(prompt, not cron_exists)
else:
    do_crontab = True

if do_crontab:
    with NamedTemporaryFile('w+') as temp_cron_file:
        temp_cron_file.write(dedent('''\
            * * * * * root {}/bin/client-cron
        '''.format(top_dir)))
        temp_cron_file.flush()
        os.chmod(temp_cron_file.name, 0o644)

        # ensure the etc/cron.d directory exists
        os.makedirs(os.path.dirname(cron_file), exist_ok=True)
        shutil.copy(temp_cron_file.name, cron_file)

    print('Installed {}'.format(cron_file))

print('Done!')
<commit_msg>Client cron job shouldn't generate emails<commit_after>#!/usr/bin/env python3

import argparse
import os
from tempfile import NamedTemporaryFile
from textwrap import dedent
import shutil

from qlmdm import top_dir
from qlmdm.prompts import get_bool


os.chdir(top_dir)


parser = argparse.ArgumentParser(
    description='Finalize installation of the qlmdm client.',
)
parser.add_argument(
    '--prefix',
    metavar='PATH',
    default='/',
    help='The install prefix.',
)
parser.add_argument(
    '-y',
    '--no-prompt',
    action='store_false',
    dest='prompt',
    help='Do not prompt the user before installing or replacing the crontab',
)

args = parser.parse_args()

cron_file = os.path.join(args.prefix, 'etc/cron.d/qlmdm')
cron_exists = os.path.exists(cron_file)

if args.prompt:
    if cron_exists:
        prompt = 'Do you want to replace the crontab?'
    else:
        prompt = 'Do you want to install the crontab?'

    do_crontab = get_bool(prompt, not cron_exists)
else:
    do_crontab = True

if do_crontab:
    with NamedTemporaryFile('w+') as temp_cron_file:
        temp_cron_file.write(dedent('''\
            SHELL=/bin/bash
            * * * * * root {}/bin/client-cron &>/dev/null
        '''.format(top_dir)))
        temp_cron_file.flush()
        os.chmod(temp_cron_file.name, 0o644)

        # ensure the etc/cron.d directory exists
        os.makedirs(os.path.dirname(cron_file), exist_ok=True)
        shutil.copy(temp_cron_file.name, cron_file)

    print('Installed {}'.format(cron_file))

print('Done!')

{'fraction_non_alphanumeric': 0.1205298013245033, 'fraction_numerical': 0.0033112582781456954, 'mean_word_length': 3.3034188034188032, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2716354', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1054, 'n_words': 239}