bridge: constructor now generate files in a 'generated' subdirectory

This commit is contained in:
Goffi 2011-01-24 21:48:09 +01:00
commit 69c0c458f0

View file

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#consts
NAME = u"bridge_constructor"
VERSION="0.1.0"
DEST_DIR="generated"
ABOUT = NAME+u""" v%s (c) Jérôme Poisson (aka Goffi) 2011
---
@ -157,6 +158,32 @@ class Constructor:
"""create the constructor in SàT core side (backend)"""
raise NotImplementedError
def generateFrontendSide(self):
"""create the constructor in SàT frontend side"""
raise NotImplementedError
def finalWrite(self, filename, file_buf):
"""Write the final generated file in DEST_DIR/filename
@param filename: name of the file to generate
@param file_buf: list of lines (stings) of the file"""
if os.path.exists(DEST_DIR) and not os.path.isdir(DEST_DIR):
print ("The destination dir [%s] can't be created: a file with this name already exists !")
sys.exit(1)
try:
if not os.path.exists(DEST_DIR):
os.mkdir(DEST_DIR)
full_path=os.path.join(DEST_DIR,filename)
if os.path.exists(full_path) and not self.options.force:
print ("The destination file [%s] already exists ! Use --force to overwrite it" % full_path)
try:
with open(full_path,'w') as dest_file:
dest_file.write('\n'.join(file_buf))
except IOError:
print ("Can't open destination file [%s]" % full_path)
except OSError:
print("It's not possible to generate the file, check your permissions")
exit(1)
class DbusConstructor(Constructor):
def __init__(self, bridge_template, options):
@ -226,13 +253,7 @@ class DbusConstructor(Constructor):
sys.exit(1)
#now we write to final file
if os.path.exists(self.core_dest) and not self.options.force:
print ("The destination file [%s] already exists ! Use --force to overwrite it" % self.core_dest)
try:
with open(self.core_dest,'w') as dest_file:
dest_file.write('\n'.join(core_bridge))
except IOError:
print ("Can't open destination file [%s]" % self.core_dest)
self.finalWrite(self.core_dest, core_bridge)
def generateFrontendSide(self):
methods_part = []
@ -274,13 +295,7 @@ class DbusConstructor(Constructor):
sys.exit(1)
#now we write to final file
if os.path.exists(self.frontend_dest) and not self.options.force:
print ("The destination file [%s] already exists ! Use --force to overwrite it" % self.frontend_dest)
try:
with open(self.frontend_dest,'w') as dest_file:
dest_file.write('\n'.join(frontend_bridge))
except IOError:
print ("Can't open destination file [%s]" % self.frontend_dest)
self.finalWrite(self.frontend_dest, frontend_bridge)
class ConstructorError(Exception):