本文整理汇总了Python中top.utils.files.remove_files函数的典型用法代码示例。如果您正苦于以下问题:Python remove_files函数的具体用法?Python remove_files怎么用?Python remove_files使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove_files函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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()
示例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)
示例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)
示例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()
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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()
示例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()
示例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()