当前位置: 首页>>代码示例>>Python>>正文


Python filegenerator.FileGenerator类代码示例

本文整理汇总了Python中awscli.customizations.s3.filegenerator.FileGenerator的典型用法代码示例。如果您正苦于以下问题:Python FileGenerator类的具体用法?Python FileGenerator怎么用?Python FileGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_s3_file

    def test_s3_file(self):
        """
        Generate a single s3 file
        Note: Size and last update are not tested because s3 generates them.
        """
        input_s3_file = {'src': {'path': self.file1, 'type': 's3'},
                         'dest': {'path': 'text1.txt', 'type': 'local'},
                         'dir_op': False, 'use_src_name': False}
        params = {'region': 'us-east-1'}
        self.parsed_responses = [{"ETag": "abcd", "ContentLength": 100,
                                  "LastModified": "2014-01-09T20:45:49.000Z"}]
        self.patch_make_request()

        file_gen = FileGenerator(self.client, '')
        files = file_gen.call(input_s3_file)
        result_list = []
        for filename in files:
            result_list.append(filename)
        file_stat = FileStat(src=self.file1, dest='text1.txt',
                             compare_key='text1.txt',
                             size=result_list[0].size,
                             last_update=result_list[0].last_update,
                             src_type='s3',
                             dest_type='local', operation_name='')

        ref_list = [file_stat]
        self.assertEqual(len(result_list), len(ref_list))
        for i in range(len(result_list)):
            compare_files(self, result_list[i], ref_list[i])
开发者ID:mtdowling,项目名称:aws-cli,代码行数:29,代码来源:test_filegenerator.py

示例2: test_warn_bad_symlink

 def test_warn_bad_symlink(self):
     """
     This tests to make sure it fails when following bad symlinks.
     """
     abs_root = six.text_type(os.path.abspath(self.root) + os.sep)
     input_local_dir = {'src': {'path': abs_root,
                                'type': 'local'},
                        'dest': {'path': self.bucket,
                                 'type': 's3'},
                        'dir_op': True, 'use_src_name': True}
     file_stats = FileGenerator(self.service, self.endpoint,
                                '', True).call(input_local_dir)
     file_gen = FileGenerator(self.service, self.endpoint, '', True)
     file_stats = file_gen.call(input_local_dir)
     all_filenames = self.filenames + self.symlink_files
     all_filenames.sort()
     result_list = []
     for file_stat in file_stats:
         result_list.append(getattr(file_stat, 'src'))
     self.assertEqual(len(result_list), len(all_filenames))
     # Just check to make sure the right local files are generated.
     for i in range(len(result_list)):
         filename = six.text_type(os.path.abspath(all_filenames[i]))
         self.assertEqual(result_list[i], filename)
     self.assertFalse(file_gen.result_queue.empty())
开发者ID:emyphan,项目名称:aws-cli,代码行数:25,代码来源:test_filegenerator.py

示例3: test_s3_file

    def test_s3_file(self):
        """
        Generate a single s3 file
        Note: Size and last update are not tested because s3 generates them.
        """
        input_s3_file = {'src': {'path': self.file1, 'type': 's3'},
                         'dest': {'path': 'text1.txt', 'type': 'local'},
                         'dir_op': False, 'use_src_name': False}
        params = {'region': 'us-east-1'}
        file_gen = FileGenerator(self.service, self.endpoint, '')
        files = file_gen.call(input_s3_file)
        result_list = []
        for filename in files:
            result_list.append(filename)
        file_stat = FileStat(src=self.file1, dest='text1.txt',
                             compare_key='text1.txt',
                             size=result_list[0].size,
                             last_update=result_list[0].last_update,
                             src_type='s3',
                             dest_type='local', operation_name='')

        ref_list = [file_stat]
        self.assertEqual(len(result_list), len(ref_list))
        for i in range(len(result_list)):
            compare_files(self, result_list[i], ref_list[i])
开发者ID:emyphan,项目名称:aws-cli,代码行数:25,代码来源:test_filegenerator.py

示例4: test_no_warning

 def test_no_warning(self):
     file_gen = FileGenerator(self.service, self.endpoint, '', False)
     self.files.create_file("foo.txt", contents="foo")
     full_path = os.path.join(self.root, "foo.txt")
     return_val = file_gen.triggers_warning(full_path)
     self.assertFalse(return_val)
     self.assertTrue(file_gen.result_queue.empty())
开发者ID:emyphan,项目名称:aws-cli,代码行数:7,代码来源:test_filegenerator.py

示例5: test_error_raised_on_decoding_error

 def test_error_raised_on_decoding_error(self, listdir_mock):
     # On Python3, sys.getdefaultencoding
     file_generator = FileGenerator(None, None, None, None)
     # utf-8 encoding for U+2713.
     listdir_mock.return_value = [b'\xe2\x9c\x93']
     with self.assertRaises(FileDecodingError):
         list(file_generator.list_files(self.directory, dir_op=True))
开发者ID:HackedByChinese,项目名称:aws-cli,代码行数:7,代码来源:test_filegenerator.py

示例6: test_list_local_files_with_unicode_chars

    def test_list_local_files_with_unicode_chars(self):
        p = os.path.join
        open(p(self.directory, u"a"), "w").close()
        open(p(self.directory, u"a\u0300"), "w").close()
        open(p(self.directory, u"a\u0300-1"), "w").close()
        open(p(self.directory, u"a\u03001"), "w").close()
        open(p(self.directory, u"z"), "w").close()
        open(p(self.directory, u"\u00e6"), "w").close()
        os.mkdir(p(self.directory, u"a\u0300a"))
        open(p(self.directory, u"a\u0300a", u"a"), "w").close()
        open(p(self.directory, u"a\u0300a", u"z"), "w").close()
        open(p(self.directory, u"a\u0300a", u"\u00e6"), "w").close()

        file_generator = FileGenerator(None, None, None, None)
        values = list(el[0] for el in file_generator.list_files(self.directory, dir_op=True))
        expected_order = [
            os.path.join(self.directory, el)
            for el in [
                u"a",
                u"a\u0300",
                u"a\u0300-1",
                u"a\u03001",
                u"a\u0300a%sa" % os.path.sep,
                u"a\u0300a%sz" % os.path.sep,
                u"a\u0300a%s\u00e6" % os.path.sep,
                u"z",
                u"\u00e6",
            ]
        ]
        self.assertEqual(values, expected_order)
开发者ID:CitizenB,项目名称:aws-cli,代码行数:30,代码来源:test_filegenerator.py

示例7: test_normalize_sort_backslash

 def test_normalize_sort_backslash(self):
     names = ['xyz123456789',
              'xyz1\\test',
              'xyz\\test']
     ref_names = [names[2], names[1], names[0]]
     filegenerator = FileGenerator(None, None, None)
     filegenerator.normalize_sort(names, '\\', '/')
     for i in range(len(ref_names)):
         self.assertEqual(ref_names[i], names[i])
开发者ID:emyphan,项目名称:aws-cli,代码行数:9,代码来源:test_filegenerator.py

示例8: test_no_exists

 def test_no_exists(self):
     file_gen = FileGenerator(self.service, self.endpoint, '', False)
     filename = os.path.join(self.root, 'file')
     return_val = file_gen.triggers_warning(filename)
     self.assertTrue(return_val)
     warning_message = file_gen.result_queue.get()
     self.assertEqual(warning_message.message,
                      ("warning: Skipping file %s. File does not exist." %
                       filename))
开发者ID:emyphan,项目名称:aws-cli,代码行数:9,代码来源:test_filegenerator.py

示例9: test_no_skip_symlink_dir

 def test_no_skip_symlink_dir(self):
     filename = 'dir'
     path = os.path.join(self.files.rootdir, 'dir/')
     os.mkdir(path)
     sym_path = os.path.join(self.files.rootdir, 'symlink')
     os.symlink(path, sym_path)
     filegenerator = FileGenerator(self.client, '', True)
     self.assertFalse(filegenerator.should_ignore_file(sym_path))
     self.assertFalse(filegenerator.should_ignore_file(path))
开发者ID:mtdowling,项目名称:aws-cli,代码行数:9,代码来源:test_filegenerator.py

示例10: test_skip_symlink

 def test_skip_symlink(self):
     filename = 'foo.txt'
     self.files.create_file(os.path.join(self.files.rootdir,
                            filename),
                            contents='foo.txt contents')
     sym_path = os.path.join(self.files.rootdir, 'symlink')
     os.symlink(filename, sym_path)
     filegenerator = FileGenerator(self.client, '', False)
     self.assertTrue(filegenerator.should_ignore_file(sym_path))
开发者ID:mtdowling,项目名称:aws-cli,代码行数:9,代码来源:test_filegenerator.py

示例11: test_normalize_sort

 def test_normalize_sort(self):
     names = ['xyz123456789',
              'xyz1' + os.path.sep + 'test',
              'xyz' + os.path.sep + 'test']
     ref_names = [names[2], names[1], names[0]]
     filegenerator = FileGenerator(None, None, None)
     filegenerator.normalize_sort(names, os.path.sep, '/')
     for i in range(len(ref_names)):
         self.assertEqual(ref_names[i], names[i])
开发者ID:emyphan,项目名称:aws-cli,代码行数:9,代码来源:test_filegenerator.py

示例12: test_no_skip_symlink

 def test_no_skip_symlink(self):
     filename = 'foo.txt'
     path = self.files.create_file(os.path.join(self.files.rootdir,
                                                filename),
                                   contents='foo.txt contents')
     sym_path = os.path.join(self.files.rootdir, 'symlink')
     os.symlink(path, sym_path)
     filegenerator = FileGenerator(self.service, self.endpoint,
                                   '', True)
     self.assertFalse(filegenerator.should_ignore_file(sym_path))
     self.assertFalse(filegenerator.should_ignore_file(path))
开发者ID:emyphan,项目名称:aws-cli,代码行数:11,代码来源:test_filegenerator.py

示例13: test_list_files_is_in_sorted_order

    def test_list_files_is_in_sorted_order(self):
        p = os.path.join
        open(p(self.directory, "test-123.txt"), "w").close()
        open(p(self.directory, "test-321.txt"), "w").close()
        open(p(self.directory, "test123.txt"), "w").close()
        open(p(self.directory, "test321.txt"), "w").close()
        os.mkdir(p(self.directory, "test"))
        open(p(self.directory, "test", "foo.txt"), "w").close()

        file_generator = FileGenerator(None, None, None, None)
        values = list(el[0] for el in file_generator.list_files(self.directory, dir_op=True))
        self.assertEqual(values, list(sorted(values)))
开发者ID:CitizenB,项目名称:aws-cli,代码行数:12,代码来源:test_filegenerator.py

示例14: test_error_raised_on_decoding_error

 def test_error_raised_on_decoding_error(self, listdir_mock):
     # On Python3, sys.getdefaultencoding
     file_generator = FileGenerator(None, None, None)
     # utf-8 encoding for U+2713.
     listdir_mock.return_value = [b'\xe2\x9c\x93']
     list(file_generator.list_files(self.directory, dir_op=True))
     # Ensure the message was added to the result queue and is
     # being skipped.
     self.assertFalse(file_generator.result_queue.empty())
     warning_message = file_generator.result_queue.get()
     self.assertIn("warning: Skipping file ", warning_message.message)
     self.assertIn("Please check your locale settings.",
                   warning_message.message)
开发者ID:emyphan,项目名称:aws-cli,代码行数:13,代码来源:test_filegenerator.py

示例15: test_is_special_file_warning

 def test_is_special_file_warning(self):
     file_gen = FileGenerator(self.service, self.endpoint, '', False)
     file_path = os.path.join(self.files.rootdir, 'foo')
     # Use socket for special file.
     sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     sock.bind(file_path)
     return_val = file_gen.triggers_warning(file_path)
     self.assertTrue(return_val)
     warning_message = file_gen.result_queue.get()
     self.assertEqual(warning_message.message,
                      ("warning: Skipping file %s. File is character "
                       "special device, block special device, FIFO, or "
                       "socket." % file_path))
开发者ID:emyphan,项目名称:aws-cli,代码行数:13,代码来源:test_filegenerator.py


注:本文中的awscli.customizations.s3.filegenerator.FileGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。