Skip to content
Snippets Groups Projects
Commit d6ad4d55 authored by Mike Lynch's avatar Mike Lynch
Browse files

Added command-line arguments, removed debugging output

parent 78e512f5
Branches
Tags
No related merge requests found
// Module to generate a bunch of CATALOG.json files which
// have arbitrary but realistic data
//
// TODO: generate some random text files and add them
// as well
const ORGANISATION = {
'id': 'https://examples.edu',
......@@ -35,7 +38,7 @@ const fs = require('fs-extra');
const randdict = require('random-word');
const path = require('path');
const uuidv4 = require('uuid/v4');
const ArgumentParser = require('argparse').ArgumentParser;
function randrange(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
......@@ -76,7 +79,6 @@ function randsentence() {
function randtext() {
const nsentences = randrange(PARA_MIN, PARA_MAX);
console.log(nsentences);
return randoms(nsentences, randsentence).join(' ') + '\n';
}
......@@ -117,14 +119,10 @@ async function makedatacrate(dest, datapub) {
});
const catfile = path.join(dest, id, 'CATALOG.json');
await fs.writeFile(catfile, JSON.stringify(catalog, null, 2));
console.log('Wrote ' + catfile);
const datapubfile = path.join(dest, id, 'datapub.json');
await fs.writeFile(datapubfile, JSON.stringify(datapub, null, 2));
console.log('Wrote ' + datapubfile);
}
async function makedatacrates(dest, n) {
async function randomdatacrates(dest, n) {
const datapubs = randdatapubs(n);
Promise.all(
datapubs.map(async p => {
......@@ -134,7 +132,37 @@ async function makedatacrates(dest, n) {
console.log("Done");
}
makedatacrates('./output/', 5)
var parser = new ArgumentParser({
version: '1.0.0',
addHelp: true,
description: 'Generates a bunch of plausible random DataCrates'
});
parser.addArgument(
['-d', '--directory'],
{
help: "Directory in which to write DataCrates. Will be created if it doesn't exist",
defaultValue: './output/'
}
);
parser.addArgument(
['-n', '--number'],
{
help: 'Number of DataCrates to generate.',
type: 'int',
defaultValue: 10
}
);
var args = parser.parseArgs();
console.log(`Generating ${args['number']} random DataCrates in ${args['directory']}`);
randomdatacrates(args['directory'], args['number']);
......@@ -65,6 +65,14 @@
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg="
},
"argparse": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
"requires": {
"sprintf-js": "~1.0.2"
}
},
"array-equal": {
"version": "1.0.0",
"resolved": "http://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz",
......@@ -1403,6 +1411,11 @@
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"optional": true
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
},
"ssf": {
"version": "0.10.2",
"resolved": "https://registry.npmjs.org/ssf/-/ssf-0.10.2.tgz",
......
......@@ -14,6 +14,7 @@
"license": "GPL-3.0",
"repository": "https://code.research.uts.edu.au/eresearch/datacrate",
"dependencies": {
"argparse": "^1.0.10",
"calcyte": "^1.0.2",
"fs-extra": "^7.0.0",
"jsonld": "^1.1.0",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment