def prepareFiles(request, validateonly):
    tricoder_fileinfo = {}
    tricoder_files = []
    numProblems = 0
    for lineno, afile in enumerate(request.FILES.getlist('tricoderfiles')):
        # print afile
        # we gotta do this for now!
        if 'barcode.' not in afile.name: afile.name = 'barcode.' + afile.name
        fileinfo = {'id': lineno, 'name': afile.name, 'status': '', 'date': time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())}
        # always use the current date as the date for the filename checking
        today = time.strftime("%Y-%m-%d", time.localtime())
        filenamepattern = r'^barcode.TRIDATA_' + re.escape(today) + r'_[\w_\.]+\.DAT$'
        if not re.match(filenamepattern, afile.name):
            fileinfo['status'] = 'filename is not valid'
            numProblems += 1
        else:
            try:
                print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name', afile.name, 'size', afile.size)
                if not validateonly:
                    handle_uploaded_file(afile)
                fileinfo['status'] = 'OK'
            except:
                if validateonly:
                    fileinfo['status'] = 'validation failed'
                else:
                    fileinfo['status'] = 'file handling problem, not uploaded'
                numProblems += 1

        tricoder_files.append(fileinfo)

    if numProblems > 0:
        errormsg = 'Errors found, abandoning upload. Please fix and try again.'
    else:
        tricoder_filenumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        tricoder_fileinfo['tricoder_filenumber'] = tricoder_filenumber
        tricoder_fileinfo['estimatedtime'] = '%8.1f' % (len(tricoder_files) * 10 / 60.0)

        if 'createtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'createtricoder'
            if not validateonly:
                loginfo('start', get_tricoder_file('input',tricoder_filenumber), request)
                try:
                    retcode = subprocess.call(
                        [POSTBLOBPATH, get_tricoder_file('input',tricoder_filenumber)])
                    if retcode < 0:
                        loginfo('process', tricoder_filenumber + " Child was terminated by signal %s" % -retcode,
                                request)
                    else:
                        loginfo('process', tricoder_filenumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', get_tricoder_file('input',tricoder_filenumber), request)

        elif 'uploadtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'uploadtricoder'
        else:
            tricoder_fileinfo['status'] = 'No status possible'

    return tricoder_fileinfo, tricoder_files, numProblems
Exemplo n.º 2
0
def prepareFiles(request, validateonly):
    tricoder_fileinfo = {}
    tricoder_files = []
    for lineno, afile in enumerate(request.FILES.getlist("tricoderfiles")):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ("id", lineno, "name", afile.name, "size", afile.size)
            fileinfo = {"id": lineno, "name": afile.name, "size": afile.size, "date": ""}
            if not validateonly:
                handle_uploaded_file(afile)
            tricoder_files.append(fileinfo)
        except:
            if not validateonly:
                # we still upload the file, anyway...
                handle_uploaded_file(afile)
            tricoder_files.append(
                {"name": afile.name, "size": afile.size, "error": "problem extracting image metadata, not processed"}
            )

    if len(tricoder_files) > 0:
        tricoder_filenumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        tricoder_fileinfo["tricoder_filenumber"] = tricoder_filenumber
        tricoder_fileinfo["estimatedtime"] = "%8.1f" % (len(tricoder_files) * 10 / 60.0)

        if "createtricoder" in request.POST:
            tricoder_fileinfo["status"] = "createtricoder"
            if not validateonly:
                loginfo("start", get_tricoder_file(tricoder_filenumber), request)
                try:
                    retcode = subprocess.call([POSTBLOBPATH, get_tricoder_file(tricoder_filenumber)])
                    if retcode < 0:
                        loginfo(
                            "process", tricoder_filenumber + " Child was terminated by signal %s" % -retcode, request
                        )
                    else:
                        loginfo("process", tricoder_filenumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo("error", "Execution failed: %s" % e, request)
                loginfo("finish", get_tricoder_file(tricoder_filenumber), request)

        elif "uploadtricoder" in request.POST:
            tricoder_fileinfo["status"] = "uploadtricoder"
        else:
            tricoder_fileinfo["status"] = "No status possible"

    return tricoder_fileinfo, tricoder_files
Exemplo n.º 3
0
def prepareFiles(request, validateonly):
    tricoder_fileinfo = {}
    tricoder_files = []
    for lineno, afile in enumerate(request.FILES.getlist('tricoderfiles')):
        # print afile
        try:
            print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name', afile.name, 'size', afile.size)
            fileinfo = {'id': lineno, 'name': afile.name, 'size': afile.size, 'date': ''}
            if not validateonly:
                handle_uploaded_file(afile)
            tricoder_files.append(fileinfo)
        except:
            if not validateonly:
                # we still upload the file, anyway...
                handle_uploaded_file(afile)
            tricoder_files.append({'name': afile.name, 'size': afile.size,
                           'error': 'problem extracting image metadata, not processed'})

    if len(tricoder_files) > 0:
        tricoder_filenumber = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        tricoder_fileinfo['tricoder_filenumber'] = tricoder_filenumber
        tricoder_fileinfo['estimatedtime'] = '%8.1f' % (len(tricoder_files) * 10 / 60.0)

        if 'createtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'createtricoder'
            if not validateonly:
                loginfo('start', get_tricoder_file(tricoder_filenumber), request)
                try:
                    retcode = subprocess.call(
                        [POSTBLOBPATH, get_tricoder_file(tricoder_filenumber)])
                    if retcode < 0:
                        loginfo('process', tricoder_filenumber + " Child was terminated by signal %s" % -retcode, request)
                    else:
                        loginfo('process', tricoder_filenumber + ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish', get_tricoder_file(tricoder_filenumber), request)

        elif 'uploadtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'uploadtricoder'
        else:
            tricoder_fileinfo['status'] = 'No status possible'

    return tricoder_fileinfo, tricoder_files
def showresults(request):
    filename = request.GET['filename']
    directory = request.GET['directory']
    f = open(get_tricoder_file(directory,filename), "rb")
    status = 'up'
    timestamp = time.strftime("%b %d %Y %H:%M:%S", time.localtime())
    return render(request, 'uploadtricoder.html',
                  {'timestamp': timestamp, 'version': prmz.VERSION,
                   'status': status, 'apptitle': TITLE, 'serverinfo': SERVERINFO,
                   'filecontent': f.read(), 'filename': filename, 'directory': directory})
Exemplo n.º 5
0
def showresults(request):
    filename = request.GET['filename']
    directory = request.GET['directory']
    f = open(get_tricoder_file(directory, filename), "rb")
    status = 'up'
    timestamp = time.strftime("%b %d %Y %H:%M:%S", time.localtime())
    return render(
        request, 'uploadtricoder.html', {
            'timestamp': timestamp,
            'version': prmz.VERSION,
            'status': status,
            'apptitle': TITLE,
            'serverinfo': SERVERINFO,
            'filecontent': f.read(),
            'filename': filename,
            'directory': directory
        })
Exemplo n.º 6
0
def showresults(request, filename):
    f = open(get_tricoder_file(filename), "rb")
    response = HttpResponse(FileWrapper(f), content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    return response
Exemplo n.º 7
0
def showresults(request, filename):
    f = open(get_tricoder_file(filename), "rb")
    response = HttpResponse(FileWrapper(f), content_type="text/csv")
    response["Content-Disposition"] = 'attachment; filename="%s"' % filename
    return response
Exemplo n.º 8
0
def prepareFiles(request, validateonly):
    tricoder_fileinfo = {}
    tricoder_files = []
    numProblems = 0
    for lineno, afile in enumerate(request.FILES.getlist('tricoderfiles')):
        # print afile
        # we gotta do this for now!
        if 'barcode.' not in afile.name: afile.name = 'barcode.' + afile.name
        fileinfo = {
            'id': lineno,
            'name': afile.name,
            'status': '',
            'date': time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
        }
        # always use the current date as the date for the filename checking
        today = time.strftime("%Y-%m-%d", time.localtime())
        filenamepattern = r'^barcode.TRIDATA_' + re.escape(
            today) + r'_[\w_\.]+\.DAT$'
        if not re.match(filenamepattern, afile.name):
            fileinfo['status'] = 'filename is not valid'
            numProblems += 1
        else:
            try:
                print "%s %s: %s %s (%s %s)" % ('id', lineno, 'name',
                                                afile.name, 'size', afile.size)
                if not validateonly:
                    handle_uploaded_file(afile)
                fileinfo['status'] = 'OK'
            except:
                if validateonly:
                    fileinfo['status'] = 'validation failed'
                else:
                    fileinfo['status'] = "error! %s" % traceback.format_exc()
                    sys.stderr.write("error! %s" % traceback.format_exc())
                numProblems += 1

        tricoder_files.append(fileinfo)

    if numProblems > 0:
        errormsg = 'Errors found, abandoning upload. Please fix and try again.'
    else:
        tricoder_filenumber = time.strftime("%Y-%m-%d-%H-%M-%S",
                                            time.localtime())
        tricoder_fileinfo['tricoder_filenumber'] = tricoder_filenumber
        tricoder_fileinfo['estimatedtime'] = '%8.1f' % (len(tricoder_files) *
                                                        10 / 60.0)

        if 'createtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'createtricoder'
            if not validateonly:
                loginfo('start', get_tricoder_file('input',
                                                   tricoder_filenumber),
                        request)
                try:
                    retcode = subprocess.call([
                        POSTBLOBPATH,
                        get_tricoder_file('input', tricoder_filenumber)
                    ])
                    if retcode < 0:
                        loginfo(
                            'process', tricoder_filenumber +
                            " Child was terminated by signal %s" % -retcode,
                            request)
                    else:
                        loginfo(
                            'process', tricoder_filenumber +
                            ": Child returned %s" % retcode, request)
                except OSError as e:
                    loginfo('error', "Execution failed: %s" % e, request)
                loginfo('finish',
                        get_tricoder_file('input', tricoder_filenumber),
                        request)

        elif 'uploadtricoder' in request.POST:
            tricoder_fileinfo['status'] = 'uploadtricoder'
        else:
            tricoder_fileinfo['status'] = 'No status possible'

    return tricoder_fileinfo, tricoder_files, numProblems