# Path: makeapp/exceptions.py
# class CommandError(MakeappException):
#     """Raised when projector detects external process invocation error."""


import fileinput
import logging
import os
import shutil
import sys
import tempfile
from contextlib import contextmanager
from subprocess import Popen, PIPE, STDOUT
from typing import Generator, List, Optional, Dict
from .exceptions import CommandError

def replace_infile(filepath: str, pairs: Dict[str, str]):
    """Replaces some term by another in file contents.

    :param filepath:
    :param pairs: search -> replace.

    """
    with fileinput.input(files=filepath, inplace=True) as f:

        for line in f:

            for search, replace in pairs.items():
                line = line.replace(search, replace)

            sys.stdout.write(line)


def check_command(command: str, hint: str):
    """Checks whether a command is available.
    If not - raises an exception.

    :param command:
    :param hint:

    """
    try:
        run_command(f'type {command}')

    except CommandError:

# Path: makeapp/exceptions.py
# class CommandError(MakeappException):
#     """Raised when projector detects external process invocation error."""


# Path: makeapp/utils.py
import fileinput
import logging
import os
import shutil
import sys
import tempfile
from contextlib import contextmanager
from subprocess import Popen, PIPE, STDOUT
from typing import Generator, List, Optional, Dict
from .exceptions import CommandError


def replace_infile(filepath: str, pairs: Dict[str, str]):
    """Replaces some term by another in file contents.

    :param filepath:
    :param pairs: search -> replace.

    """
    with fileinput.input(files=filepath, inplace=True) as f:

        for line in f:

            for search, replace in pairs.items():
                line = line.replace(search, replace)

            sys.stdout.write(line)


def check_command(command: str, hint: str):
    """Checks whether a command is available.
    If not - raises an exception.

    :param command:
    :param hint:

    """
    try:
        run_command(f'type {command}')

    except CommandError:

        raise CommandError(