• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python files.remove_files函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_process_comms_exists

    def test_process_comms_exists(self):
        """Check processing -- comms already exists.
        """
        dry = False

        comms_err_file = os.path.join(self._comms_dir, 'email.%d.pe' % 12)
        fh = open(comms_err_file, 'w')
        fh.close()

        kwargs = {'template': 'pe',
                  'service_code': 3,
                  'bu_ids': (1, 2, 3),
                  'delivery_partners': ('Nparcel', ),
                  'in_files': [self._test_file],
                  'dry': dry}
        received = self._on.process(**kwargs)
        expected = [10]
        msg = 'OnDelivery (comms already exists) processing error'
        self.assertListEqual(received, expected, msg)

        # Check that the comms files were written out.
        received = [os.path.join(self._comms_dir,
                                 x) for x in os.listdir(self._comms_dir)]
        received = [x for x in received if x != comms_err_file]
        expected = [os.path.join(self._comms_dir, '%s.%d.%s') %
                    ('email', 10, 'pe'),
                    os.path.join(self._comms_dir, '%s.%d.%s') %
                    ('sms', 10, 'pe')]
        msg = 'OnDelivery (comms already exists) comms directory list error'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Cleanup.
        remove_files(received)
        remove_files(comms_err_file)
开发者ID:loum,项目名称:top,代码行数:34,代码来源:test_ondelivery.py


示例2: test_write_new_file_handle

    def test_write_new_file_handle(self):
        """Write out T1250 file to new file handle.
        """
        dir = tempfile.mkdtemp()

        dry = False
        data = ('TOLP', 'data string')
        fhs = {}
        received = self._md.write(data, fhs, dir=dir, dry=dry)
        msg = 'T1250 write-out to new file handle should return True'
        self.assertTrue(received, msg)

        # Close file handles.
        files = []
        for fh in fhs.values():
            files.append(fh.name)
            fh.close()

        received = len(files)
        expected = 1
        msg = 'T1250 write-out should only produce 1 file'
        self.assertEqual(received, expected, msg)

        fh = open(files[0])
        received = fh.read().rstrip()
        expected = 'data string'
        msg = 'T1250 file content incorrect'
        self.assertEqual(received, expected, msg)

        # Clean up.
        remove_files([fhs[x].name for x in fhs.keys()])
        os.removedirs(dir)
开发者ID:loum,项目名称:top,代码行数:32,代码来源:test_mapperdaemon.py


示例3: 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


示例4: test_process_no_tcd_file

    def test_process_no_tcd_file(self):
        """Check processing -- no TCD file.
        """
        dry = False

        kwargs = {'template': 'pe',
                  'service_code': 3,
                  'bu_ids': (1, 2, 3),
                  'delivery_partners': ('Nparcel', ),
                  'dry': dry}
        received = self._on.process(**kwargs)
        expected = [12]
        msg = 'Processed primary elect should return values'
        self.assertListEqual(received, expected, msg)

        # Check that the comms files were written out.
        received = [os.path.join(self._comms_dir,
                                 x) for x in os.listdir(self._comms_dir)]
        expected = [os.path.join(self._comms_dir, '%s.%d.%s') %
                    ('email', 12, 'pe'),
                    os.path.join(self._comms_dir, '%s.%d.%s') %
                    ('sms', 12, 'pe')]
        msg = 'Comms directory file list error'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Cleanup.
        remove_files(received)
开发者ID:loum,项目名称:top,代码行数:27,代码来源:test_ondelivery.py


示例5: test_copy_file

    def test_copy_file(self):
        """Copy file -- unconditional.
        """
        dir = tempfile.mkdtemp()
        source_file = tempfile.NamedTemporaryFile()
        source_file_name = source_file.name

        old_base_dir = self._i.base_dir
        self._i.set_base_dir(dir)

        received = self._i.copy_file(source_file_name,
                                     dir,
                                     conditional=False)
        msg = 'Unconditional file copy should return True'
        self.assertTrue(received, msg)

        # Now copy the same unconditionally.
        received = self._i.copy_file(source_file_name,
                                     dir,
                                     conditional=False)
        msg = 'Unconditional secondary file copy should return True'
        self.assertTrue(received, msg)

        # ... and copy the same conditionally.
        received = self._i.copy_file(source_file_name,
                                     dir,
                                     conditional=True)
        msg = 'Conditional secondary file copy should return False'
        self.assertFalse(received, msg)

        # Clean up.
        remove_files([os.path.join(dir, x) for x in os.listdir(dir)])
        self._i.set_base_dir(old_base_dir)
        os.removedirs(dir)
开发者ID:loum,项目名称:top,代码行数:34,代码来源:test_init.py


示例6: 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


示例7: test_process

    def test_process(self):
        """Verify a processing loop.
        """
        # Place a copy of the test files in temp directory.
        dir = tempfile.mkdtemp()
        test_file = os.path.join('top',
                                 'tests',
                                 'files',
                                 'NSW_VANA_REF_20131121065550.txt')
        proc_file = os.path.join(dir, os.path.basename(test_file))
        copy_file(test_file, proc_file)
        sig_files = ['P3014R0-00007342.ps', 'P3014R0-00007343.ps']
        for f in sig_files:
            fh = open(os.path.join(dir, f), 'w')
            fh.close()

        # Original signature files should not exist.
        received = self._pt.process(file=proc_file, column='JOB_KEY')
        msg = 'POD translation processing loop error'
        for f in sig_files:
            self.assertFalse(os.path.exists(os.path.join(dir, f)))

        # Check that the translated file was produced.
        received = os.path.exists('%s.xlated' % proc_file)
        msg = 'Translated file error'
        self.assertTrue(received, msg)

        remove_files(get_directory_files_list(dir))
        os.removedirs(dir)
开发者ID:loum,项目名称:top,代码行数:29,代码来源:test_podtranslator.py


示例8: stop

    def stop(self):
        """Stop the daemon.

        Will run a series of checks around the existence of a PID file
        before attempting to terminate the daemon.

        **Returns:**
            boolean::

                ``True`` -- success
                ``False`` -- failure

        """
        stop_status = False

        if self.pid:
            # OK to terminate.
            log.debug('stopping daemon process with PID: %s' % self.pid)

            try:
                os.kill(int(self.pid), signal.SIGTERM)
            except OSError, err:
                log.warn('err: %s' % str(err))
                log.warn('PID "%s" does not exist' % self.pid)
                if err.errno == 3:
                    # For a daemon process, remove the PID file.
                    if self.pidfile is not None:
                        log.warn('Removing PID file "%s"' % self.pidfile)
                        remove_files(self.pidfile)
            else:
                stop_status = True
                self.pid = None
开发者ID:loum,项目名称:top,代码行数:32,代码来源:daemon.py


示例9: 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


示例10: test_get_files

    def test_get_files(self):
        """Get inbound report files list.
        """
        test_file_dir = os.path.join('top', 'tests', 'files')
        dir_1 = tempfile.mkdtemp()
        dir_2 = tempfile.mkdtemp()
        files = ['VIC_VANA_REI_20131108145146.txt',
                 'VIC_VANA_REP_20131108145146.txt']
        copy_file(os.path.join(test_file_dir, files[0]),
                  os.path.join(dir_1, files[0]))
        copy_file(os.path.join(test_file_dir, files[1]),
                  os.path.join(dir_2, files[1]))
        dirs = [dir_1, dir_2]
        filters = ['.*_REP_\d{14}\.txt$', '.*_REI_\d{14}\.txt$']

        received = self._e.get_files(dirs, filters)
        expected = [os.path.join(dir_1, files[0]),
                    os.path.join(dir_2, files[1])]
        msg = 'Exporter report files list error'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Clean up.
        for d in dirs:
            remove_files(get_directory_files_list(d))
            os.removedirs(d)
开发者ID:loum,项目名称:top,代码行数:25,代码来源:test_exporter.py


示例11: test_flag_comms_previous_no_comms_files

    def test_flag_comms_previous_no_comms_files(self):
        """Check if comms flag has been set previously.
        """
        comms_flags = [os.path.join(self._comms_dir, 'sms.1.body'),
                       os.path.join(self._comms_dir, 'email.2.body.err')]
        for f in comms_flags:
            fh = open(f, 'w')
            fh.close()

        action = 'email'
        id = 1
        service = 'body'
        received = self._s.flag_comms_previous(action, id, service)
        msg = 'Previous comms flag should not exist and return False'
        self.assertFalse(received, msg)

        action = 'sms'
        id = 1
        service = 'body'
        received = self._s.flag_comms_previous(action, id, service)
        msg = 'Previous comms flag exists and return True'
        self.assertTrue(received, msg)

        action = 'email'
        id = 2
        service = 'body'
        received = self._s.flag_comms_previous(action, id, service)
        msg = 'Previous comms err flag should exist and return True'
        self.assertTrue(received, msg)

        # Clean up.
        remove_files(comms_flags)
开发者ID:loum,项目名称:top,代码行数:32,代码来源:test_service.py


示例12: test_xlsx_to_csv_converter

    def test_xlsx_to_csv_converter(self):
        """Convert a xlsx file to csv.
        """
        test_dir = os.path.join('top', 'tests', 'files')
        xlsx_file = os.path.join(test_dir, 'ADP-Bulk-Load.xlsx')
        dir = tempfile.mkdtemp()
        file_to_convert = os.path.join(dir, os.path.basename(xlsx_file))
        copy_file(xlsx_file, file_to_convert)

        csv_file = xlsx_to_csv_converter(file_to_convert)

        # Check that the csv file exists.
        msg = 'CSV file does not exist'
        received = os.path.exists(csv_file)
        self.assertTrue(received, msg)

        # Check contents.
        fh = open(csv_file)
        received = fh.readline().strip()
        fh.close()

        fh = open(os.path.join(test_dir, 'ADP-Bulk-Load.csv'))
        expected = fh.readline().strip()
        fh.close()

        msg = 'CSV file contents error'
        self.assertEqual(received, expected, msg)

        # Clean up.
        remove_files(get_directory_files_list(dir))
        os.removedirs(dir)
开发者ID:loum,项目名称:top,代码行数:31,代码来源:test_files.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_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


示例15: 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


示例16: 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


示例17: 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


示例18: test_process

    def test_process(self):
        """Check processing.
        """
        dry = False

        service_code = 3
        bu_ids = (1, 2, 3)
        in_files = [self._test_file]
        kwargs = {'template': 'pe',
                  'service_code': service_code,
                  'bu_ids': bu_ids,
                  'in_files': in_files,
                  'delivery_partners': ('Nparcel', ),
                  'dry': dry}
        received = self._on.process(**kwargs)
        expected = [10, 12]
        msg = 'List of processed primary elect items incorrect'
        self.assertListEqual(received, expected, msg)

        # Check that the comms files were written out.
        received = [os.path.join(self._comms_dir,
                                 x) for x in os.listdir(self._comms_dir)]
        expected = [os.path.join(self._comms_dir, '%s.%d.%s') %
                    ('email', 10, 'pe'),
                    os.path.join(self._comms_dir, '%s.%d.%s') %
                    ('sms', 10, 'pe'),
                    os.path.join(self._comms_dir, '%s.%d.%s') %
                    ('email', 12, 'pe'),
                    os.path.join(self._comms_dir, '%s.%d.%s') %
                    ('sms', 12, 'pe')]
        msg = 'Comms directory file list error'
        self.assertListEqual(sorted(received), sorted(expected), msg)

        # Cleanup.
        remove_files(received)
开发者ID:loum,项目名称:top,代码行数:35,代码来源:test_ondelivery.py


示例19: test_write

    def test_write(self):
        """Test outbound file write-out.
        """
        data = '%s\n' % 'xxx'

        fhs = {}
        kwargs = {'data': data,
                  'fhs': fhs,
                  'delivery_partner': 'parcelpoint',
                  'infile': self._file,
                  'dry': False}
        self._fd.write(**kwargs)
        files_closed = self._fd.close(fhs)

        outfile = files_closed[0]
        fh = open(outfile)
        received = fh.read().rstrip()
        fh.close()
        expected = data + '%%EOF'
        msg = 'Written content error'
        self.assertEqual(received, expected, msg)

        # Clean up.
        remove_files(outfile)
        os.removedirs(os.path.join(self._out_dir, 'parcelpoint', 'out'))
开发者ID:loum,项目名称:top,代码行数:25,代码来源:test_filterdaemon.py


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python log.debug函数代码示例发布时间:2022-05-27
下一篇:
Python files.get_directory_files_list函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap