Move create_remote_dirs parameter to sync function

This commit is contained in:
Mikhail Gordeev 2021-04-10 01:41:07 +03:00
parent 09c061e9b3
commit fa7bfe1c5a
6 changed files with 7 additions and 20 deletions

View File

@ -78,11 +78,7 @@ def main():
args = parse_args()
stages = set(args.stages) - set(args.skip_stages)
cb = cloud_build.CB(
config=args.config,
tasks=args.tasks,
create_remote_dirs=args.create_remote_dirs,
)
cb = cloud_build.CB(config=args.config, tasks=args.tasks)
if 'build' in stages:
no_tests = 'test' not in stages
cb.create_images(no_tests=no_tests)
@ -91,7 +87,7 @@ def main():
if 'sign' in stages:
cb.sign()
if 'sync' in stages:
cb.sync()
cb.sync(create_remote_dirs=args.create_remote_dirs)
if __name__ == '__main__':

View File

@ -54,13 +54,11 @@ class CB:
config: str,
*,
data_dir: Optional[PathLike] = None,
create_remote_dirs: bool = False,
tasks: Optional[dict[str, List[str]]] = None,
) -> None:
self.initialized = False
self._save_cwd = os.getcwd()
self.parse_config(config)
self._create_remote_dirs = create_remote_dirs
if tasks is None:
self.tasks = {}
else:
@ -710,10 +708,10 @@ Dir::Etc::preferencesparts "/var/empty";
host = remote[:colon]
self.call(['ssh', host, 'kick'])
def sync(self) -> None:
def sync(self, create_remote_dirs: bool = False) -> None:
for branch in self.branches:
remote = self.remote(branch)
if self._create_remote_dirs:
if create_remote_dirs:
os.makedirs(remote, exist_ok=True)
cmd = [
'rsync',

View File

@ -68,7 +68,6 @@ class TestErrors(TestCase):
cloud_build = CB(
config='tests/test_try_build_all.yaml',
data_dir=self.kwargs['data_dir'],
create_remote_dirs=True,
)
regex = r'build.*:'
self.assertRaisesRegex(
@ -86,7 +85,6 @@ class TestErrors(TestCase):
cloud_build = CB(
config='tests/test_try_build_all.yaml',
data_dir=self.kwargs['data_dir'],
create_remote_dirs=True,
)
regex = r'build.*:'
self.assertRaisesRegex(
@ -104,7 +102,6 @@ class TestErrors(TestCase):
cloud_build = CB(
config='tests/test_not_try_build_all.yaml',
data_dir=self.kwargs['data_dir'],
create_remote_dirs=True,
)
regex = r'build.*aarch64'
self.assertRaisesRegex(

View File

@ -26,12 +26,11 @@ class TestIntegrationImages(TestCase):
cloud_build = CB(
config='tests/test_integration_images.yaml',
data_dir=(cls.work_dir / 'cloud_build').as_posix(),
create_remote_dirs=True,
)
cloud_build.create_images(no_tests=True)
cloud_build.copy_external_files()
cloud_build.sign()
cloud_build.sync()
cloud_build.sync(create_remote_dirs=True)
images_dir = cls.work_dir / 'images'
cls.images = {}

View File

@ -25,12 +25,11 @@ class TestNoDelete(TestCase):
cb = CB(
config='tests/test_no_delete_false.yaml',
data_dir=self.data_dir,
create_remote_dirs=True,
)
other_file = self.images_dir / 'other_file.txt'
other_file.write_text('Some text')
cb.create_images(no_tests=True)
cb.sync()
cb.sync(create_remote_dirs=True)
del cb
msg = 'Other files shoud be deleted if not no_delete'
if other_file.exists():
@ -41,12 +40,11 @@ class TestNoDelete(TestCase):
cb = CB(
config='tests/test_no_delete_true.yaml',
data_dir=self.data_dir,
create_remote_dirs=True,
)
other_file = self.images_dir / 'other_file.txt'
other_file.write_text('Some text')
cb.create_images(no_tests=True)
cb.sync()
cb.sync(create_remote_dirs=True)
del cb
msg = 'Other files shoud not be deleted if no_delete'
if not other_file.exists():

View File

@ -22,7 +22,6 @@ class TestRebuild(TestCase):
self.cb = CB(
config='tests/test_rebuild.yaml',
data_dir=self.data_dir,
create_remote_dirs=True,
)
def tearDown(self):