Replacing shutil copytree by dirsync

Reviewed-by: gtema <artem.goncharov@gmail.com>
Co-authored-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-committed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
This commit is contained in:
Hasko, Vladimir 2023-01-30 07:52:19 +00:00 committed by zuul
parent ccd8ac5fcb
commit eb996cfbfc
2 changed files with 15 additions and 6 deletions

View File

@ -2,3 +2,4 @@ GitPython
ruamel.yaml ruamel.yaml
requests requests
jinja2 jinja2
dirsync

View File

@ -18,9 +18,9 @@ import argparse
import logging import logging
import os import os
import pathlib import pathlib
import shutil
import subprocess import subprocess
import warnings import warnings
from dirsync import sync
from git import Repo from git import Repo
from git import SymbolicReference from git import SymbolicReference
@ -111,13 +111,21 @@ def process_repositories(args, service):
new_branch.set_tracking_branch(remote_ref) new_branch.set_tracking_branch(remote_ref)
new_branch.checkout() new_branch.checkout()
shutil.copytree( source_path = pathlib.Path(copy_from, doc["rst_location"])
pathlib.Path(copy_from, doc["rst_location"]), target_path = pathlib.Path(copy_to, doc["rst_location"])
pathlib.Path(copy_to, doc["rst_location"]), sync(
ignore=lambda a, b: ["conf.py"], source_path,
dirs_exist_ok=True, target_path,
'sync',
purge=True,
create=True,
content=True,
ignore=['conf.py']
) )
repo_to.index.add([doc["rst_location"]]) repo_to.index.add([doc["rst_location"]])
for obj in repo_to.index.diff(None).iter_change_type('D'):
repo_to.index.remove([obj.b_path])
if len(repo_to.index.diff("HEAD")) == 0: if len(repo_to.index.diff("HEAD")) == 0:
# Nothing to commit # Nothing to commit
logging.debug("No changes.") logging.debug("No changes.")