# Path: app/core/management/commands/_private.py
# class CommandHelper:
#     def __init__(self, command):
#         self.base_dir = settings.BASE_DIR
#         self.command = command
#         self.string_queue = []
# 
#     def add_to_print_queue(self, s):
#         self.string_queue.append(s)
# 
#     def print_queue(self):
#         self.command.stdout.write('')
#         self.command.stdout.write('>>> DJANGO-SKELETON:')
#         for item in self.string_queue:
#             self.command.stdout.write(str(item))
#         self.command.stdout.write('')
# 
#     def load_fixtures(self):
#         management.call_command('loaddata', 'debug_core.json')
#         management.call_command('loaddata', 'debug_account.json')
#         management.call_command('loaddata', 'debug_blog.json')


import shutil
import os
from django.core import management
from django.core.management.base import NoArgsCommand
from django.conf import settings
from ._private import CommandHelper
        self.base_dir = settings.BASE_DIR
        self.helper = CommandHelper(self)

    def handle_noargs(self, **options):
        # DEBUG: Remove current database file
        if settings.DEBUG:
            try:
                self.helper.add_to_print_queue('Trying to remove database file...')
                os.remove(settings.DATABASES['default']['NAME'])
                self.helper.add_to_print_queue('Database removed')
            except Exception as e:
                self.helper.add_to_print_queue('Error on removing database file')
                self.helper.add_to_print_queue('ERROR: ' + e.message)

        # DEBUG: Remove static, media and log files
        if settings.DEBUG:
            try:
                self.helper.add_to_print_queue('Trying to remove static, media and log files...')
                shutil.rmtree(os.path.join(self.base_dir, 'files', 'public', 'media'))
                os.remove(os.path.join(self.base_dir, 'files', 'logs', 'django.log'))
                os.remove(os.path.join(self.base_dir, 'files', 'logs', 'application.log'))
                os.remove(os.path.join(self.base_dir, 'files', 'logs', 'logic.log'))
                shutil.rmtree(os.path.join(self.base_dir, 'files', 'public', 'static'))
            except Exception as e:
                self.helper.add_to_print_queue('Error on removing static, media and log files')
                self.helper.add_to_print_queue('ERROR: ' + str(e))

        # DEBUG: Migrate, Superuser and Fixtures
        if settings.DEBUG:
            try:

# Path: app/core/management/commands/_private.py
# class CommandHelper:
#     def __init__(self, command):
#         self.base_dir = settings.BASE_DIR
#         self.command = command
#         self.string_queue = []
# 
#     def add_to_print_queue(self, s):
#         self.string_queue.append(s)
# 
#     def print_queue(self):
#         self.command.stdout.write('')
#         self.command.stdout.write('>>> DJANGO-SKELETON:')
#         for item in self.string_queue:
#             self.command.stdout.write(str(item))
#         self.command.stdout.write('')
# 
#     def load_fixtures(self):
#         management.call_command('loaddata', 'debug_core.json')
#         management.call_command('loaddata', 'debug_account.json')
#         management.call_command('loaddata', 'debug_blog.json')


# Path: app/core/management/commands/init.py
import shutil
import os
from django.core import management
from django.core.management.base import NoArgsCommand
from django.conf import settings
from ._private import CommandHelper

        self.base_dir = settings.BASE_DIR
        self.helper = CommandHelper(self)

    def handle_noargs(self, **options):
        # DEBUG: Remove current database file
        if settings.DEBUG:
            try:
                self.helper.add_to_print_queue('Trying to remove database file...')
                os.remove(settings.DATABASES['default']['NAME'])
                self.helper.add_to_print_queue('Database removed')
            except Exception as e:
                self.helper.add_to_print_queue('Error on removing database file')
                self.helper.add_to_print_queue('ERROR: ' + e.message)

        # DEBUG: Remove static, media and log files
        if settings.DEBUG:
            try:
                self.helper.add_to_print_queue('Trying to remove static, media and log files...')
                shutil.rmtree(os.path.join(self.base_dir, 'files', 'public', 'media'))
                os.remove(os.path.join(self.base_dir, 'files', 'logs', 'django.log'))
                os.remove(os.path.join(self.base_dir, 'files', 'logs', 'application.log'))
                os.remove(os.path.join(self.base_dir, 'files', 'logs', 'logic.log'))
                shutil.rmtree(os.path.join(self.base_dir, 'files', 'public', 'static'))
            except Exception as e:
                self.helper.add_to_print_queue('Error on removing static, media and log files')
                self.helper.add_to_print_queue('ERROR: ' + str(e))

        # DEBUG: Migrate, Superuser and Fixtures
        if settings.DEBUG:
            try:

                self.helper.add_to_print_queue('Trying to migrate, create superuser and load development fixtures...')