mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 01:08:19 +00:00
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:
parent
5ffe5fd9b3
commit
2dbde5df22
@ -42,9 +42,11 @@ from ..utils.application_id import get_next_application_id
|
||||
from ..utils.asyncio.pool import Pool
|
||||
from ..utils.asyncio import locking
|
||||
from ..utils.asyncio import aiozipstream
|
||||
from ..utils.asyncio import wait_run_in_executor
|
||||
from .export_project import export_project
|
||||
from .import_project import import_project
|
||||
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -1262,11 +1264,7 @@ class Project:
|
||||
new_project_id = str(uuid.uuid4())
|
||||
new_project_path = p_work.joinpath(new_project_id)
|
||||
# copy dir
|
||||
scripts_path = os.path.join(pathlib.Path(__file__).resolve().parent.parent.parent, 'scripts')
|
||||
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()
|
||||
await wait_run_in_executor(shutil.copytree, self.path, new_project_path.as_posix())
|
||||
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())
|
||||
project_name = name or topology["name"]
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user