def choose_sync_strategies(self):
        """Determines the sync strategy for the command.

        It defaults to the default sync strategies but a customizable sync
        strategy can overide the default strategy if it returns the instance
        of its self when the event is emitted.
        """
        sync_strategies = {}
        # Set the default strategies.
        sync_strategies['file_at_src_and_dest_sync_strategy'] = \
            SizeAndLastModifiedSync()
        sync_strategies['file_not_at_dest_sync_strategy'] = MissingFileSync()
        sync_strategies['file_not_at_src_sync_strategy'] = NeverSync()

        # Determine what strategies to overide if any.
        responses = self.session.emit('choosing-s3-sync-strategy',
                                      params=self.parameters)
        if responses is not None:
            for response in responses:
                override_sync_strategy = response[1]
                if override_sync_strategy is not None:
                    sync_type = override_sync_strategy.sync_type
                    sync_type += '_sync_strategy'
                    sync_strategies[sync_type] = override_sync_strategy

        return sync_strategies
Exemple #2
0
class TestNeverSync(unittest.TestCase):
    def setUp(self):
        self.sync_strategy = NeverSync()

    def test_constructor(self):
        self.assertEqual(self.sync_strategy.sync_type, 'file_not_at_src')

    def test_determine_should_sync(self):
        time_dst = datetime.datetime.now()

        dst_file = FileStat(src='', dest='',
                            compare_key='test.py', size=10,
                            last_update=time_dst, src_type='s3',
                            dest_type='local', operation_name='')

        should_sync = self.sync_strategy.determine_should_sync(
            None, dst_file)
        self.assertFalse(should_sync)
Exemple #3
0
class TestNeverSync(unittest.TestCase):
    def setUp(self):
        self.sync_strategy = NeverSync()

    def test_constructor(self):
        self.assertEqual(self.sync_strategy.sync_type, 'file_not_at_src')

    def test_determine_should_sync(self):
        time_dst = datetime.datetime.now()

        dst_file = FileStat(src='',
                            dest='',
                            compare_key='test.py',
                            size=10,
                            last_update=time_dst,
                            src_type='s3',
                            dest_type='local',
                            operation_name='')

        should_sync = self.sync_strategy.determine_should_sync(None, dst_file)
        self.assertFalse(should_sync)
Exemple #4
0
 def setUp(self):
     self.sync_strategy = NeverSync()
Exemple #5
0
 def setUp(self):
     self.sync_strategy = NeverSync()