-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddLabelJob.js
71 lines (64 loc) · 2.14 KB
/
addLabelJob.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//TODO: This file must be revised
/*globals require, process, __dirname, GLOBAL, console, global*/
/**
* @module Executor:AddLabelJob
* @author lattmann / https://github.com/lattmann
* @author ksmyth / https://github.com/ksmyth
*/
var nodeRequire = require;
if (process.argv.length !== 4) {
throw new Error('Usage: node ' + process.argv[1] + ' URL (zipfile or *.zip)');
}
var webGMEUrl = process.argv[2];
var filearg = process.argv[3];
var requirejs = require('requirejs');
requirejs.config({
baseUrl: __dirname,
paths: {
blob: 'node_modules/webgme-engine/src/common/blob',
common: 'node_modules/webgme-engine/src/common'
},
nodeRequire: nodeRequire
});
var url = require('url');
var path = require('path');
var fs = require('fs');
var webGMEPort = url.parse(webGMEUrl).port || (url.parse(webGMEUrl).protocol === 'https:' ? 443 : 80);
global.WebGMEGlobal = {
getConfig: function () {
'use strict';
return {
server: url.parse(webGMEUrl).hostname,
serverPort: webGMEPort,
httpsecure: url.parse(webGMEUrl).protocol === 'https:'
};
}
};
requirejs(['blob/BlobClient', 'minimatch'], function (BlobClient, minimatch) {
'use strict';
var files;
if (filearg === '*.zip' || filearg === '*zip') {
files = fs.readdirSync('.').filter(minimatch.filter('*.zip', {matchBase: true}));
} else {
files = [filearg];
}
var hashes = {},
blobClient = new BlobClient(GLOBAL.WebGMEGlobal.getConfig()),
completed = 0,
putFile = function (zipfile) {
blobClient.putFile(path.basename(zipfile), fs.readFileSync(zipfile), function (err, hash) {
if (err) {
console.error(err);
process.exit(2);
}
// console.log(zipfile + ' hash ' + hash);
hashes[path.basename(zipfile, '.zip')] = hash;
if (++completed === files.length) {
console.log(JSON.stringify(hashes, null, 4));
}
});
};
for (var i = 0; i < files.length; i++) {
putFile(files[i]);
}
});