summaryrefslogtreecommitdiff
path: root/src/pyssg/utils.py
blob: a24d7cab6ab2a7a6e777c65b6f9f98524add3bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import sys
import shutil
import logging
from logging import Logger

log: Logger = logging.getLogger(__name__)


def create_dir(path: str, p: bool=False) -> None:
    try:
        if p:
            os.makedirs(path)
        else:
            os.mkdir(path)
        log.info('created directory "%s"', path)
    except FileExistsError:
        log.info('directory "%s" already exists, ignoring', path)


def copy_file(src: str, dst: str) -> None:
    if not os.path.exists(dst):
        shutil.copy2(src, dst)
        log.info('copied file "%s" to "%s"', src, dst)
    else:
        log.info('file "%s" already exists, ignoring', dst)


def sanity_check_path(path: str) -> None:
    if '$' in  path:
        log.error('"$" character found in path "%s";'
                  ' could be due to non-existant env var.', path)
        sys.exit(1)