Copying project files directly, rather than copying them in an import-export fashion, can make copying projects many times faster

This commit is contained in:
赵昕彧 2024-09-25 20:27:46 +08:00
parent 5ffe5fd9b3
commit 2dbde5df22
2 changed files with 3 additions and 20 deletions

View File

@ -42,9 +42,11 @@ from ..utils.application_id import get_next_application_id
from ..utils.asyncio.pool import Pool from ..utils.asyncio.pool import Pool
from ..utils.asyncio import locking from ..utils.asyncio import locking
from ..utils.asyncio import aiozipstream from ..utils.asyncio import aiozipstream
from ..utils.asyncio import wait_run_in_executor
from .export_project import export_project from .export_project import export_project
from .import_project import import_project from .import_project import import_project
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -1262,11 +1264,7 @@ class Project:
new_project_id = str(uuid.uuid4()) new_project_id = str(uuid.uuid4())
new_project_path = p_work.joinpath(new_project_id) new_project_path = p_work.joinpath(new_project_id)
# copy dir # copy dir
scripts_path = os.path.join(pathlib.Path(__file__).resolve().parent.parent.parent, 'scripts') await wait_run_in_executor(shutil.copytree, self.path, new_project_path.as_posix())
process = await asyncio.create_subprocess_exec('python', os.path.join(scripts_path, 'copy_tree.py'), '--src',
self.path, '--dst',
new_project_path.as_posix())
await process.wait()
log.info("[FAST] Copy project: {} to: '{}', cost={}s".format(self.path, new_project_path, time.time() - t0)) log.info("[FAST] Copy project: {} to: '{}', cost={}s".format(self.path, new_project_path, time.time() - t0))
topology = json.loads(new_project_path.joinpath('{}.gns3'.format(self.name)).read_bytes()) topology = json.loads(new_project_path.joinpath('{}.gns3'.format(self.name)).read_bytes())
project_name = name or topology["name"] project_name = name or topology["name"]

View File

@ -1,15 +0,0 @@
import argparse
import shutil
# 复制目录
def copy_tree(src, dst):
shutil.copytree(src, dst)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='for test')
parser.add_argument('--src', type=str, help='', default='')
parser.add_argument('--dst', type=str, help='', default='')
args = parser.parse_args()
copy_tree(args.src, args.dst)