def generate(self, outdir):
        if os.path.exists(outdir):
            if os.path.isdir(outdir):
                # Delete the contents outdir, not outdir itself
                for entry in os.listdir(outdir):
                    path = os.path.join(outdir, entry)
                    if os.path.isdir(path):
                        shutil.rmtree(path)
                    else:
                        os.remove(path)
            else:
                raise ValueError('%r is not a directory' % outdir)

        try:
            os.mkdir(outdir)
        except OSError as err:
            if err.errno != errno.EEXIST:
                raise

        for filespec in self.files:
            path = os.path.join(outdir, filespec.realpath(self.index_file))

            if not os.path.exists(os.path.dirname(path)):
                os.makedirs(os.path.dirname(path))

            with open(path, 'wb') as fobj:
                data = self.view(filespec, mode='generating')
                fobj.write(data)
dataset/ETHPy150Open akheron/stango/stango/__init__.py/Stango.generate/original