Skip to content

Commit

Permalink
Add clean and messages management script and update build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 14, 2024
1 parent 85ebe0d commit cba45de
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rdmo/core/management/commands/build.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import subprocess
import sys

from django.core.management import call_command
from django.core.management.base import BaseCommand


class Command(BaseCommand):

def handle(self, *args, **options):
call_command('npm', 'ci')
call_command('npm', 'run', 'build:prod')
subprocess.call(['/bin/bash', '-c', f'{sys.executable} -m build'])
53 changes: 53 additions & 0 deletions rdmo/core/management/commands/clean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
import shutil

from django.conf import settings
from django.core.management.base import BaseCommand


class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument('command', choices=[
'all',
'dist',
'media',
'npm',
'python',
'static',
])

def handle(self, *args, **options):
if options['command'] in ['all', 'dist']:
self.clean_dir('dist')
self.clean_dir('rdmo.egg-info')
if options['command'] in ['all', 'media']:
self.clean_dir(settings.MEDIA_ROOT)
if options['command'] in ['all', 'npm']:
self.clean_dir('node_modules')
if options['command'] in ['all', 'static']:
self.clean_static()
if options['command'] in ['all', 'python']:
self.clean_python()

def clean_python(self):
for root, dirs, files in os.walk('.'):
for dir_name in dirs:
if dir_name == '__pycache__':
self.clean_dir(os.path.join(root, dir_name), quiet=True)

def clean_static(self):
self.clean_dir(settings.STATIC_ROOT)

for path in [
# 'rdmo/core/static', # TODO: enable after cleanup
'rdmo/management/static',
# 'rdmo/projects/static' # TODO: enable after cleanup
]:
self.clean_dir(path)

def clean_dir(self, path, quiet=False):
if path and os.path.exists(path):
shutil.rmtree(path)
if not quiet:
print(f'Directory "{path}" has been removed!')
17 changes: 17 additions & 0 deletions rdmo/core/management/commands/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import subprocess

from django.core.management.base import BaseCommand


class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument('command', choices=['make', 'compile'])

def handle(self, *args, **options):
if options['command'] == 'make':
subprocess.check_call(['django-admin', 'makemessages', '--all'], cwd='rdmo')
subprocess.check_call(['django-admin', 'makemessages', '--all', '-d', 'djangojs'], cwd='rdmo')

elif options['command'] == 'compile':
subprocess.check_call(['django-admin', 'compilemessages'], cwd='rdmo')
2 changes: 2 additions & 0 deletions rdmo/core/management/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
ROOT_URLCONF = ''

DATABASES = {}

STATIC_ROOT = 'static_root'

0 comments on commit cba45de

Please sign in to comment.