cciw-website / scripts /

The default branch has multiple heads

#!/usr/bin/env python2.5
from optparse import OptionParser
import sys
from django.contrib.auth.models import User
from cciw.cciwmain.models import Person
from cciw.officers.create import create_officer, create_multiple_officers

parser = OptionParser(usage=
""" <username> <first_name> <last_name> <email>
OR: --leader <username> <first_name> <last_name> <email> "<Person name>"
OR: --update <username> <first_name> <last_name> <email>
OR: --fromcsv < data.csv
OR: --fromcsv --dryrun < data.csv

parser.add_option("-u", "--update", dest="update", action="store_true", default=False, help="Updates an existing record, resetting password and sending out email again")
parser.add_option("", "--leader", dest="is_leader", action="store_true", default=False, help="Adds/updates this person as a leader, not an officer")
parser.add_option("", "--dryrun", dest="dryrun", action="store_true", default=False, help="Don't touch the database or actually send emails")
parser.add_option("", "--fromcsv", dest="fromcsv", action="store_true", default=False, help="Read data in from CSV file")

def usage_and_exit():

def main():
    options, args = parser.parse_args()

    if options.fromcsv:
        if len(args) > 0:
        if options.is_leader:
            print "'--leader' not valid with '--fromcsv'"
        csv_data = parse_csv_data(sys.stdin)
        create_multiple_officers(csv_data, options.dryrun, verbose=True)

        if options.is_leader:
            if len(args) != 5:
            username, first_name, last_name, email, personname = args
            if personname is not None:
                    person = Person.objects.get(name=personname)
                except Person.DoesNotExist:
                    print "Person called '%s' does not exist in the database" % personname
                person = None

            create_officer(username, first_name, last_name, email,
                           update=options.update, is_leader=True,
                           person=person, verbose=True)
            if len(args) != 4:
            username, first_name, last_name, email = args
            create_officer(username, first_name, last_name, email,
                           update=options.update, verbose=True)

def parse_csv_data(iterable):
    import csv
    return list(csv.reader(iterable))

if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.