Initial
This commit is contained in:
0
base/console_scripts/__init__.py
Normal file
0
base/console_scripts/__init__.py
Normal file
95
base/console_scripts/admin.py
Normal file
95
base/console_scripts/admin.py
Normal file
@@ -0,0 +1,95 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import argparse
|
||||
import os
|
||||
import pkg_resources
|
||||
import sys
|
||||
|
||||
DJANGO_MAIN_MODULE = 'main'
|
||||
VERSION = '0.1'
|
||||
|
||||
|
||||
class AdminCommand(object):
|
||||
@staticmethod
|
||||
def _setup_argparser():
|
||||
kwargs = {
|
||||
'description': 'Tool to manage your test django installation.',
|
||||
}
|
||||
parser = argparse.ArgumentParser(**kwargs)
|
||||
|
||||
parser.add_argument('-V', '--version', action='version',
|
||||
version='%(prog)s ' + VERSION)
|
||||
|
||||
subparsers = parser.add_subparsers(dest='subcmd', metavar='CMD',
|
||||
title='subcommands',
|
||||
description="Use '%(prog)s CMD -h' to show help for a subcommand")
|
||||
subparser = subparsers.add_parser('setup', help='Setup the installation.')
|
||||
subparser.add_argument('path', metavar='PATH',
|
||||
help='A directory, where the project files will be installed.')
|
||||
|
||||
return parser
|
||||
|
||||
def _parse_args(self, argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv[1:]
|
||||
if not argv:
|
||||
argv = ['--help']
|
||||
|
||||
return self._argparser.parse_args(argv)
|
||||
|
||||
@staticmethod
|
||||
def _subcmd_setup(cmd_args):
|
||||
django_main_module = DJANGO_MAIN_MODULE
|
||||
django_base_dir = cmd_args.path
|
||||
|
||||
sys.stdout.write('Setup installation in \'{path}\'...\n'.format(path=django_base_dir))
|
||||
|
||||
if os.path.exists(django_base_dir):
|
||||
if not os.path.isdir(django_base_dir):
|
||||
sys.stderr.write('{path}: Not a directory.\n'.format(path=django_base_dir))
|
||||
return os.EX_USAGE
|
||||
else:
|
||||
os.makedirs(django_base_dir)
|
||||
|
||||
sys.stdout.write('Creating django project...\n')
|
||||
django_cmd = 'django-admin startproject {name} "{path}"'.format(name=django_main_module,
|
||||
path=django_base_dir)
|
||||
exitval = os.system(django_cmd)
|
||||
if exitval != os.EX_OK:
|
||||
return exitval
|
||||
|
||||
sys.stdout.write('Configure django project...\n')
|
||||
|
||||
input_file = os.path.join('django_project_config', 'additional_settings.py')
|
||||
output_file = os.path.join(django_base_dir, django_main_module, 'settings.py')
|
||||
with open(output_file, 'ab') as f:
|
||||
f.write(pkg_resources.resource_string(__package__, input_file))
|
||||
|
||||
sys.stdout.write('Creating directories...\n')
|
||||
dirs = [
|
||||
os.path.join(django_base_dir, 'var', 'log'),
|
||||
os.path.join(django_base_dir, 'var', 'www', 'static'),
|
||||
]
|
||||
|
||||
for d in dirs:
|
||||
sys.stdout.write(' - %s\n' % d)
|
||||
os.makedirs(d)
|
||||
|
||||
return os.EX_OK
|
||||
|
||||
def __init__(self):
|
||||
self._argparser = self._setup_argparser()
|
||||
|
||||
def __call__(self, argv=None):
|
||||
cmd_args = self._parse_args(argv)
|
||||
subcmd = cmd_args.subcmd
|
||||
method_name = '_subcmd_{}'.format(subcmd)
|
||||
method = getattr(self, method_name)
|
||||
exitval = method(cmd_args)
|
||||
return exitval
|
||||
|
||||
|
||||
def main():
|
||||
cmd = AdminCommand()
|
||||
exitval = cmd()
|
||||
sys.exit(exitval)
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
#
|
||||
# Additional settings for django-test
|
||||
#
|
||||
|
||||
BASE_VAR_DIR = os.path.join(BASE_DIR, 'var')
|
||||
LOG_DIR = os.path.join(BASE_VAR_DIR, 'log')
|
||||
|
||||
INSTALLED_APPS += [
|
||||
'django_extensions',
|
||||
# Our main app
|
||||
'base',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'base.urls'
|
||||
STATIC_ROOT = os.path.join(BASE_VAR_DIR, 'www', 'static')
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'default': {
|
||||
'format': '%(asctime)s - %(name)s - %(levelname)s: %(message)s'
|
||||
},
|
||||
'verbose': {
|
||||
'format': ('%(asctime)s -- %(processName)s[%(process)d]:%(threadName)s[%(thread)d] -- '
|
||||
'%(name)s -- %(module)s...%(funcName)s() -- %(pathname)s:%(lineno)d -- '
|
||||
'%(levelname)s: %(message)s')
|
||||
},
|
||||
},
|
||||
'filters': {
|
||||
'require_debug_true': {
|
||||
'()': 'django.utils.log.RequireDebugTrue',
|
||||
},
|
||||
'require_debug_false': {
|
||||
'()': 'django.utils.log.RequireDebugFalse',
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'null': {
|
||||
'class': 'logging.NullHandler',
|
||||
},
|
||||
'console_debug': {
|
||||
'level': 'DEBUG',
|
||||
'filters': ['require_debug_true'],
|
||||
'class': 'logging.StreamHandler',
|
||||
},
|
||||
'console_default': {
|
||||
'level': 'INFO',
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'logging.StreamHandler',
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'level': 'INFO',
|
||||
'propagate': True,
|
||||
},
|
||||
},
|
||||
'root': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console_debug', 'console_default'],
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user