예제 #1
0
def upload_import(request):
    logger = getLogger('app')

    if request.method == 'POST':
        # Provided numbers identify dives which should be imported
        numbers = request.POST.getlist('numbers')
        upload_id = request.POST.get('upload_id')
        
        upload = get_object_or_404(DiveUpload, pk=upload_id, user=request.user)

        try:
            logger.debug("Parsing dives from upload #%d" % int(upload_id))

            # TODO: Parse only requested dives to improve performance
            dives = subsurface.parse_full(upload.data.path)
            logger.debug("Parsed %d dives" % len(dives))

            # Save parsed dives
            count = 0
            for dive, samples, events, sLocation in dives:
                if unicode(dive.number) in numbers:
                    _save_dive(request.user, dive, samples, events, sLocation)
                    count += 1
            
            logger.info("Saved %d dives" % count)
            messages.success(request, "Successfully imported %d dives." % count)
            return redirect('divelog_dive_list')
            
        except ParseError as ex:
            logger.error(ex)
            messages.error(request, "Failed parsing XML file.<br />Underlying error: %s" % ex.message)
            return redirect('divelog_upload_view', upload_id = upload_id)

    raise Http404
예제 #2
0
def run():
    path = DATA("subsurface-1.xml")

    start = datetime.now()
    p = subsurface.parse_short(path)
    print "Parse short taken: ", datetime.now() - start

    print p

    start = datetime.now()
    p = subsurface.parse_full(path)
    print "Parse full taken: ", datetime.now() - start

    print [(x[0], len(x[1])) for x in p]