From 69c0c458f07fca2453db4e4594469c54ab5177c6 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 24 Jan 2011 21:48:09 +0100 Subject: [PATCH] bridge: constructor now generate files in a 'generated' subdirectory --- .../bridge_constructor/bridge_contructor.py | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/bridge/bridge_constructor/bridge_contructor.py b/src/bridge/bridge_constructor/bridge_contructor.py index 5651e098..dbcd5c75 100755 --- a/src/bridge/bridge_constructor/bridge_contructor.py +++ b/src/bridge/bridge_constructor/bridge_contructor.py @@ -23,6 +23,7 @@ along with this program. If not, see . #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):