Refactor: split code into several django apps (we call them modules).
This commit is contained in:
37
dav_base/management/commands/enable_module.py
Normal file
37
dav_base/management/commands/enable_module.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import os
|
||||
import pkg_resources
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from dav_base.config.modules import DJANGO_MAIN_MODULE, ModuleMeta
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Enable a modular app in django-dav installation.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('module', help='the name of the module')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
django_base_dir = settings.BASE_DIR
|
||||
django_main_module = DJANGO_MAIN_MODULE
|
||||
module_name = options['module']
|
||||
|
||||
config = settings.MODULE_CONFIG
|
||||
|
||||
if module_name in config.modules.keys():
|
||||
raise CommandError('Module \'{}\' is already enabled'.format(module_name))
|
||||
|
||||
settings_file_name = 'settings-{}.py'.format(module_name)
|
||||
input_file = os.path.join('django_project_config', settings_file_name)
|
||||
if pkg_resources.resource_exists(module_name, input_file):
|
||||
output_file = os.path.join(django_base_dir, django_main_module, settings_file_name)
|
||||
if not os.path.exists(output_file):
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(pkg_resources.resource_string(module_name, input_file))
|
||||
|
||||
module_meta_obj = ModuleMeta(module_name)
|
||||
config.modules[module_name] = module_meta_obj
|
||||
config.save()
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Module \'{}\' enabled.'.format(module_name)))
|
||||
Reference in New Issue
Block a user