Skip to content

Commit

Permalink
Check that required input files exist (in inputs folder)
Browse files Browse the repository at this point in the history
  • Loading branch information
James authored and James committed Apr 27, 2019
1 parent 6a212a6 commit 6c64180
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/org/idiosapps/ExceptionHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ExceptionHelper {
return getExceptionMessage(XETEX)
} else if (exception.toString().contains(PDFTEX)) {
return getExceptionMessage(PDFTEX)
} else if (exception.toString().contains("Input")) {
return exception.message.toString() // Exception already contains missing input file info
} else {
// log out start of stacktrace - should help with any Exception
exception.printStackTrace()
Expand Down
34 changes: 17 additions & 17 deletions src/main/kotlin/org/idiosapps/FXMLController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class FXMLController {
@FXML
fun buildButtonClicked() {

try { // first check dependencies - have a good idea of what to expect
try { // first check dependencies & inputs - have a good idea of what to expect
OSUtils.hasProgram(PDFTEX)
OSUtils.hasProgram(XETEX)
buildGradedReader() // our pipeline for building our graded reader!
Filenames.checkInputs()

buildGradedReader() // use our pipeline for building our graded reader!
} catch (exception: Exception) {
exception.printStackTrace()

Expand All @@ -36,8 +38,6 @@ class FXMLController {
private fun buildGradedReader() {
var languageUsed = "mandarin"

val filenames = Filenames() // load defaults from class

var vocabArray: ArrayList<String> = ArrayList() // This is a list of all the input vocabulary
var vocabComponentArray: ArrayList<ArrayList<String>> =
ArrayList() // This an [array of [arrays containing input vocab split into parts]]
Expand All @@ -50,38 +50,38 @@ class FXMLController {


OSUtils.tryMakeOutputDir() // Java will only make a new file if the parent folder exists (on Windows anyway)
val outputStoryTeXWriter = PrintWriter(filenames.outputStoryFilename, "UTF-8")
val outputStoryTeXWriter = PrintWriter(Filenames.outputStoryFilename, "UTF-8")

VocabUtils.splitVocabIntoParts(filenames.inputVocabFilename, vocabArray, vocabComponentArray)
VocabUtils.splitVocabIntoParts(filenames.inputKeyNamesFilename, keyNameArray, keyNameComponentArray)
VocabUtils.splitVocabIntoParts(Filenames.inputVocabFilename, vocabArray, vocabComponentArray)
VocabUtils.splitVocabIntoParts(Filenames.inputKeyNamesFilename, keyNameArray, keyNameComponentArray)

TexUtils.copyToTex(outputStoryTeXWriter, filenames.inputHeaderFilename)
TexUtils.copyToTex(outputStoryTeXWriter, filenames.inputTitleFilename)
TexUtils.copyToTex(outputStoryTeXWriter, filenames.inputStoryFilename)
TexUtils.copyToTex(outputStoryTeXWriter, Filenames.inputHeaderFilename)
TexUtils.copyToTex(outputStoryTeXWriter, Filenames.inputTitleFilename)
TexUtils.copyToTex(outputStoryTeXWriter, Filenames.inputStoryFilename)

SummaryPageWriter.writeVocabSection(outputStoryTeXWriter, filenames.inputVocabFilename, vocabComponentArray)
SummaryPageWriter.writeVocabSection(outputStoryTeXWriter, Filenames.inputVocabFilename, vocabComponentArray)
// todo WriteSummaryPage.writeTexGrammar

outputStoryTeXWriter.append("\\end{document}")
outputStoryTeXWriter.close()

PDFUtils.xelatexToPDF()

val pdfNumberOfPages = PDFUtils.getNumberOfPDFPages(filenames.outputPDFFilename)
PDFUtils.readPDF(filenames.outputPDFFilename, vocabComponentArray, pdfPageLastSentences, pdfNumberOfPages)
val pdfNumberOfPages = PDFUtils.getNumberOfPDFPages(Filenames.outputPDFFilename)
PDFUtils.readPDF(Filenames.outputPDFFilename, vocabComponentArray, pdfPageLastSentences, pdfNumberOfPages)
TexUtils.getTexLineNumbers(
filenames.outputStoryFilename,
Filenames.outputStoryFilename,
pdfPageLastSentences,
texLinesOfPDFPagesLastSentences,
texLineIndexOfPDFPageLastSentence
)

TeXStyling.addStyling(vocabComponentArray, filenames.outputStoryFilename, SUPERSCRIPT_STYLING)
TeXStyling.addStyling(keyNameComponentArray, filenames.outputStoryFilename, UNDERLINE_STYLING)
TeXStyling.addStyling(vocabComponentArray, Filenames.outputStoryFilename, SUPERSCRIPT_STYLING)
TeXStyling.addStyling(keyNameComponentArray, Filenames.outputStoryFilename, UNDERLINE_STYLING)

FooterUtils.addVocabFooters(
vocabComponentArray,
filenames.outputStoryFilename,
Filenames.outputStoryFilename,
texLinesOfPDFPagesLastSentences,
languageUsed,
pdfNumberOfPages,
Expand Down
38 changes: 29 additions & 9 deletions src/main/kotlin/org/idiosapps/Filenames.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
package org.idiosapps

import java.io.File

class Filenames {
val inputPrefix: String = "./input/"
val outputPrefix: String = "./output/"
companion object {
val inputPrefix: String = "./input/"
val outputPrefix: String = "./output/"

val inputHeaderFilename: String = inputPrefix + "header"
val inputTitleFilename: String = inputPrefix + "title"
val inputStoryFilename: String = inputPrefix + "story"

val inputVocabFilename: String = inputPrefix + "vocab"
val inputKeyNamesFilename: String = inputPrefix + "names"

val inputHeaderFilename: String = inputPrefix + "header"
val inputTitleFilename: String = inputPrefix + "title"
val inputStoryFilename: String = inputPrefix + "story"
val outputStoryFilename: String = outputPrefix + "outputStory.tex"
val outputPDFFilename: String = outputPrefix + "outputStory.pdf"

val inputVocabFilename: String = inputPrefix + "vocab"
val inputKeyNamesFilename: String = inputPrefix + "names"
fun checkInputs() {
val inputArray = arrayListOf(
inputHeaderFilename,
inputTitleFilename,
inputStoryFilename,
inputVocabFilename,
inputKeyNamesFilename
)

val outputStoryFilename: String = outputPrefix + "outputStory.tex"
val outputPDFFilename: String = outputPrefix + "outputStory.pdf"
for (input in inputArray) {
val inputFile = File(input)
if (!inputFile.exists()) { // could also check for size > 0 on required inputs
throw Exception("Input does not exist: $input")
}
}
}
}
}

0 comments on commit 6c64180

Please sign in to comment.