# HG changeset patch # User Goffi # Date 1295902089 -3600 # Node ID 0288f97334f29b77f862f3217dac80f0548bfdc5 # Parent 4005bf3ce35df06ad43be82e8ff468407b45bb6e bridge: constructor now generate files in a 'generated' subdirectory diff -r 4005bf3ce35d -r 0288f97334f2 src/bridge/bridge_constructor/bridge_contructor.py --- a/src/bridge/bridge_constructor/bridge_contructor.py Mon Jan 24 21:47:16 2011 +0100 +++ b/src/bridge/bridge_constructor/bridge_contructor.py Mon Jan 24 21:48:09 2011 +0100 @@ -23,6 +23,7 @@ #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 @@ """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 @@ 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 @@ 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):