:param filename:
            File to write into
        :param append:
            Either append to existing content (if not already included)
            or completely replace `filename`
        :param backup:
            Create a backup of `filename` before writing.
            Only applies when `append` is set

def write(self, filename, append=True, backup=True):
        '''
        :param filename:
            File to write into
        :param append:
            Either append to existing content (if not already included)
            or completely replace `filename`
        :param backup:
            Create a backup of `filename` before writing.
            Only applies when `append` is set
        '''

        res = self.sub
        if append:
            org = read_file(filename)
            if org:
                if res in org:
                    res = org
                else:
                    if backup:
                        backup_location(filename)
                    res = org + res

        write_file(filename, res)
        return self.m(
            'template %s' % ('appended' if append else 'written'),
            more=dict(fields=self.__fields, file=filename)
        )