ctl: turn collectstatic into a django command (#6735)

This commit is contained in:
Frédéric Péters 2017-08-12 11:33:04 +02:00
parent b595a2d22e
commit 92cc4014db
3 changed files with 21 additions and 25 deletions

View File

@ -10,7 +10,7 @@ from wcs.workflows import Workflow
from wcs.wf.jump import JumpWorkflowStatusItem from wcs.wf.jump import JumpWorkflowStatusItem
from wcs.fields import StringField, EmailField from wcs.fields import StringField, EmailField
import wcs.qommon.ctl import wcs.qommon.ctl
from wcs.ctl.collectstatic import CmdCollectStatic from wcs.qommon.management.commands.collectstatic import Command as CmdCollectStatic
from wcs.ctl.process_bounce import CmdProcessBounce from wcs.ctl.process_bounce import CmdProcessBounce
from wcs.ctl.wipe_data import CmdWipeData from wcs.ctl.wipe_data import CmdWipeData
from wcs.ctl.trigger_jumps import select_and_jump_formdata from wcs.ctl.trigger_jumps import select_and_jump_formdata

View File

@ -1,5 +1,5 @@
# w.c.s. - web application for online forms # w.c.s. - web application for online forms
# Copyright (C) 2005-2016 Entr'ouvert # Copyright (C) 2005-2017 Entr'ouvert
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -17,33 +17,31 @@
import os import os
import shutil import shutil
from qommon.ctl import Command, make_option from django.core.management.base import BaseCommand
from qommon.publisher import get_publisher_class
class Command(BaseCommand):
help = "Collect static files in a single location."
class CmdCollectStatic(Command): def add_arguments(self, parser):
name = 'collectstatic' parser.add_argument('-c', '--clear',
action='store_true', dest='clear', default=False,
help="Clear the existing files using the storage "
"before trying to copy or link the original file.")
parser.add_argument('-l', '--link',
action='store_true', dest='link', default=False,
help="Create a symbolic link to each file instead of copying.")
def __init__(self): def handle(self, **options):
Command.__init__(self, [ Publisher = get_publisher_class()
make_option('-c', '--clear', action='store_true', Publisher.ERROR_LOG = None
dest='clear', default=False), pub = Publisher.create_publisher()
make_option('-l', '--link', action='store_true',
dest='link', default=False),
])
def execute(self, base_options, sub_options, args):
import publisher
publisher.WcsPublisher.configure(self.config)
publisher.WcsPublisher.ERROR_LOG = None
pub = publisher.WcsPublisher.create_publisher(
register_cron=False, register_tld_names=False)
return self.collectstatic(pub, return self.collectstatic(pub,
clear=sub_options.clear, link=sub_options.link) clear=options['clear'], link=options['link'])
@classmethod @classmethod
def collectstatic(cls, pub, clear=False, link=False): def collectstatic(cls, pub, clear=False, link=False):
from wcs.root import StaticsDirectory root_directory_class = pub.root_directory_class.static
root_directory_class = StaticsDirectory
static_dir = os.path.join(pub.app_dir, 'collectstatic') static_dir = os.path.join(pub.app_dir, 'collectstatic')
if clear and os.path.exists(static_dir): if clear and os.path.exists(static_dir):
shutil.rmtree(static_dir) shutil.rmtree(static_dir)
@ -67,5 +65,3 @@ class CmdCollectStatic(Command):
os.symlink(os.path.join(basedir, filename), dst_filename) os.symlink(os.path.join(basedir, filename), dst_filename)
else: else:
shutil.copy(os.path.join(basedir, filename), dst_filename) shutil.copy(os.path.join(basedir, filename), dst_filename)
CmdCollectStatic.register()

View File

@ -131,10 +131,10 @@ INSTALLED_APPS = (
#'django.contrib.sessions', #'django.contrib.sessions',
#'django.contrib.sites', #'django.contrib.sites',
#'django.contrib.messages', #'django.contrib.messages',
'django.contrib.staticfiles',
#'django.contrib.admin', #'django.contrib.admin',
'gadjo', 'gadjo',
'wcs.qommon', 'wcs.qommon',
'django.contrib.staticfiles',
) )
WCS_LEGACY_CONFIG_FILE = None WCS_LEGACY_CONFIG_FILE = None