#!/usr/bin/env python # Sections # # Douglas Thrift # # $Id$ from __init__ import lock from ccscslab.facebook.models import Section from django.db import transaction import optparse @transaction.commit_on_success def main(): parser = optparse.OptionParser() parser.add_option('-D', '--debug', action = 'store_true', dest = 'debug') options = parser.parse_args()[0] lock(options.debug) # TODO: Projects, Books and Stuff tabs = (('The Lab', ''), ('People', 'people'), ('Computers', 'computers'), ('Webcam', 'webcam')) actions = (('Settings', 'settings'), ('Invite', 'invite'), ('Get an Account', 'account')) sections = [] for tab, items in ((True, tabs), (False, actions)): for position, (name, path) in enumerate(items): if options.debug: print '%s:\n %s\n %u' % (path, name, position) section, inserted = Section.objects.get_or_create(name = name, tab = tab) section.path = path section.position = position section.save() if options.debug: print ' %s' % ('inserted' if inserted else 'updated') sections.append(section.id) Section.objects.exclude(id__in = sections).delete() if __name__ == '__main__': main()