Skip to content
Permalink
1dee481352
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
75 lines (62 sloc) 2.16 KB
__author__ = 'esgeh'
from django.core.management.base import BaseCommand
from django.core.management import call_command
from django.conf import settings
import logging
from os import environ
from pathlib import Path
import time
class Command(BaseCommand):
help = """dump cms"""
def add_arguments(self, parser):
pass
def handle(self, *args, **options):
logger = self.init_logging(verbosity = options['verbosity'])
timestr = time.strftime("%Y%m%d-%H%M%S")
try:
output_file = (Path(environ['RES_DIR']) / "fixtures" / timestr) . with_suffix( ".json" )
output_file.parent.mkdir(
parents = True,
exist_ok = True
)
except KeyError:
output_file = f"cmsdump{timestr}.json"
call_command(
"dumpdata",
"cms",
"djangocms_text_ckeditor",
"auth.user",
exclude = [
"contenttypes",
"auth.Permission",
],
natural_foreign = True,
natural_primary = True,
output = output_file
)
logger.info( "done" )
def init_logging( self, verbosity):
FORMAT = '%(asctime)s [%(levelname)s] %(name)s %(funcName)s:%(lineno)d: %(message)s'
logging.basicConfig(format=FORMAT)
self.logger = logging.getLogger( __name__ )
logger = self.logger
# detect django logging level:
'''
0 means no output.
1 means normal output (default). WARNING
2 means verbose output. INFO
3 means very verbose output. DEBUG
'''
# create loggers:
if verbosity == None:
logger.setLevel( logging.WARNING )
elif verbosity == 0:
logger.setLevel( logging.ERROR )
elif verbosity == 1:
logger.setLevel( logging.WARNING )
elif verbosity == 2:
logger.setLevel( logging.INFO )
else: # (verbosity >= 3:)
logger.setLevel( logging.DEBUG )
print( "logging level: {}".format( logger.getEffectiveLevel() ) )
return logger