def modsMakerHome(profileFilename):
    if request.method == "POST":
        input_file = request.files["input_file"]
        filename = request.files["input_file"].filename
        selectedSheet = request.form.get('sheetlist')

        globalConditions = {}
        for formInput in request.form:
            globalConditions[formInput] = True

        if ".xlsx" in filename:
            zipFile, filename = fileSupport.createZipFromExcel(
                input_file.read(), selectedSheet,
                os.path.join("profiles", profileFilename + ".yaml"),
                globalConditions)
            response = make_response(zipFile)
            response.headers[
                "Content-Disposition"] = "attachment; filename=" + filename
            return response

        else:
            return render_template(
                'error.html',
                error=
                "Please go back and select a .XLSX Excel file to proceed.",
                title="Error")

    else:
        profile = profileInterpreter.Profile(
            os.path.join("profiles", profileFilename + ".yaml"))
        return render_template(
            'mods/modsFileSelect.html',
            profilename=profileFilename,
            globalconditions=profile.profileGlobalConditions,
            title="MODS Maker")
Exemplo n.º 2
0
def createFileFromRow(row, profilePath, globalConditions):
    profile = profileInterpreter.Profile(profilePath, globalConditions=globalConditions)

    xmlString = profile.convertRowToXmlString(row)
    filename = getFilenameFromRow(row, 0, profile.profileFilenameColumn) + profile.profileFileExtension

    fileBuffer = io.StringIO()

    if xmlString != None:
        fileBuffer.write(xmlString)
            
    return fileBuffer.getvalue(), filename
def displayProfile(profileFilename):
    if request.method == "GET":
        modsMaker = profileInterpreter.Profile(
            os.path.join("profiles", profileFilename + ".yaml"))
        fieldList = modsMaker.getFieldList()
        yaml = open(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "profiles", profileFilename + ".yaml")).read()

        return render_template('profiles/profile.html',
                               fieldList=fieldList,
                               profilename=profileFilename,
                               yaml=yaml,
                               title="Profiles")
Exemplo n.º 4
0
def createPreviewFromRows(rows, profilePath, globalConditions):
    profile = profileInterpreter.Profile(profilePath, globalConditions=globalConditions)

    allXmlString = ""

    for (index, row) in enumerate(rows):
        
        xmlString = profile.convertRowToXmlString(row)
        filename = getFilenameFromRow(row, index, profile.profileFilenameColumn)

        if xmlString:
            allXmlString = allXmlString + "\n\n" + filename + profile.profileFileExtension + "\n\n" + xmlString
            allXmlString = allXmlString.lstrip("\n\n")
    
    return allXmlString
Exemplo n.º 5
0
def createZipFromExcel(excelFile, sheetName, profilePath, globalConditions):
    rows = convertXlsxToDictList(excelFile, sheetName)
    profile = profileInterpreter.Profile(profilePath, globalConditions=globalConditions)

    zipBuffer = io.BytesIO()
    zipObj = ZipFile(zipBuffer, 'w')

    for (index, row) in enumerate(rows):
        xmlString = profile.convertRowToXmlString(row)
        filename = getFilenameFromRow(row, index, profile.profileFilenameColumn)

        fileBuffer = io.StringIO()

        if xmlString != None:
                fileBuffer.write(xmlString)
                zipObj.writestr(filename + profile.profileFileExtension, fileBuffer.getvalue())
            
    zipObj.close()
    
    return zipBuffer.getvalue(), sheetName + '.zip'
def displayProfileForm(profileFilename):
    if request.method == "POST":
        metadata = request.form.to_dict()
        globalConditions = dict.fromkeys(metadata, True)
        xmlFile, filename = fileSupport.createFileFromRow(
            metadata,
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "profiles", profileFilename + ".yaml"),
            globalConditions)
        response = make_response(xmlFile)
        response.headers[
            "Content-Disposition"] = "attachment; filename=" + filename
        return response
    if request.method == "GET":
        profile = profileInterpreter.Profile(
            os.path.join("profiles", profileFilename + ".yaml"))
        fieldList = profile.getFieldList()

        allHeaders = {}

        for index, field in enumerate(fieldList):
            headers = field.get("headers", [])

            for header in headers:

                if allHeaders.get(header, None):
                    headers.remove(header)
                    fieldList[index]["headers"] = headers
                else:
                    allHeaders[header] = "here"

        filenameColumn = profile.profileFilenameColumn

        return render_template(
            'forms/form.html',
            fieldList=fieldList,
            profilename=profileFilename,
            globalconditions=profile.profileGlobalConditions,
            filenameColumn=filenameColumn,
            title="Forms")