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