Newer
Older
// Quick tool for making a datacrate from a data pub
// FIXME - convert to ro-crate
const datacrate = require('./lib/catalog.js');
const calcyte = require('calcyte');
const fs = require('fs-extra');
const path = require('path');
const ArgumentParser = require('argparse').ArgumentParser;
const ORGANISATION = {
'id': 'https://www.uts.edu.au/',
'name': 'University of Technology Sydney'
};
const OWNER = 'Kathryn.T.Braye@student.uts.edu.au';
const APPROVER = 'Sharyn.Wise@uts.edu.au';
const CITATION = 'Citation';
const ZIP_PATH = 'https://test/'
async function makecatalog(doi, datapub, dest, zip) {
await fs.ensureDir(dest);
const catalog = await datacrate.datapub2catalog({
bagged: true,
zip: zip,
datapub: datapub,
organisation: ORGANISATION,
owner: OWNER,
approver: APPROVER
});
const catfile = path.join(dest, 'CATALOG.json');
await fs.writeFile(catfile, JSON.stringify(catalog, null, 2));
async function makedatacrate(catalog, dir, citation, zip) {
const index = new calcyte.Index();
index.init(catalog, dir, true);
console.log("Writing DataCrate");
index.make_index_html(citation, zip);
}
// const catalog_json = path.join(dir, sails.config.datapubs.datacrate.catalog_json);
// sails.log.info(`Building CATALOG.json with jsonld_h`);
// sails.log.silly(`catalog = ${JSON.stringify(catalog)}`);
// sails.log.info(`Writing CATALOG.json to ${catalog_json}`);
// fs.writeFileSync(catalog_json, JSON.stringify(catalog, null, 2));
// const index = new Index();
// index.init(catalog, dir, false);
// sails.log.info(`Writing CATALOG.html`);
// index.make_index_html("text_citation", "zip_path"); //writeFileSync
// return Observable.of({});
async function convertdatapub(pid, jsonfile, dest, zip) {
const datapub = await fs.readJSON(jsonfile);
const citation = datapub['citation_doi'];
const catalogfile = await makecatalog(pid, datapub, dest, zip);
await makedatacrate(catalogfile, dest, citation, zip);
}
var parser = new ArgumentParser({
version: '1.0.0',
addHelp: true,
description: 'Converts a ReDBox data publication to a CATALOG.json'
});
parser.addArgument(
['-i', '--input'],
{
help: "The input data publication",
required: true
parser.addArgument(
['-p', '--persistentid'],
{
help: "The persistent ID for the datacrate (a DOI, say)",
required: true
});
parser.addArgument(
['-z', '--zip'],
{
help: "The URL of the zipped datacrate when it is published",
defaultValue: ZIP_PATH
}
);
parser.addArgument(
['-d', '--directory'],
{
help: "Directory in which to write the CATALOG.json. Will be created if it doesn't exist",
defaultValue: './datacrate/'
}
);
var args = parser.parseArgs();
convertdatapub(args['persistentid'], args['input'], args['directory'], args['zip']);