work on monitor command

This commit is contained in:
bkfox
2015-06-30 17:31:01 +02:00
parent 45178862db
commit 2b78ba19de
3 changed files with 65 additions and 6 deletions

View File

@ -1,3 +1,5 @@
import argparse
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone
import programs.models as models
@ -17,6 +19,14 @@ class Model:
self.post = post
def to_string (self):
return '\n'.join(
[ ' - required: {}'.format(', '.join(self.required))
, ' - optional: {}'.format(', '.join(self.optional))
, (self.post is AddTags and ' - tags available\n') or
'\n'
])
def check_or_raise (self, options):
for req in self.required:
if req not in options:
@ -145,11 +155,24 @@ models = {
}
, AddTags
)
, 'episode': Model( models.Episode
, { 'title': str }
, { 'subtitle': str, 'can_comment': bool, 'date': DateTime
, 'parent_id': int, 'public': bool
}
, AddTags
)
, 'schedule': Model( models.Schedule
, { 'parent_id': int, 'date': DateTime, 'duration': Time
, 'frequency': int }
, { 'rerun': bool }
)
, 'soundfile': Model( models.SoundFile
, { 'parent_id': int, 'date': DateTime, 'file': str
, 'duration': Time}
, { 'fragment': bool, 'embed': str, 'removed': bool }
, AddTags
)
}
@ -158,6 +181,7 @@ class Command (BaseCommand):
help='Create, update, delete or dump an element of the given model.' \
' If no action is given, dump it'
def add_arguments (self, parser):
parser.add_argument( 'model', type=str
, metavar="MODEL"
@ -210,6 +234,13 @@ class Command (BaseCommand):
group.add_argument('--frequency', type=int)
group.add_argument('--rerun', action='store_true')
# fields
parser.formatter_class=argparse.RawDescriptionHelpFormatter
parser.epilog = 'available fields per model:'
for name, model in models.items():
parser.epilog += '\n ' + model.model.type() + ': \n' \
+ model.to_string()
def handle (self, *args, **options):
model = options.get('model')