-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental command to output "fixture" containing cms content
- Loading branch information
EsGeh
authored and
EsGeh
committed
Nov 28, 2019
1 parent
fb05644
commit be67fa7
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
__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") | ||
output_file = (Path(environ['RES_DIR']) / "fixtures" / timestr) . with_suffix( ".json" ) | ||
|
||
output_file.parent.mkdir( | ||
parents = True, | ||
exist_ok = True | ||
) | ||
|
||
call_command( | ||
"dumpdata", "cms", | ||
"djangocms_text_ckeditor", | ||
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 |