def downloadStudentForms(options):
  # TODO(nathaniel): Get these imports at top-level just like any others.
  from google.appengine.ext import db
  from soc.views.helper import lists
  from soc.modules.gsoc.models import profile
  from soc.modules.gsoc.models import program as program_model

  if not options.program_path:
    parser.error('--program is required')
  program = program_model.GSoCProgram.get_by_key_name(options.program_path)
  if not program:
    print 'Could not find program "%s"' % options.program_path
    return

  def QueryGen():
    query = profile.GSoCStudentInfo.all()
    query.filter('number_of_projects', 1)
    query.filter('program', program)
    return query

  outputdir = os.path.abspath(options.outputdir)

  if not os.path.exists(outputdir):
    os.mkdir(outputdir)

  if not os.path.isdir(outputdir):
    print "Could not create output dir: %s" % outputdir

  print "Fetching StudentInfo..."
  students = [i for i in interactive.deepFetch(QueryGen) if i.tax_form]

  keys = lists.collectParentKeys(students)
  keys = list(set(keys))

  prefetched = {}

  print "Fetching Profile..."

  for i in xrange(0, len(keys), 100):
    chunk = keys[i:i+100]
    entities = db.get(chunk)
    prefetched.update(dict((i.key(), i) for i in entities if i))

  lists.distributeParentKeys(students, prefetched)

  for student in students:
    form = student.tax_form
    _, ext = os.path.splitext(form.filename)
    path = os.path.join(outputdir, student.parent().link_id + ext)
    dst = open(path, "w")
    src = form.open()
    shutil.copyfileobj(src, dst)
    print "Downloading form to '%s'..." % path

  print 'Done.'
Example #2
0
def downloadStudentForms(options):
  from google.appengine.ext import db
  from soc.views.helper import lists as list_helper
  from soc.modules.gsoc.models.profile import GSoCStudentInfo


  q = lambda: GSoCStudentInfo.all().filter('number_of_projects', 1)

  outputdir = os.path.abspath(options.outputdir)

  if not os.path.exists(outputdir):
    os.mkdir(outputdir)

  if not os.path.isdir(outputdir):
    print "Could not create output dir: %s" % outputdir

  print "Fetching StudentInfo..."
  students = list(i for i in interactive.deepFetch(q) if i.tax_form)

  keys = list_helper.collectParentKeys(students)
  keys = list(set(keys))

  prefetched = {}

  print "Fetching Profile..."

  for i in xrange(0, len(keys), 100):
    chunk = keys[i:i+100]
    entities = db.get(chunk)
    prefetched.update(dict((i.key(), i) for i in entities if i))

  list_helper.distributeParentKeys(students, prefetched)

  countries = ['United States']
  us_students = [i for i in students if i.parent().res_country in countries]

  for student in us_students:
    form = student.tax_form
    _, ext = os.path.splitext(form.filename)
    path = os.path.join(outputdir, student.parent().link_id + ext)
    dst = open(path, "w")
    src = form.open()
    shutil.copyfileobj(src, dst)
    print "Downloading form to '%s'..." % path

  print "Done."
def downloadStudentForms(options):
  from google.appengine.ext import db
  from soc.views.helper import lists as list_helper
  from soc.modules.gci.models.profile import GCIProfile
  from soc.modules.gci.models.profile import GCIStudentInfo
  from soc.modules.gci.models.program import GCIProgram
  from soc.modules.gci.models.score import GCIScore

  if not options.program_path:
    print "--program_path or -p option is required"
  program = GCIProgram.get_by_key_name(options.program_path)

  outputdir = os.path.abspath(options.outputdir)
  if not os.path.exists(outputdir):
    os.mkdir(outputdir)

  if not os.path.isdir(outputdir):
    print "Could not create output dir: %s" % outputdir

  q = lambda: GCIScore.all().filter("program =", program)
  print "Fetching GCIScore..."
  scores = list(i for i in interactive.deepFetch(q))

  keys = list_helper.collectParentKeys(scores)
  keys = list(set(keys))
  prefetched = {}

  print "Fetching Profile..."
  for i in xrange(0, len(keys), 100):
    chunk = keys[i:i+100]
    entities = db.get(chunk)
    prefetched.update(dict((i.key(), i) for i in entities if i))

  profiles = prefetched.values()
  list_helper.distributeParentKeys(scores, prefetched)

  keys = list_helper.collectKeys(GCIProfile.student_info, entities)
  keys = list(set(keys))
  prefetched = {}

  print "Fetching StudentInfo..."
  for i in xrange(0, len(keys), 100):
    chunk = keys[i:i+100]
    entities = db.get(chunk)
    prefetched.update(dict((i.key(), i) for i in entities if i))

  studentInfos = prefetched.values()
  list_helper.distributeKeys(GCIProfile.student_info, profiles, prefetched)

  i = 0
  while i < len(profiles):
    try:
      profile = profiles[i]
      consent_form = profile.student_info.consent_form
      student_id_form = profile.student_info.student_id_form
      if not consent_form or not student_id_form:
        print "At least one form missing from %s" % profile.link_id
      else:
        _saveForm(profile, consent_form, 'consent-form', outputdir)
        _saveForm(profile, consent_form, 'student-id-form', outputdir)
    except Exception, e:
      continue
    i += 1
Example #4
0
def downloadStudentForms(options):
    from google.appengine.ext import db
    from soc.views.helper import lists as list_helper
    from soc.modules.gci.models.profile import GCIProfile
    from soc.modules.gci.models.profile import GCIStudentInfo
    from soc.modules.gci.models.program import GCIProgram
    from soc.modules.gci.models.score import GCIScore

    if not options.program_path:
        print "--program_path or -p option is required"
    program = GCIProgram.get_by_key_name(options.program_path)

    outputdir = os.path.abspath(options.outputdir)
    if not os.path.exists(outputdir):
        os.mkdir(outputdir)

    if not os.path.isdir(outputdir):
        print "Could not create output dir: %s" % outputdir

    q = lambda: GCIScore.all().filter("program =", program)
    print "Fetching GCIScore..."
    scores = list(i for i in interactive.deepFetch(q))

    keys = list_helper.collectParentKeys(scores)
    keys = list(set(keys))
    prefetched = {}

    print "Fetching Profile..."
    for i in xrange(0, len(keys), 100):
        chunk = keys[i:i + 100]
        entities = db.get(chunk)
        prefetched.update(dict((i.key(), i) for i in entities if i))

    profiles = prefetched.values()
    list_helper.distributeParentKeys(scores, prefetched)

    keys = list_helper.collectKeys(GCIProfile.student_info, entities)
    keys = list(set(keys))
    prefetched = {}

    print "Fetching StudentInfo..."
    for i in xrange(0, len(keys), 100):
        chunk = keys[i:i + 100]
        entities = db.get(chunk)
        prefetched.update(dict((i.key(), i) for i in entities if i))

    studentInfos = prefetched.values()
    list_helper.distributeKeys(GCIProfile.student_info, profiles, prefetched)

    i = 0
    while i < len(profiles):
        try:
            profile = profiles[i]
            consent_form = profile.student_info.consent_form
            student_id_form = profile.student_info.student_id_form
            if not consent_form or not student_id_form:
                print "At least one form missing from %s" % profile.link_id
            else:
                _saveForm(profile, consent_form, 'consent-form', outputdir)
                _saveForm(profile, consent_form, 'student-id-form', outputdir)
        except Exception, e:
            continue
        i += 1