Mercurial > libervia-backend
changeset 271:0288f97334f2
bridge: constructor now generate files in a 'generated' subdirectory
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 24 Jan 2011 21:48:09 +0100 |
parents | 4005bf3ce35d |
children | 1d2e0dfe7114 |
files | src/bridge/bridge_constructor/bridge_contructor.py |
diffstat | 1 files changed, 29 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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):