remove distutils in favor of shutil

This commit is contained in:
Nick Sweeting 2019-03-27 11:39:51 -04:00
parent e1a1ea25dd
commit 002206d4fe
2 changed files with 9 additions and 7 deletions

View file

@ -6,12 +6,6 @@ from string import Template
from typing import List, Tuple, Iterator, Optional
from dataclasses import fields
try:
from distutils.dir_util import copy_tree
except ImportError:
print('[X] Missing "distutils" python package. To install it, run:')
print(' pip install distutils')
from schema import Link, ArchiveIndex, ArchiveResult
from config import (
OUTPUT_DIR,
@ -29,6 +23,7 @@ from util import (
ExtendedEncoder,
enforce_types,
TimedProgress,
copy_and_overwrite,
)
from parse import parse_links
from links import validate_links
@ -149,7 +144,7 @@ def write_html_links_index(out_dir: str, links: List[Link], finished: bool=False
path = os.path.join(out_dir, 'index.html')
copy_tree(os.path.join(TEMPLATES_DIR, 'static'), os.path.join(out_dir, 'static'))
copy_and_overwrite(os.path.join(TEMPLATES_DIR, 'static'), os.path.join(out_dir, 'static'))
with open(os.path.join(out_dir, 'robots.txt'), 'w+') as f:
f.write('User-agent: *\nDisallow: /')

View file

@ -2,6 +2,7 @@ import os
import re
import sys
import time
import shutil
from json import JSONEncoder
from typing import List, Optional, Any
@ -604,6 +605,12 @@ def chmod_file(path: str, cwd: str='.', permissions: str=OUTPUT_PERMISSIONS, tim
raise Exception('Failed to chmod {}/{}'.format(cwd, path))
@enforce_types
def copy_and_overwrite(from_path: str, to_path: str):
if os.path.exists(to_path):
shutil.rmtree(to_path)
shutil.copytree(from_path, to_path)
@enforce_types
def chrome_args(**options) -> List[str]:
"""helper to build up a chrome shell command with arguments"""