wxPython/wxGlade-0.9.1/codegen/__init__.py
def save_file(self, filename, content, mainfile=False, content_only=False):
        """Store the content in a file.

        A shebang is added in top of all mainfiles. The permissions of mainfiles will be set to 0755 too.
        common.save_file() is used for storing content, i.e. the file will only be written in case of changes.

        filename:     File name
        content:      File content as list of strings
        mainfile:     Mainfiles gets a shebang and 0755 permissions.
        content_only: Write only content to the file"""

        tmp = []

        # write additional information to file header
        if not content_only:
            # add shebang to main file
            if self.shebang and mainfile or self.language == 'C++':
                tmp.append( self.shebang )

            # add file encoding notice
            if self.tmpl_encoding and self.app_encoding:
                tmp.append( self.tmpl_encoding % self.app_encoding )

            # add created by notice
            if self.tmpl_generated_by:
                tmp.append( self.tmpl_generated_by % {'comment_sign': self.comment_sign,
                                                      'generated_by': self.create_generated_by() } )

            # add language specific note
            if self.language_note:
                tmp.append( "%s" % self.language_note )

            # add a empty line
            tmp.append( "\n" )

        # add original file content
        tmp += content

        # encode unicode to binary; filter out empty line
        def encode(line):
            if isinstance(line, compat.unicode):
                return line.encode(self.app_encoding)
            return line
        try:
            tmp = [encode(line) for line in tmp if line]
        except UnicodeEncodeError as inst:
            raise errors.WxgOutputUnicodeError( self.app_encoding,
                                                inst.object[inst.start:inst.end].encode('unicode-escape'),
                                                inst.start, inst.end )

        # check for necessary sub directories e.g. for Perl or Python modules
        dirname = os.path.dirname(filename)
        if dirname and not os.path.isdir(dirname):
            try:
                os.makedirs(dirname)
            except:
                self._logger.exception( _('Can not create output directory "%s"'), dirname )

        # save the file now
        try:
            common.save_file(filename, tmp, 'codegen')
        except (errors.WxgBaseException, EnvironmentError):
            # EnvironmentError's will be caught at a higher level
            raise
        except:
            self._logger.exception(_('Internal Error'))
        if mainfile and sys.platform in ['linux2', 'darwin']:
            try:
                # make the file executable
                os.chmod(filename, 0o755)
            except OSError as e:
                # this isn't necessarily a bad error
                self.warning(_('Changing permission of file "%s" failed: %s') % (filename, str(e)))
Store the content in a file.

        A shebang is added in top of all mainfiles. The permissions of mainfiles will be set to 0755 too.
        common.save_file() is used for storing content, i.e. the file will only be written in case of changes.

        filename:     File name
        content:      File content as list of strings
        mainfile:     Mainfiles gets a shebang and 0755 permissions.
        content_only: Write only content to the file
Store the content in a file.
A shebang is added in top of all mainfiles. The permissions of mainfiles will be set to 0755 too.

File name
content:      File content as list of strings
mainfile:     Mainfiles gets a shebang and 0755 permissions.
content_only: Write only content to the file
Store the content in a file . A shebang is added in top of all mainfiles . The permissions of mainfiles will be set to 0755 too . File name content : File content as list of strings mainfile : Mainfiles gets a shebang and 0755 permissions . content_only : Write only content to the file
def save_file(self, filename, content, mainfile=False, content_only=False):
        tmp = []
        if not content_only:
            if self.shebang and mainfile or self.language == 'C++':
                tmp.append( self.shebang )
            if self.tmpl_encoding and self.app_encoding:
                tmp.append( self.tmpl_encoding % self.app_encoding )
            if self.tmpl_generated_by:
                tmp.append( self.tmpl_generated_by % {'comment_sign': self.comment_sign,
                                                      'generated_by': self.create_generated_by() } )
            if self.language_note:
                tmp.append( "%s" % self.language_note )
            tmp.append( "\n" )
        tmp += content
        def encode(line):
            if isinstance(line, compat.unicode):
                return line.encode(self.app_encoding)
            return line
        try:
            tmp = [encode(line) for line in tmp if line]
        except UnicodeEncodeError as inst:
            raise errors.WxgOutputUnicodeError( self.app_encoding,
                                                inst.object[inst.start:inst.end].encode('unicode-escape'),
                                                inst.start, inst.end )
        dirname = os.path.dirname(filename)
        if dirname and not os.path.isdir(dirname):
            try:
                os.makedirs(dirname)
            except:
                self._logger.exception( _('Can not create output directory "%s"'), dirname )
        try:
            common.save_file(filename, tmp, 'codegen')
        except (errors.WxgBaseException, EnvironmentError):
            raise
        except:
            self._logger.exception(_('Internal Error'))
        if mainfile and sys.platform in ['linux2', 'darwin']:
            try:
                os.chmod(filename, 0o755)
            except OSError as e:
                self.warning(_('Changing permission of file "%s" failed: %s') % (filename, str(e)))
def save_file ( self , filename , content , mainfile = False , content_only = False ) : tmp = [ ] if not content_only : if self . shebang and mainfile or self . language == 'C++' : tmp . append ( self . shebang ) if self . tmpl_encoding and self . app_encoding : tmp . append ( self . tmpl_encoding % self . app_encoding ) if self . tmpl_generated_by : tmp . append ( self . tmpl_generated_by % { 'comment_sign' : self . comment_sign , 'generated_by' : self . create_generated_by ( ) } ) if self . language_note : tmp . append ( "%s" % self . language_note ) tmp . append ( "\n" ) tmp += content def encode ( line ) : if isinstance ( line , compat . unicode ) : return line . encode ( self . app_encoding ) return line try : tmp = [ encode ( line ) for line in tmp if line ] except UnicodeEncodeError as inst : raise errors . WxgOutputUnicodeError ( self . app_encoding , inst . object [ inst . start : inst . end ] . encode ( 'unicode-escape' ) , inst . start , inst . end ) dirname = os . path . dirname ( filename ) if dirname and not os . path . isdir ( dirname ) : try : os . makedirs ( dirname ) except : self . _logger . exception ( _ ( 'Can not create output directory "%s"' ) , dirname ) try : common . save_file ( filename , tmp , 'codegen' ) except ( errors . WxgBaseException , EnvironmentError ) : raise except : self . _logger . exception ( _ ( 'Internal Error' ) ) if mainfile and sys . platform in [ 'linux2' , 'darwin' ] : try : os . chmod ( filename , 0o755 ) except OSError as e : self . warning ( _ ( 'Changing permission of file "%s" failed: %s' ) % ( filename , str ( e ) ) )
Store the content in a file.
Store the content in a file .
"""Store the content in a file.

        A shebang is added in top of all mainfiles. The permissions of mainfiles will be set to 0755 too.
        common.save_file() is used for storing content, i.e. the file will only be written in case of changes.

        filename:     File name
        content:      File content as list of strings
        mainfile:     Mainfiles gets a shebang and 0755 permissions.
        content_only: Write only content to the file""" # write additional information to file header # add shebang to main file # add file encoding notice # add created by notice # add language specific note # add a empty line # add original file content # encode unicode to binary; filter out empty line # check for necessary sub directories e.g. for Perl or Python modules # save the file now # EnvironmentError's will be caught at a higher level # make the file executable # this isn't necessarily a bad error
self
filename
content
mainfile
content_only