[Windows] Fixed problems with os.rename
- Now using os.replace - It removes the target if already there
This commit is contained in:
parent
11773e920d
commit
ebabc0b37b
|
|
@ -291,9 +291,7 @@ class GS(object):
|
|||
@staticmethod
|
||||
def make_bkp(fname):
|
||||
bkp = fname+'-bak'
|
||||
if os.path.isfile(bkp):
|
||||
os.remove(bkp)
|
||||
os.rename(fname, bkp)
|
||||
os.replace(fname, bkp)
|
||||
|
||||
@staticmethod
|
||||
def zones():
|
||||
|
|
|
|||
|
|
@ -1797,9 +1797,7 @@ class Schematic(object):
|
|||
# Keep a back-up of existing files
|
||||
if os.path.isfile(fname):
|
||||
bkp = fname+'-bak'
|
||||
if os.path.isfile(bkp):
|
||||
os.remove(bkp)
|
||||
os.rename(fname, bkp)
|
||||
os.replace(fname, bkp)
|
||||
with open(fname, 'wt') as f:
|
||||
f.write('EESchema Schematic File Version {}\n'.format(self.version))
|
||||
f.write('EELAYER {} {}\n'.format(self.eelayer_n, self.eelayer_m))
|
||||
|
|
|
|||
|
|
@ -1751,9 +1751,7 @@ class SchematicV6(Schematic):
|
|||
# Keep a back-up of existing files
|
||||
if os.path.isfile(fname):
|
||||
bkp = fname+'-bak'
|
||||
if os.path.isfile(bkp):
|
||||
os.remove(bkp)
|
||||
os.rename(fname, bkp)
|
||||
os.replace(fname, bkp)
|
||||
with open(fname, 'wt') as f:
|
||||
f.write(dumps(sch))
|
||||
f.write('\n')
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ class AnyDrill(BaseOptions):
|
|||
for k_f, f in files.items():
|
||||
if f:
|
||||
logger.debug("Renaming {} -> {}".format(k_f, f))
|
||||
os.rename(k_f, f)
|
||||
os.replace(k_f, f)
|
||||
# Generate the report
|
||||
if self.report:
|
||||
drill_report_file = self.expand_filename(output_dir, self.report, 'drill_report', 'txt')
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class AnyLayerOptions(VariantOptions):
|
|||
plot_ctrl.PlotLayer()
|
||||
plot_ctrl.ClosePlot()
|
||||
if self.output and k_filename != filename:
|
||||
os.rename(k_filename, filename)
|
||||
os.replace(k_filename, filename)
|
||||
if create_job:
|
||||
jobfile_writer.AddGbrFile(id, os.path.basename(filename))
|
||||
generated[la.layer] = os.path.basename(filename)
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ class IBoMOptions(VariantOptions):
|
|||
logger.debug('Output from command:\n'+cmd_output_dec+'\n')
|
||||
if output:
|
||||
logger.debug('Renaming output file: {} -> {}'.format(cur, output))
|
||||
os.rename(cur, output)
|
||||
os.replace(cur, output)
|
||||
|
||||
|
||||
@output_class
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ class KiBoMOptions(BaseOptions):
|
|||
if m and m.group(1) != output:
|
||||
cur = m.group(1)
|
||||
logger.debug('Renaming output file: {} -> {}'.format(cur, output))
|
||||
os.rename(cur, output)
|
||||
os.replace(cur, output)
|
||||
logger.debug('Output from command:\n'+cmd_output.decode())
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ def test_pdf_refill_2(test_dir):
|
|||
assert os.path.isfile(bkp)
|
||||
finally:
|
||||
if os.path.isfile(bkp):
|
||||
os.rename(bkp, ori)
|
||||
os.replace(bkp, ori)
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ def test_update_xml_1(test_dir):
|
|||
ctx = context.TestContext(test_dir, prj, 'update_xml', '')
|
||||
# The XML should be created where the schematic is located
|
||||
xml = os.path.abspath(os.path.join(ctx.get_board_dir(), prj+'.xml'))
|
||||
os.rename(xml, xml+'-bak')
|
||||
os.replace(xml, xml+'-bak')
|
||||
try:
|
||||
ctx.run()
|
||||
# Check all outputs are there
|
||||
|
|
@ -171,7 +171,7 @@ def test_update_xml_1(test_dir):
|
|||
logging.debug(os.path.basename(xml)+' OK')
|
||||
finally:
|
||||
os.remove(xml)
|
||||
os.rename(xml+'-bak', xml)
|
||||
os.replace(xml+'-bak', xml)
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
|
|
@ -246,7 +246,7 @@ def test_sch_replace_1(test_dir):
|
|||
assert m.group(1) == text
|
||||
finally:
|
||||
for k, v in files.items():
|
||||
os.rename(v, k)
|
||||
os.replace(v, k)
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ def test_pcb_replace_1(test_dir):
|
|||
assert m is not None
|
||||
assert m.group(1) == text
|
||||
finally:
|
||||
os.rename(file_back, file)
|
||||
os.replace(file_back, file)
|
||||
ctx.clean_up(keep_project=True)
|
||||
|
||||
|
||||
|
|
@ -304,7 +304,7 @@ def test_set_text_variables_1(test_dir):
|
|||
assert 'Comment4' in data['text_variables']
|
||||
assert data['text_variables']['Comment4'] == text
|
||||
finally:
|
||||
os.rename(file_back, file)
|
||||
os.replace(file_back, file)
|
||||
ctx.expect_out_file(prj+'-bom_'+hash+'.csv')
|
||||
ctx.clean_up(keep_project=True)
|
||||
|
||||
|
|
@ -329,6 +329,6 @@ def test_set_text_variables_2(test_dir):
|
|||
assert 'text_variables' in data
|
||||
assert 'Comment4' not in data['text_variables']
|
||||
finally:
|
||||
os.rename(file_back, file)
|
||||
os.replace(file_back, file)
|
||||
ctx.expect_out_file(prj+'-bom_'+hash+'.csv')
|
||||
ctx.clean_up(keep_project=True)
|
||||
|
|
|
|||
Loading…
Reference in New Issue