<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate(self):
 """Generate the page html file. Just open the destination file for writing and write the result of rendering this page. """

        generated_content = ''
        if 'published' in (self._config['status'][0]).lower():
            if os.path.isdir(self.dirs['www_dir']):
                shutil.rmtree(self.dirs['www_dir'])
            os.mkdir(self.dirs['www_dir'])
            # copy the whole source directory of the page,
            # excluding 'nowww' and *s2md
            sfl = glob.glob(os.path.join(self.dirs['source_dir'], "*"))
            dirlist = [f for f in sfl if os.path.isdir(f)]
            filelist = [f for f in sfl if os.path.isfile(f)]
            for f in filelist:
                if not '.md' in os.path.split(f)[1]:
                    shutil.copy(f, self.dirs['www_dir'])
            for d in dirlist:
                rfn = os.path.split(d)[1]
                if rfn != 'nowww':
                    shutil.copytree(d, os.path.join(self.dirs['www_dir'], rfn))
                #write the rendered "page" to file

            #fout = open(self.dirs['www_filename'], 'w')
            #fout.write(self.render())
            #fout.close()

            generated_content = self.render()
            fout = codecs.open(self.dirs['www_filename'], "w", encoding="utf-8", errors="xmlcharrefreplace")
            fout.write(generated_content)
            fout.close()

        return generated_content