1
0
Fork 0
This repository has been archived on 2022-08-04. You can view files and clone it, but cannot push or open issues or pull requests.
website_generator/website_generator/actions/files.py

30 lines
923 B
Python

from website_generator.fields import PathMatcherField, PathField
from website_generator.config import ActionConfig
from website_generator.actions import Action
import shutil
import typesystem
class CopyActionConfig(ActionConfig):
src = PathMatcherField()
dest = PathField(allow_null=True, must_exist=False, allow_folders=True)
overwite = typesystem.Boolean(default=True)
class CopyAction(Action):
type = 'copy'
def __init__(self, **params):
config = CopyActionConfig.validate(params)
params['src'] = config.src
params['dest'] = config.dest
params['overwrite'] = config.overwrite
super().__init__(**params)
def __call__(self):
for source_path in self.src.all():
if source_path.is_dir():
shutil.copytree(str(source_path), str(self.dest))
else:
shutil.copy2(str(source_path), str(self.dest))