Exemplo n.º 1
0
    def create_project(self, project_dir):
        os.makedirs(project_dir)

        # Find the current Django versions in the buildout versions.
        # Assume the newest Django when no version is found.
        version = None
        b_versions = self.buildout.get('versions')
        if b_versions:
            django_version = (
                b_versions.get('django') or
                b_versions.get('Django')
            )
            if django_version:
                version_re = re.compile("\d+\.\d+")
                match = version_re.match(django_version)
                version = match and match.group()

        config = versions.get(version, versions['Newest'])

        template_vars = {'secret': self.generate_secret()}
        template_vars.update(self.options)

        self.create_file(
            os.path.join(project_dir, 'development.py'),
            config['development_settings'], template_vars)

        self.create_file(
            os.path.join(project_dir, 'production.py'),
            config['production_settings'], template_vars)

        self.create_file(
            os.path.join(project_dir, 'urls.py'),
            config['urls'], template_vars)

        self.create_file(
            os.path.join(project_dir, 'settings.py'),
            config['settings'], template_vars)

        # Create the media and templates directories for our
        # project
        os.mkdir(os.path.join(project_dir, 'media'))
        os.mkdir(os.path.join(project_dir, 'templates'))

        # Make the settings dir a Python package so that Django
        # can load the settings from it. It will act like the
        # project dir.
        open(os.path.join(project_dir, '__init__.py'), 'w').close()
Exemplo n.º 2
0
    def create_project(self, project_dir):
        os.makedirs(project_dir)

        # Find the current Django versions in the buildout versions.
        # Assume the newest Django when no version is found.
        version = None
        b_versions = self.buildout.get("versions")
        if b_versions:
            django_version = b_versions.get("django") or b_versions.get("Django")
            if django_version:
                version_re = re.compile("\d+\.\d+")
                match = version_re.match(django_version)
                version = match and match.group()

        config = versions.get(version, versions["Newest"])

        template_vars = {"secret": self.generate_secret()}
        template_vars.update(self.options)

        self.create_file(os.path.join(project_dir, "development.py"), config["development_settings"], template_vars)

        self.create_file(os.path.join(project_dir, "production.py"), config["production_settings"], template_vars)

        self.create_file(os.path.join(project_dir, "urls.py"), config["urls"], template_vars)

        self.create_file(os.path.join(project_dir, "settings.py"), config["settings"], template_vars)

        # Create the media and templates directories for our
        # project
        os.mkdir(os.path.join(project_dir, "media"))
        os.mkdir(os.path.join(project_dir, "templates"))

        # Make the settings dir a Python package so that Django
        # can load the settings from it. It will act like the
        # project dir.
        open(os.path.join(project_dir, "__init__.py"), "w").close()