Commit 0c3c21f3 authored by Tristan Gingold's avatar Tristan Gingold

makefile.py: simplify code.

parent d08cfef6
...@@ -150,23 +150,16 @@ class ToolMakefile(object): ...@@ -150,23 +150,16 @@ class ToolMakefile(object):
self.writeln(tmp) self.writeln(tmp)
def initialize(self): def initialize(self):
"""Open the Makefile file and print a header if not initialized""" """Open the Makefile file and print a header"""
if not self._initialized: if os.path.exists(self._filename):
if os.path.exists(self._filename): os.remove(self._filename)
if os.path.isfile(self._filename):
os.remove(self._filename)
elif os.path.isdir(self._filename):
os.rmdir(self._filename)
self._file = open(self._filename, "a+") self._file = open(self._filename, "w")
self._initialized = True self.writeln("########################################")
self.writeln("########################################") self.writeln("# This file was generated by hdlmake #")
self.writeln("# This file was generated by hdlmake #") self.writeln("# http://ohwr.org/projects/hdl-make/ #")
self.writeln("# http://ohwr.org/projects/hdl-make/ #") self.writeln("########################################")
self.writeln("########################################") self.writeln()
self.writeln()
elif not self._file:
self._file = open(self._filename, "a+")
def makefile_close(self): def makefile_close(self):
self._file.close() self._file.close()
...@@ -175,6 +168,7 @@ class ToolMakefile(object): ...@@ -175,6 +168,7 @@ class ToolMakefile(object):
def write(self, line=None): def write(self, line=None):
"""Write a string in the manifest, no new line""" """Write a string in the manifest, no new line"""
if not self._initialized: if not self._initialized:
self._initialized = True
self.initialize() self.initialize()
if shell.check_windows(): if shell.check_windows():
self._file.write(line.replace('\\"', '"')) self._file.write(line.replace('\\"', '"'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment