Skip to content

Commit

Permalink
replaced xslt
Browse files Browse the repository at this point in the history
  • Loading branch information
nleanba committed Feb 23, 2024
1 parent b5c774b commit 2b3c50e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 76 deletions.
91 changes: 15 additions & 76 deletions src/action_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* The jobs are accepted as messages and stored on disk, when the worker is started uncompleted jobs are picked up and exxecuted.
*/
import * as path from "https://deno.land/std@0.209.0/path/mod.ts";
import { path } from "./deps.ts";
import { config } from "../config/config.ts";
import { createBadge } from "./log.ts";
import { type Job, JobsDataBase } from "./JobsDataBase.ts";
import { getModifiedAfter, updateLocalData } from "./repoActions.ts";
import { gg2rdf } from "./gg2rdf.ts";

const GHTOKEN = Deno.env.get("GHTOKEN");

Expand Down Expand Up @@ -54,41 +55,6 @@ async function run() {
updateLocalData("source", log);

// run saxon on modified files
for (const file of modified) {
if (file.endsWith(".xml")) {
Deno.mkdirSync(
config.workDir + "/tmprdf/" + file.slice(0, file.lastIndexOf("/")),
{
recursive: true,
},
);
const p = new Deno.Command("java", {
args: [
"-jar",
path.fromFileUrl(import.meta.resolve("./saxon-he-10.8.jar")),
`-s:${file}`,
`-o:${config.workDir}/tmprdf/${file.slice(0, -4)}.rdf`,
`-xsl:${path.fromFileUrl(import.meta.resolve("./gg2rdf.xslt"))}`,
],
cwd: config.workDir + "/repo/source",
});
const { success, stdout, stderr } = await p.output();
if (!success) {
log("saxon failed:");
} else {
log("saxon succesful:");
}
log("STDOUT:");
log(new TextDecoder().decode(stdout));
log("STDERR:");
log(new TextDecoder().decode(stderr));
if (!success) {
throw new Error("Saxon failed");
}
}
}

// convert modified files to ttl
for (const file of modified) {
if (file.endsWith(".xml")) {
Deno.mkdirSync(
Expand All @@ -97,45 +63,16 @@ async function run() {
recursive: true,
},
);
const p = new Deno.Command("rapper", {
args: [
"-e",
"-w",
"-q",
`${file.slice(0, -4)}.rdf`,
"--output",
"turtle",
],
cwd: config.workDir + "/tmprdf",
stdin: "piped",
stdout: "piped",
stderr: "piped",
});
const child = p.spawn();

// open a file and pipe the subprocess output to it.
child.stdout.pipeTo(
Deno.openSync(`${config.workDir}/tmpttl/${file.slice(0, -4)}.ttl`, {
write: true,
create: true,
}).writable,
);

child.stderr.pipeTo(
Deno.openSync(path.join(jobStatus.dir, "log.txt"), {
append: true,
write: true,
create: true,
}).writable,
);

// manually close stdin
child.stdin.close();

const status = await child.status;
if (!status.success) {
log(`Rapper failed on ${file.slice(0, -4)}.rdf`);
throw new Error("Rapper failed");
try {
gg2rdf(
`${config.workDir}/repo/source/${file}`,
`${config.workDir}/tmpttl/${file.slice(0, -4)}.ttl`,
);
log("gg2rdf succesful");
} catch (error) {
log("gg2rdf failed:");
log(error);
throw new Error("gg2rdf failed");
}
}
}
Expand Down Expand Up @@ -169,7 +106,9 @@ async function run() {
try {
Deno.removeSync(ttlFile);
} catch (e) {
log(`Failed to remove file ${ttlFile}. Possbly the xml file was removed before it was trnsformed. \n${e}`);
log(
`Failed to remove file ${ttlFile}. Possbly the xml file was removed before it was transformed. \n${e}`,
);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {
} from "https://deno.land/std@0.202.0/http/file_server.ts";

export { existsSync } from "https://deno.land/std@0.202.0/fs/mod.ts";
export * as path from "https://deno.land/std@0.209.0/path/mod.ts";

export { parseArgs } from "https://deno.land/std@0.215.0/cli/parse_args.ts";

Expand Down

0 comments on commit 2b3c50e

Please sign in to comment.