Python django.conf.settings.PROJECT_ROOT Examples

The following are 4 code examples for showing how to use django.conf.settings.PROJECT_ROOT(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .

Example 1
Project: linkedevents   Author: City-of-Helsinki   File: event_import.py    License: MIT License 5 votes vote down vote up
def handle(self, *args, **options):
        module = options['module']
        if module not in self.importers:
            raise CommandError("Importer %s not found. Valid importers: %s" % (module, self.imp_list))
        imp_class = self.importers[module]

        if hasattr(settings, 'PROJECT_ROOT'):
            root_dir = settings.PROJECT_ROOT
        else:
            root_dir = settings.BASE_DIR
        importer = imp_class({'data_path': os.path.join(root_dir, 'data'),
                              'verbosity': int(options['verbosity']),
                              'cached': options['cached'],
                              'single': options['single'],
                              'remap': options['remap'],
                              'force': options['force']})

        # Activate the default language for the duration of the import
        # to make sure translated fields are populated correctly.
        old_lang = get_language()
        activate(settings.LANGUAGES[0][0])

        for imp_type in self.importer_types:
            name = "import_%s" % imp_type
            method = getattr(importer, name, None)
            if options[imp_type]:
                if not method:
                    raise CommandError("Importer {} does not support importing {}".format(importer.name, imp_type))
                if imp_type == 'courses' and 'extension_course' not in settings.INSTALLED_APPS:
                    raise CommandError("Course extension must be installed when importing courses.")
            else:
                if not options['all']:
                    continue

            if method:
                method()

        activate(old_lang) 
Example 2
Project: wagtail-cookiecutter-foundation   Author: chrisdev   File: copy_media.py    License: MIT License 5 votes vote down vote up
def handle(self, **options):
        media_src_dir = os.path.join(settings.PROJECT_ROOT, 'pages', 'media')
        image_src_dir = os.path.join(media_src_dir, 'images')
        image_src_dir_or = os.path.join(media_src_dir, 'original_images')
        documents_src_dir = os.path.join(media_src_dir, 'documents')
        image_dest_dir_or = os.path.join(settings.MEDIA_ROOT,
                                         'original_images')
        image_dest_dir = os.path.join(settings.MEDIA_ROOT, 'images')
        documents_dest_dir = os.path.join(settings.MEDIA_ROOT, 'documents')

        if not os.path.isdir(image_dest_dir):
            os.makedirs(image_dest_dir)

        for filename in os.listdir(image_src_dir):
            shutil.copy(os.path.join(image_src_dir, filename), image_dest_dir)

        if not os.path.isdir(image_dest_dir_or):
            os.makedirs(image_dest_dir_or)

        for filename in os.listdir(image_src_dir_or):
            shutil.copy(
                os.path.join(image_src_dir_or, filename), image_dest_dir_or
            )

        if not os.path.isdir(documents_dest_dir):
            os.makedirs(documents_dest_dir)

        for filename in os.listdir(documents_src_dir):
            shutil.copy(
                os.path.join(documents_src_dir, filename), documents_dest_dir
            ) 
Example 3
Project: madewithwagtail   Author: springload   File: load_initial_data.py    License: MIT License 5 votes vote down vote up
def handle(self, *args, **options):
        fixtures_dir = os.path.join(settings.PROJECT_ROOT, settings.SITE_NAME, 'core', 'fixtures')
        fixture_file = os.path.join(fixtures_dir, 'initial_data.json')
        image_src_dir = os.path.join(fixtures_dir, 'images')
        image_dest_dir = os.path.join(settings.MEDIA_ROOT, 'original_images')

        call_command('loaddata', fixture_file, verbosity=3)

        if not os.path.isdir(image_dest_dir):
            os.makedirs(image_dest_dir)

        for filename in os.listdir(image_src_dir):
            shutil.copy(os.path.join(image_src_dir, filename), image_dest_dir) 
Example 4
Project: cartoview   Author: cartologic   File: installer.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def execute_command(self, command):
        project_dir = None
        if hasattr(settings, 'BASE_DIR'):
            project_dir = settings.BASE_DIR
        elif hasattr(settings, 'PROJECT_ROOT'):
            project_dir = settings.PROJECT_ROOT
        elif hasattr(settings, 'APP_ROOT'):
            project_dir = settings.APP_ROOT
        manage_py = os.path.join(project_dir, 'manage.py')
        process = subprocess.Popen(
            "{} {} {}".format(executable, manage_py, command), shell=True)
        out, err = process.communicate()
        logger.info(out)
        logger.error(err)