Ignore:
Timestamp:
May 8, 2011, 7:45:17 PM (14 years ago)
Author:
rick
Message:

I guess the python documentation is right about this one :-)

"Lots of people want their programs to have “required options”. Think about it.
If it’s required, then it’s not optional! If there is a piece of information
that your program absolutely requires in order to run successfully, that’s what
positional arguments are for." - http://docs.python.org/library/optparse.html

Fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/management/commands/import_droidstumbler.py

    r9162 r9163  
    2626
    2727from django.core.management import setup_environ
    28 from django.core.management.base import BaseCommand
     28from django.core.management.base import BaseCommand, CommandError
    2929from optparse import OptionParser, make_option
    3030from gheat.models import *
     31import csv
    3132import datetime
    32 import csv
     33import os
     34import sys
    3335
    3436def import_droidstumbler(location, meetrondje, gebruiker, email):
     
    4951
    5052class Command(BaseCommand):
     53  args = '<csvfile>'
    5154  option_list = BaseCommand.option_list + (
    52     make_option('-f', '--location', dest='location', default='location'),
    5355    make_option('-m', '--meetrondje', dest='meetrondje', default='rondje'),
    5456    make_option('-g', '--gebruiker', dest='gebruiker', default='username'),
     
    5759
    5860  def handle(self, *args, **options):
    59     import_droidstumbler(options['location'],options['meetrondje'],options['gebruiker'],options['email'])
     61    try:
     62      (csv_file,) = args
     63    except ValueError:
     64      self.print_help(sys.argv[0],sys.argv[1])
     65      raise CommandError("Not all arguments are provided")
     66    if not os.path.isfile(csv_file):
     67      raise CommandError("csv file '%s' does not exists" % csv_file)
     68    import_droidstumbler(csv_file,options['meetrondje'],options['gebruiker'],options['email'])
Note: See TracChangeset for help on using the changeset viewer.