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


Python files.get_directory_files_list函数代码示例

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


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

示例1: test_copy_to_multiple_directories

    def test_copy_to_multiple_directories(self):
        """Copy files into multiple directories.
        """
        dir1 = tempfile.mkdtemp()
        dir2 = tempfile.mkdtemp()
        dirs = [dir1, dir2]
        file_1_obj = tempfile.NamedTemporaryFile(suffix='.txt')
        file_2_obj = tempfile.NamedTemporaryFile(suffix='.txt')
        file_3_obj = tempfile.NamedTemporaryFile(suffix='.txt')
        files = [file_1_obj.name, file_2_obj.name, file_3_obj.name]

        self._ftp.copy_to_multiple_directories(dirs, files)

        # Check target dirs.
        for dir in dirs:
            tmp_files = get_directory_files_list(dir)
            received = [os.path.basename(x) for x in tmp_files]
            expected = [os.path.basename(x) for x in files]
            msg = 'Mutliple dir copy - %s listing error' % dir
            self.assertListEqual(sorted(received), sorted(expected), msg)

        # Clean up.
        file_1_obj.close()
        file_2_obj.close()
        file_3_obj.close()
        for dir in dirs:
            remove_files(get_directory_files_list(dir))
            os.removedirs(dir)
开发者ID:loum,项目名称:top,代码行数:28,代码来源:test_ftp.py

示例2: test_signature_archive_selective

    def test_signature_archive_selective(self):
        """Archive signature file -- only *.ps files.
        """
        # Define the archive directory.
        archive_dir = tempfile.mkdtemp()
        self._e.set_signature_dir(self._dir)

        # Create a dummy signature files.
        dummy_files = ['22222.ps', '22222.png']
        for i in dummy_files:
            sig_file = os.path.join(self._e.signature_dir, i)
            fh = open(sig_file, 'w')
            fh.close()

        archive_control = {'ps': True,
                           'png': False}
        self._e.archive_signature_file(22222,
                                       archive_control,
                                       self._e.signature_dir,
                                       archive_dir)

        # Check that the file now exists in archive.
        digest_path = gen_digest_path('22222')
        archive_digest_path = os.path.join(archive_dir, *digest_path)
        received = get_directory_files_list(archive_digest_path)
        expected = [os.path.join(archive_digest_path, '22222.ps')]
        msg = 'Signature file archive directory should succeed -- ps only'
        self.assertListEqual(received, expected, msg)

        # Cleanup
        self._e.reset()
        remove_files(get_directory_files_list(self._e.signature_dir))
        remove_files(received)
        self._e.set_signature_dir(None)
        os.removedirs(archive_digest_path)
开发者ID:loum,项目名称:top,代码行数:35,代码来源:test_exporter.py

示例3: get_files

    def get_files(self):
        """Searches the :attr:`adp_in_dirs` directories for TCD report
        files.

        **Returns:**
            list of ADP bulk load files

        """
        files = []

        for dir in self.adp_in_dirs:
            log.debug('Searching "%s" for ADP bulk insert files' % dir)
            if len(self.adp_file_formats):
                for format in self.adp_file_formats:
                    files.extend(get_directory_files_list(dir, format))
            else:
                files.extend(get_directory_files_list(dir))

        # Convert xlsx file to csv.
        converted_files = []
        for f in files:
            tmp_file = xlsx_to_csv_converter(f)
            if tmp_file is not None:
                converted_files.append(tmp_file)

        log.debug('All ADP bulk load files: "%s"' % converted_files)

        return converted_files
开发者ID:loum,项目名称:top,代码行数:28,代码来源:adpdaemon.py

示例4: test_inbound

    def test_inbound(self):
        """Inbound file transfer.
        """
        dir = self._ftp_dir
        t_files = get_directory_files_list(os.path.join(self._test_dir,
                                                        'returns'))
        for f in t_files:
            copy_file(f, os.path.join(dir, os.path.basename(f)))

        # Prepare the config.
        self._ftp.config.add_section('ftp_in')
        self._ftp.config.set('ftp_in', 'host', '127.0.0.1')
        self._ftp.config.set('ftp_in', 'port', '2121')
        self._ftp.config.set('ftp_in', 'user', 'tester')
        self._ftp.config.set('ftp_in', 'password', 'tester')
        self._ftp.config.set('ftp_in', 'filter', '.*_VANA_RE[PFI]_\d{14}\.txt')
        self._ftp.config.set('ftp_in', 'target', '')
        self._ftp.config.set('ftp_in', 'pod', 'yes')
        self._ftp._parse_config(file_based=False)

        self._ftp.inbound(self._ftp.xfers[0], dry=True)

        # Clean up.
        remove_files(get_directory_files_list(dir))
        self._ftp.reset_config()
开发者ID:loum,项目名称:top,代码行数:25,代码来源:test_ftp.py

示例5: test_move_signature_files_dry_pass

    def test_move_signature_files_dry_pass(self):
        """Move signature files -- dry pass.
        """
        dry = True

        source_dir = tempfile.mkdtemp()
        target_dir = tempfile.mkdtemp()
        sig_files = [os.path.join(source_dir, '03970006761.ps'),
                     os.path.join(source_dir, '03970006762.png')]
        for f in sig_files:
            fh = open(f, 'w')
            fh.close

        received = self._ptd.move_signature_files('03970006762',
                                                  source_dir,
                                                  target_dir,
                                                  dry=dry)
        msg = 'Signature file move error -- dry run'
        self.assertTrue(received, msg)

        # Check the source file exists.
        received = os.path.exists(os.path.join(source_dir,
                                               '03970006762.png'))
        self.assertTrue(received, msg)

        # Clean up.
        remove_files(get_directory_files_list(source_dir))
        remove_files(get_directory_files_list(target_dir))
        os.removedirs(source_dir)
        os.removedirs(target_dir)
开发者ID:loum,项目名称:top,代码行数:30,代码来源:test_podtranslatordaemon.py

示例6: test_get_files

    def test_get_files(self):
        """Get files from remote resource.
        """
        dir = self._ftp_dir
        t_files = get_directory_files_list(os.path.join(self._test_dir,
                                                        'returns'))
        remote_files = []
        for f in t_files:
            remote_files.append(os.path.basename(f))
            copy_file(f, os.path.join(dir, os.path.basename(f)))

        # Prepare the config.
        self._ftp.config.add_section('ftp_in')
        self._ftp.config.set('ftp_in', 'host', '127.0.0.1')
        self._ftp.config.set('ftp_in', 'port', '2121')
        self._ftp.config.set('ftp_in', 'user', 'tester')
        self._ftp.config.set('ftp_in', 'password', 'tester')
        self._ftp._parse_config(file_based=False)

        self._ftp.connect_resource(self._ftp.xfers[0])

        # No files to transfer.
        files_to_transfer = []
        received = self._ftp.get_files(files_to_transfer,
                                       target_dir=self._dir,
                                       dry=False)
        expected = []
        msg = 'No files to retrieve error'
        self.assertListEqual(received, expected, msg)

        # Single file transfer.
        files_to_transfer = ['VIC_VANA_REF_20131114073201.txt']
        received = self._ftp.get_files(files_to_transfer,
                                       target_dir=self._dir,
                                       dry=False)
        expected = get_directory_files_list(self._dir)
        ret = expected
        msg = 'Single file retrieved error'
        self.assertListEqual(received, expected, msg)

        # Report files to transfer.
        del expected[:]
        received = self._ftp.get_files(remote_files,
                                       target_dir=self._dir,
                                       dry=False)
        expected = get_directory_files_list(self._dir)
        msg = 'Retrieved multiple file list error'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Clean up.
        self._ftp.disconnect_resource()
        remove_files(get_directory_files_list(self._dir))
        remove_files(get_directory_files_list(dir))
        self._ftp.reset_config()
开发者ID:loum,项目名称:top,代码行数:54,代码来源:test_ftp.py

示例7: test_process

    def test_process(self):
        """Test the process cycle.
        """
        t_files = ['VIC_VANA_REP_20131108145146.txt',
                   '142828.ps',
                   '145563.ps',
                   '145601.ps',
                   '145661.ps']
        dir = tempfile.mkdtemp()
        for f in t_files:
            copy_file(os.path.join(self._test_dir, f), os.path.join(dir, f))

        # Prepare the config.
        self._ftp.config.add_section('ftp_t')
        self._ftp.config.set('ftp_t', 'host', '127.0.0.1')
        self._ftp.config.set('ftp_t', 'port', '2121')
        self._ftp.config.set('ftp_t', 'user', 'tester')
        self._ftp.config.set('ftp_t', 'password', 'tester')
        self._ftp.config.set('ftp_t', 'source', dir)
        self._ftp.config.set('ftp_t', 'filter', 'VIC_VANA_REP_\d{14}\.txt')
        self._ftp.config.set('ftp_t', 'target', '')
        self._ftp.config.set('ftp_t', 'pod', 'yes')
        self._ftp._parse_config(file_based=False)

        self._ftp.process(dry=False)

        # Check archive directory.
        ymd = datetime.datetime.now().strftime('%Y%m%d')
        archive_dir = os.path.join(self._ftp.archive_dir, 'tester', ymd)

        received = get_directory_files_list(archive_dir)
        expected = [os.path.join(archive_dir, x) for x in t_files]
        msg = 'Archive directory list not as expected'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Check FTP inbound directory.
        received = get_directory_files_list(self._ftpserver.dir)
        expected = [os.path.join(self._ftpserver.dir, x) for x in t_files]
        msg = 'FTP inbound directory list not as expected'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Clean up.
        for f in t_files:
            remove_files(os.path.join(self._ftp_dir, f))
            remove_files(os.path.join(archive_dir, f))
        os.removedirs(dir)
        os.rmdir(os.path.join(archive_dir))
        os.rmdir(os.path.join(self._ftp.archive_dir, 'tester'))
        self._ftp.reset_config()
开发者ID:loum,项目名称:top,代码行数:49,代码来源:test_ftp.py

示例8: test_process_pe_sms_error_comms

    def test_process_pe_sms_error_comms(self):
        """Test processing -- primary elect SMS error comms.
        """
        dry = True

        files = ['email.3.pe', 'sms.3.pe']

        dir = tempfile.mkdtemp()
        comms_files = []
        for f in files:
            fh = open(os.path.join(dir, f), 'w')
            comms_files.append(fh.name)
            fh.close()

        # Provide a dodgy mobile.
        sql = """UPDATE job_item
SET phone_nbr = '0531602145'
WHERE id = 3"""
        self._c.db(sql)

        for file in comms_files:
            received = self._c.process(file, dry=dry)
            msg = 'Primary Elect comms files processed incorrect'
            if os.path.basename(file) == 'email.3.pe':
                self.assertTrue(received, msg)
            else:
                self.assertFalse(received, msg)

        # Cleanup.
        remove_files(get_directory_files_list(dir))
        os.removedirs(dir)
        self._c.db.rollback()
开发者ID:loum,项目名称:top,代码行数:32,代码来源:test_comms.py

示例9: test_process_returns_err_sms

    def test_process_returns_err_sms(self):
        """Test processing -- returns with an invalid SMS.
        """
        dry = True

        # Provide a dodgy mobile.
        sql = """UPDATE returns
SET phone_nbr = '0531602145'
WHERE id = 2"""
        self._c.db(sql)

        files = ['email.2.ret', 'sms.2.ret']

        dir = tempfile.mkdtemp()
        comms_files = []
        for f in files:
            fh = open(os.path.join(dir, f), 'w')
            comms_files.append(fh.name)
            fh.close()

        for file in comms_files:
            received = self._c.process(file, dry=dry)
            msg = 'Returns comms files with invalid SMS error'
            if os.path.basename(file) == 'email.2.ret':
                self.assertTrue(received, msg)
            else:
                self.assertFalse(received, msg)

        # Cleanup.
        remove_files(get_directory_files_list(dir))
        os.removedirs(dir)
        self._c.db.rollback()
开发者ID:loum,项目名称:top,代码行数:32,代码来源:test_comms.py

示例10: test_process_reminder_email_error_comms

    def test_process_reminder_email_error_comms(self):
        """Test processing -- reminder email error comms.
        """
        dry = True

        files = ['email.6.rem', 'sms.6.rem']

        dir = tempfile.mkdtemp()
        comms_files = []
        for f in files:
            fh = open(os.path.join(dir, f), 'w')
            comms_files.append(fh.name)
            fh.close()

        # Provide a dodgy email.
        sql = """UPDATE job_item
SET email_addr = '@@@tollgroup.com'
WHERE id = 6"""
        self._c.db(sql)

        for file in comms_files:
            received = self._c.process(file, dry=dry)
            msg = 'Email error reminder comms files processed incorrect'
            if os.path.basename(file) == 'sms.6.rem':
                self.assertTrue(received, msg)
            else:
                self.assertFalse(received, msg)

        # Cleanup.
        remove_files(get_directory_files_list(dir))
        os.removedirs(dir)
        self._c.db.rollback()
开发者ID:loum,项目名称:top,代码行数:32,代码来源:test_comms.py

示例11: test_processor_valid_record_with_matched_dp_trigger

    def test_processor_valid_record_with_matched_dp_trigger(self):
        """Process valid raw T1250 line -- matched delivery partner trigger.
        """
        # Seed the Agent Id.
        agent_fields = {'code': 'N031',
                        'dp_id': 1}
        self._ldr.db(self._ldr.db._agent.insert_sql(agent_fields))
        dps = ['Nparcel']

        msg = 'Valid T1250 record should process OK'
        line = self._c.get('test_lines', 'VALID_LINE_WITH_RECIPIENTS')
        self.assertTrue(self._ldr.process(self._job_ts,
                                          line,
                                          FILE_BU.get('tolp'),
                                          COND_MAP_COMMS,
                                          dps), msg)

        # With comms enabled, we should have comms flag files.
        received = get_directory_files_list(self._comms_dir)
        sql = """SELECT id
FROM job_item"""
        self._ldr.db(sql)
        expected = []
        for row in self._ldr.db.rows():
            expected.append(os.path.join(self._comms_dir, '%s.%d.%s') %
                            ('email', row[0], 'body'))
            expected.append(os.path.join(self._comms_dir, '%s.%d.%s') %
                            ('sms', row[0], 'body'))
        msg = 'Comms directory file list error'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Restore DB state and clean.
        remove_files(received)
        self._ldr.db.rollback()
开发者ID:loum,项目名称:top,代码行数:34,代码来源:test_loader.py

示例12: test_distribute_file_archive

    def test_distribute_file_archive(self):
        """Distribute the T1250 file (archive).
        """
        base_dir = tempfile.mkdtemp()
        source_dir = os.path.join(base_dir, 'ipec', 'in')
        create_dir(source_dir)
        archive_dir = tempfile.mkdtemp()
        old_archive_dir = self._d.config.archive_dir
        self._d.config.set_archive_dir(archive_dir)

        # Fudge a T1250.
        test_file = 'T1250_TOLI_20130828202901.txt'
        fh = open(os.path.join(source_dir, test_file), 'w')
        fh.close()

        expected_archive_dir = os.path.join(archive_dir,
                                           'ipec',
                                           '20130828')

        # Test the archive.
        self._d.distribute_file(os.path.join(source_dir, test_file))
        received = get_directory_files_list(expected_archive_dir)
        expected = [os.path.join(expected_archive_dir, test_file)]
        msg = 'Archived file error'
        self.assertListEqual(received, expected, msg)

        # Cleanup.
        os.remove(os.path.join(expected_archive_dir, test_file))
        os.removedirs(source_dir)
        os.removedirs(expected_archive_dir)
        self._d.config.set_archive_dir(old_archive_dir)
开发者ID:loum,项目名称:top,代码行数:31,代码来源:test_loaderdaemon.py

示例13: test_start_non_dry

    def test_start_non_dry(self):
        """Start non-dry loop.
        """
        comms_files = ['email.8.rem', 'sms.8.rem']
        dry = False

        old_dry = self._rd.dry
        old_batch = self._rd.batch

        # Start processing.
        self._rd.set_dry(dry)
        self._rd.set_batch()
        self._rd._start(self._rd.exit_event)

        # Check that the reminder comms event files were created.
        comms_dir = self._rd._config.comms_dir
        received = get_directory_files_list(comms_dir)
        expected = [os.path.join(comms_dir, x) for x in comms_files]
        msg = 'List of reminder comms event files not as expected'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Clean up.
        remove_files(expected)
        self._rd.set_dry(old_dry)
        self._rd.set_batch(old_batch)
        self._rd.exit_event.clear()
开发者ID:loum,项目名称:top,代码行数:26,代码来源:test_reminderdaemon.py

示例14: test_filter_file_list

    def test_filter_file_list(self):
        """Filter file list.
        """
        t_dir = os.path.join(self._test_dir, 'returns')
        t_files = get_directory_files_list(t_dir)

        format = 'banana'
        received = self._ftp.filter_file_list(t_files, format)
        expected = []
        msg = '"%s" filter list error' % format
        self.assertListEqual(received, expected, msg)

        format = 'VIC_VANA_REP_\d{14}\.txt'
        received = self._ftp.filter_file_list(t_files, format)
        priority_rep_file = ['VIC_VANA_REP_20131114044105.txt',
                             'VIC_VANA_REP_20131114050106.txt']
        expected = [os.path.join(t_dir, x) for x in priority_rep_file]
        msg = '"%s" filter list error' % format
        self.assertListEqual(sorted(received), sorted(expected), msg)

        format = 'VIC_VANA_REI_\d{14}\.txt'
        received = self._ftp.filter_file_list(t_files, format)
        priority_rep_file = ['VIC_VANA_REI_20131114044602.txt',
                             'VIC_VANA_REI_20131114045103.txt',
                             'VIC_VANA_REI_20131114045604.txt']
        expected = [os.path.join(t_dir, x) for x in priority_rep_file]
        msg = '"%s" filter list error' % format
        self.assertListEqual(sorted(received), sorted(expected), msg)
开发者ID:loum,项目名称:top,代码行数:28,代码来源:test_ftp.py

示例15: test_process_loader

    def test_process_loader(self):
        """Test processing -- loader.
        """
        dry = True

        files = ['email.1.body', 'sms.1.body',
                 'email.2.body', 'sms.2.body',
                 'email.6.body', 'sms.6.body']
        dodgy = ['banana', 'email.rem.3']

        dir = tempfile.mkdtemp()
        comms_files = []
        for f in files + dodgy:
            fh = open(os.path.join(dir, f), 'w')
            comms_files.append(fh.name)
            fh.close()

        for file in comms_files:
            received = self._c.process(file, dry=dry)
            msg = 'Loader comms files processing error'
            filename = os.path.basename(file)
            if (filename == 'email.2.body' or
                filename == 'sms.2.body' or
                filename == 'email.6.body' or
                filename == 'sms.6.body'):
                self.assertTrue(received, msg)
            else:
                self.assertFalse(received, msg)

        # Cleanup.
        remove_files(get_directory_files_list(dir))
        os.removedirs(dir)
        self._c.db.rollback()
开发者ID:loum,项目名称:top,代码行数:33,代码来源:test_comms.py


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