Commit 134db22b authored by Nicolas Wavrant's avatar Nicolas Wavrant

decrease the number of calls to rsync

parent aec0ea6f
...@@ -75,7 +75,10 @@ def rsync(rsync_binary, source, destination, extra_args=None, dry=False): ...@@ -75,7 +75,10 @@ def rsync(rsync_binary, source, destination, extra_args=None, dry=False):
] ]
if isinstance(extra_args, list): if isinstance(extra_args, list):
arg_list.extend(extra_args) arg_list.extend(extra_args)
arg_list.append(source) if isinstance(source, list):
arg_list.extend(source)
else:
arg_list.append(source)
arg_list.append(destination) arg_list.append(destination)
if dry: if dry:
...@@ -143,27 +146,28 @@ def getSha256Sum(file_path): ...@@ -143,27 +146,28 @@ def getSha256Sum(file_path):
def synchroniseRunnerConfigurationDirectory(config, backup_path): def synchroniseRunnerConfigurationDirectory(config, backup_path):
rsync(config.rsync_binary, 'config.json', backup_path, dry=config.dry) file_list = ['config.json']
for hidden_file in os.listdir('.'):
for hidden_file in [ if hidden_file[0] == '.':
x for x in os.listdir('.') file_list.append(hidden_file)
if x[0] == '.' rsync(config.rsync_binary, file_list, backup_path, dry=config.dry)
]:
rsync(config.rsync_binary, hidden_file, backup_path, dry=config.dry)
def synchroniseRunnerWorkingDirectory(config, backup_path): def synchroniseRunnerWorkingDirectory(config, backup_path):
if os.path.isdir('instance'): if os.path.isdir('instance'):
exclude_list = getExcludePathList('.') exclude_list = getExcludePathList('.')
rsync( rsync(
config.rsync_binary, 'instance', backup_path, config.rsync_binary, 'instance', backup_path,
["--exclude={}".format(x) for x in exclude_list], ["--exclude={}".format(x) for x in exclude_list],
dry=config.dry, dry=config.dry,
) )
file_list = []
for file in ('project', 'public', 'proxy.db'): for file in ('project', 'public', 'proxy.db'):
if os.path.exists(file): if os.path.exists(file):
rsync(config.rsync_binary, file, backup_path, dry=config.dry) file_list.append(file)
if file_list:
rsync(config.rsync_binary, file_list, backup_path, dry=config.dry)
def getSlappartSignatureMethodDict(): def getSlappartSignatureMethodDict():
......
...@@ -136,15 +136,9 @@ class TestRunnerExporter(unittest.TestCase): ...@@ -136,15 +136,9 @@ class TestRunnerExporter(unittest.TestCase):
runner_exporter.synchroniseRunnerConfigurationDirectory( runner_exporter.synchroniseRunnerConfigurationDirectory(
config, 'backup/runner/etc/' config, 'backup/runner/etc/'
) )
self.assertEqual(check_call_mock.call_count, 3) self.assertEqual(check_call_mock.call_count, 1)
check_call_mock.assert_any_call( check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', 'config.json', 'backup/runner/etc/'] ['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', 'config.json', '.parameters.xml', '.project', 'backup/runner/etc/']
)
check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '.project', 'backup/runner/etc/']
)
check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '.project', 'backup/runner/etc/']
) )
...@@ -159,11 +153,12 @@ class TestRunnerExporter(unittest.TestCase): ...@@ -159,11 +153,12 @@ class TestRunnerExporter(unittest.TestCase):
config, 'backup/runner/runner' config, 'backup/runner/runner'
) )
self.assertEqual(check_call_mock.call_count, 2)
check_call_mock.assert_any_call( check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '--exclude=*.sock', '--exclude=*.socket', '--exclude=*.pid', '--exclude=.installed*.cfg', '--exclude=srv/backup/**', '--exclude=instance/slappart0/etc/nicolas.txt', '--exclude=instance/slappart0/etc/rafael.txt', '--exclude=srv/exporter.exclude', 'instance', 'backup/runner/runner'] ['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '--exclude=*.sock', '--exclude=*.socket', '--exclude=*.pid', '--exclude=.installed*.cfg', '--exclude=srv/backup/**', '--exclude=instance/slappart0/etc/nicolas.txt', '--exclude=instance/slappart0/etc/rafael.txt', '--exclude=srv/exporter.exclude', 'instance', 'backup/runner/runner']
) )
check_call_mock.assert_any_call( check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', 'proxy.db', 'backup/runner/runner'] ['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', 'project', 'public', 'proxy.db', 'backup/runner/runner']
) )
def test_getSlappartSignatureMethodDict(self): def test_getSlappartSignatureMethodDict(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment