Ejemplo n.º 1
0
 def create_filter(self, filters=None, root=None, dst_root=None):
     if root is None:
         root = os.getcwd()
     if filters is None:
         filters = {}
     if dst_root is None:
         dst_root = 'bucket'
     return Filter(filters, root, dst_root)
Ejemplo n.º 2
0
 def create_filter(self,
                   filters=None,
                   root=None,
                   dst_root=None,
                   parameters=None):
     if root is None:
         root = os.getcwd()
     if filters is None:
         filters = {}
     if dst_root is None:
         dst_root = 'bucket'
     if parameters is not None:
         return create_filter(parameters)
     return Filter(filters, root, dst_root)
Ejemplo n.º 3
0
    def test_include(self):
        """
        Only an include file
        """
        patterns = [['--include', '*.txt']]
        exc_inc_filter = Filter({'filters': patterns})
        files = exc_inc_filter.call(iter(self.local_files))
        result_list = []
        for filename in files:
            result_list.append(filename)
        self.assertEqual(result_list, self.local_files)

        files = exc_inc_filter.call(iter(self.s3_files))
        result_list = []
        for filename in files:
            result_list.append(filename)
        self.assertEqual(result_list, self.s3_files)
Ejemplo n.º 4
0
    def test_no_filter(self):
        """
        No filters
        """
        patterns = []
        exc_inc_filter = Filter({})
        files = exc_inc_filter.call(iter(self.local_files))
        result_list = []
        for filename in files:
            result_list.append(filename)
        self.assertEqual(result_list, self.local_files)

        files = exc_inc_filter.call(iter(self.s3_files))
        result_list = []
        for filename in files:
            result_list.append(filename)
        self.assertEqual(result_list, self.s3_files)
Ejemplo n.º 5
0
    def test_include_exclude(self):
        """
        Include all .txt files then exclude everything
        """
        patterns = [['--include', '*.txt'], ['--exclude', '*']]
        exc_inc_filter = Filter({'filters': patterns})
        files = exc_inc_filter.call(iter(self.local_files))
        result_list = []
        for filename in files:
            result_list.append(filename)
        self.assertEqual(result_list, [])

        files = exc_inc_filter.call(iter(self.s3_files))
        result_list = []
        for filename in files:
            result_list.append(filename)
        self.assertEqual(result_list, [])
Ejemplo n.º 6
0
    def run(self):
        """
        This function wires together all of the generators and completes
        the command.  First a dictionary is created that is indexed first by
        the command name.  Then using the instruction, another dictionary
        can be indexed to obtain the objects corresponding to the
        particular instruction for that command.  To begin the wiring,
        either a ``FileFormat`` or ``TaskInfo`` object, depending on the
        command, is put into a list.  Then the function enters a while loop
        that pops off an instruction.  It then determines the object needed
        and calls the call function of the object using the list as the input.
        Depending on the number of objects in the input list and the number
        of components in the list corresponding to the instruction, the call
        method of the component can be called two different ways.  If the
        number of inputs is equal to the number of components a 1:1 mapping of
        inputs to components is used when calling the call function.  If the
        there are more inputs than components, then a 2:1 mapping of inputs to
        components is used where the component call method takes two inputs
        instead of one.  Whatever files are yielded from the call function
        is appended to a list and used as the input for the next repetition
        of the while loop until there are no more instructions.
        """
        src = self.parameters['src']
        dest = self.parameters['dest']
        paths_type = self.parameters['paths_type']
        files = FileFormat().format(src, dest, self.parameters)
        rev_files = FileFormat().format(dest, src, self.parameters)

        cmd_translation = {}
        cmd_translation['locals3'] = {
            'cp': 'upload',
            'sync': 'upload',
            'mv': 'move'
        }
        cmd_translation['s3s3'] = {'cp': 'copy', 'sync': 'copy', 'mv': 'move'}
        cmd_translation['s3local'] = {
            'cp': 'download',
            'sync': 'download',
            'mv': 'move'
        }
        cmd_translation['s3'] = {
            'rm': 'delete',
            'ls': 'list_objects',
            'mb': 'make_bucket',
            'rb': 'remove_bucket'
        }
        operation = cmd_translation[paths_type][self.cmd]

        file_generator = FileGenerator(self.session, operation,
                                       self.parameters)
        rev_generator = FileGenerator(self.session, '', self.parameters)
        taskinfo = [
            TaskInfo(src=files['src']['path'],
                     src_type='s3',
                     operation=operation)
        ]
        s3handler = S3Handler(self.session, self.parameters)

        command_dict = {}
        command_dict['sync'] = {
            'setup': [files, rev_files],
            'file_generator': [file_generator, rev_generator],
            'filters': [Filter(self.parameters),
                        Filter(self.parameters)],
            'comparator': [Comparator(self.parameters)],
            's3_handler': [s3handler]
        }

        command_dict['cp'] = {
            'setup': [files],
            'file_generator': [file_generator],
            'filters': [Filter(self.parameters)],
            's3_handler': [s3handler]
        }

        command_dict['rm'] = {
            'setup': [files],
            'file_generator': [file_generator],
            'filters': [Filter(self.parameters)],
            's3_handler': [s3handler]
        }

        command_dict['mv'] = {
            'setup': [files],
            'file_generator': [file_generator],
            'filters': [Filter(self.parameters)],
            's3_handler': [s3handler]
        }

        command_dict['ls'] = {'setup': [taskinfo], 's3_handler': [s3handler]}

        command_dict['mb'] = {'setup': [taskinfo], 's3_handler': [s3handler]}

        command_dict['rb'] = {'setup': [taskinfo], 's3_handler': [s3handler]}

        files = command_dict[self.cmd]['setup']

        while self.instructions:
            instruction = self.instructions.pop(0)
            file_list = []
            components = command_dict[self.cmd][instruction]
            for i in range(len(components)):
                if len(files) > len(components):
                    file_list.append(components[i].call(*files))
                else:
                    file_list.append(components[i].call(files[i]))
            files = file_list
Ejemplo n.º 7
0
 def create_filter(self, filters=None, root=None):
     if root is None:
         root = os.getcwd()
     if filters is None:
         filters = {}
     return Filter(filters, root)