Skip to content

Commit 9b9d77f

Browse files
authored
Merge pull request #235 from OpenAF/t8
T8
2 parents efa3fb3 + a5caf80 commit 9b9d77f

12 files changed

+166
-88
lines changed

js/openaf.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,12 +3146,12 @@ function parallel(aFunction, numThreads, aAggFunction, threads) {
31463146
function __balance() {
31473147
var l = getCPULoad();
31483148
if (l > numThreads) {
3149-
sync(function() { cooldown++; });
3149+
syncFn(function() { cooldown++; });
31503150
while (l > numThreads && __cooldown < numThreads) {
31513151
sleep((l - numThreads) * 2000);
31523152
l = getCPULoad();
31533153
}
3154-
sync(function() { cooldown--; });
3154+
syncFn(function() { cooldown--; });
31553155
}
31563156
}
31573157

@@ -3207,12 +3207,12 @@ function parallelArray(anArray, aReduceFunction, initValues, aAggFunction, numTh
32073207
function __balance() {
32083208
var l = getCPULoad();
32093209
if (l > numThreads) {
3210-
sync(function() { cooldown++; });
3210+
syncFn(function() { cooldown++; });
32113211
while (l > numThreads && __cooldown < numThreads) {
32123212
sleep((l - numThreads) * 2000);
32133213
l = getCPULoad();
32143214
}
3215-
sync(function() { cooldown--; });
3215+
syncFn(function() { cooldown--; });
32163216
}
32173217
}
32183218

@@ -5766,7 +5766,7 @@ const $cache = function(aName) {
57665766
__c.prototype.create = function() {
57675767
_$(this.func).isFunction().$_("Please provide a function (fn).");
57685768

5769-
sync(() => {
5769+
syncFn(() => {
57705770
if ($ch().list().indexOf(this.name) < 0) {
57715771
$ch(this.name).create(1, "cache", {
57725772
func: this.func,
@@ -6614,10 +6614,11 @@ const $fnM = (aFnName, aMap) => {
66146614
}
66156615
}
66166616

6617-
var $sec = function() {
6618-
ow.loadSec();
6619-
return $sec.apply(this, arguments);
6620-
}
6617+
// var $sec = function() {
6618+
// ow.loadSec();
6619+
// return $sec.apply(this, arguments);
6620+
// }
6621+
ow.loadSec();
66216622

66226623
/**
66236624
* <odoc>
@@ -7070,7 +7071,7 @@ oPromise.prototype.__exec = function() {
70707071
this.__f = __getThreadPool().submit(new java.lang.Runnable({
70717072
run: () => {
70727073
var ignore = false;
7073-
sync(() => { if (thisOP.executing) ignore = true; else thisOP.executing = true; }, thisOP.executing);
7074+
syncFn(() => { if (thisOP.executing) ignore = true; else thisOP.executing = true; }, thisOP.executing);
70747075
if (ignore) return;
70757076

70767077
while (thisOP.executors.size() > 0) {
@@ -7117,7 +7118,7 @@ oPromise.prototype.__exec = function() {
71177118
}
71187119
}
71197120

7120-
sync(() => { thisOP.executing = false; }, thisOP.executing);
7121+
syncFn(() => { thisOP.executing = false; }, thisOP.executing);
71217122

71227123
if (thisOP.state == thisOP.states.NEW && thisOP.executors.isEmpty()) {
71237124
thisOP.state = thisOP.states.FULFILLED;
@@ -7438,15 +7439,15 @@ const $await = function(aName) {
74387439

74397440
var _f = function(n) { this.n = n; };
74407441
_f.prototype.wait = function(aTimeout) {
7441-
sync(() => {
7442+
syncFn(() => {
74427443
if (isDef(aTimeout))
74437444
global.__await[this.n].wait(aTimeout);
74447445
else
74457446
global.__await[this.n].wait();
74467447
}, global.__await[this.n]);
74477448
};
74487449
_f.prototype.notify = function() {
7449-
sync(() => {
7450+
syncFn(() => {
74507451
global.__await[this.n].notify();
74517452
}, global.__await[this.n]);
74527453
};
@@ -7911,6 +7912,19 @@ const $ssh = function(aMap) {
79117912
return this;
79127913
};
79137914

7915+
/**
7916+
* <odoc>
7917+
* <key>$ssh.prefix(aPrefix) : $ssh</key>
7918+
* When executing aCmd (with .get) it will use ow.format.streamSHPrefix with aPrefix.
7919+
* </odoc>
7920+
*/
7921+
__ssh.prototype.prefix = function(aPrefix) {
7922+
aPrefix = _$(aPrefix, "prefix").isString().default("sh");
7923+
ow.loadFormat();
7924+
this.fcb = () => { return ow.format.streamSHPrefix(aPrefix, this.encoding, "\n") };
7925+
return this;
7926+
};
7927+
79147928
/**
79157929
* <odoc>
79167930
* <key>$ssh.mkdir(aDirectory) : $ssh</key>

js/openafconsole.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -600,17 +600,19 @@ function __help(aTerm) {
600600
h = searchHelp(aTerm);
601601
}
602602

603-
if (h.length == 1) {
604-
__outputConsoleComments(h[0].fullkey);
605-
__outputConsoleComments(repeat(h[0].fullkey.length, '-'));
606-
__outputConsoleComments(h[0].text);
607-
} else {
608-
if (h.length > 1) {
609-
for(let i in h) {
610-
__outputConsoleComments(h[i].key);
611-
}
603+
if (isArray(h)) {
604+
if (h.length == 1 && isDef(h[0].fullkey) && isDef(h[0].text)) {
605+
__outputConsoleComments(h[0].fullkey);
606+
__outputConsoleComments(repeat(h[0].fullkey.length, '-'));
607+
__outputConsoleComments(h[0].text);
612608
} else {
613-
__outputConsoleComments("Term '" + aTerm + "' not found.");
609+
if (h.length > 1) {
610+
for(let i in h) {
611+
__outputConsoleComments(h[i].key);
612+
}
613+
} else {
614+
__outputConsoleComments("Term '" + aTerm + "' not found.");
615+
}
614616
}
615617
}
616618
}

js/openafnlinq.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ var nLinq = function(anObject) {
127127
if (aTmpl.indexOf("{ski}") >= 0) aTmpl = aTmpl.replace(/{ski}/g, ($$(aValue).isString() && !useCase ? "String(" : ""));
128128
if (aTmpl.indexOf("{eki}") >= 0) aTmpl = aTmpl.replace(/{eki}/g, ($$(aValue).isString() && !useCase ? ").toLowerCase()" : ""));
129129
if (isM) aTmpl = aTmpl.replace(/{k}/g, (!useDot ? "$$$$(r).get(" + JSON.stringify(aKey) + ")" : "r." + aKey)); else aTmpl = aTmpl.replace(/{k}/g, "r");
130+
131+
if ($$(aValue).isString()) aValue = aValue.replace(/\$/g, "$$$");
130132
if ($$(aValue2).isDef()) {
133+
if ($$(aValue2).isString()) aValue2 = aValue2.replace(/\$/g, "$$$");
131134
aValue2 = vValue(aValue2);
132135
aTmpl = aTmpl.replace(/{v}/g, aValue).replace(/{v2}/g, aValue2);
133136
} else {

js/owrap.ch.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ OpenWrap.ch.prototype.__types = {
4444
}
4545
} else {
4646
this.__channels[aName].find(function(aKey) {
47-
sync(function() { keys.push(aKey); }, keys);
47+
syncFn(function() { keys.push(aKey); }, keys);
4848
});
4949
}
5050

@@ -633,7 +633,7 @@ OpenWrap.ch.prototype.__types = {
633633
getAll : function(aName, full) {
634634
var res = [];
635635
this.__cache[aName].Ch.forEach(function(aKey, aValue) {
636-
sync(function() { res.push(aValue); }, res);
636+
syncFn(function() { res.push(aValue); }, res);
637637
}, full);
638638
return res;
639639
},
@@ -3869,7 +3869,7 @@ OpenWrap.ch.prototype.comms = {
38693869
if (sUUID == aUUID) return;
38703870

38713871
$ch("__comm::" + na).create();
3872-
sync(function() {
3872+
syncFn(function() {
38733873
if (isUnDef(ow.ch.comms.__counter[na])) {
38743874
ow.ch.comms.__counter[na] = 0;
38753875
}
@@ -3901,8 +3901,8 @@ OpenWrap.ch.prototype.comms = {
39013901
ow.ch.jobs[na].length < 1 &&
39023902
ow.ch.size(na) > 0) {
39033903

3904-
sync(function() { ow.ch.comms.__counter[na] = 0; }, ow.ch.comms.__counter[na]);
3905-
sync(function() {
3904+
syncFn(function() { ow.ch.comms.__counter[na] = 0; }, ow.ch.comms.__counter[na]);
3905+
syncFn(function() {
39063906
//ow.obj.rest.set(aURL, { "o": "r", "k": Object.keys(ow.ch.getKeys(na)[0]), "t": t }, ow.ch.getAll(na), aL, aP, aT);
39073907
$rest({
39083908
login: aL,
@@ -3919,14 +3919,14 @@ OpenWrap.ch.prototype.comms = {
39193919
if (typeof v != "object") av = { "key": k, "value": v };
39203920
switch(op) {
39213921
case "setall":
3922-
sync(function() {
3922+
syncFn(function() {
39233923
if (ow.ch.comms.__counter[na] != 0)
39243924
ow.ch.comms.__counter[na]++;
39253925
else
39263926
ow.ch.comms.__counter[na] = 1;
39273927
}, ow.ch.comms.__counter[na]);
39283928
var res;
3929-
sync(function() {
3929+
syncFn(function() {
39303930
//res = ow.obj.rest.jsonSet(aURL, { "o": "a", "k": k, "t": t }, v, aL, aP, aT);
39313931
res = $rest({
39323932
login: aL,
@@ -3938,14 +3938,14 @@ OpenWrap.ch.prototype.comms = {
39383938
}, aURL);
39393939
break;
39403940
case "unsetall":
3941-
sync(function() {
3941+
syncFn(function() {
39423942
if (ow.ch.comms.__counter[na] != 0)
39433943
ow.ch.comms.__counter[na]++;
39443944
else
39453945
ow.ch.comms.__counter[na] = 1;
39463946
}, ow.ch.comms.__counter[na]);
39473947
var res;
3948-
sync(function() {
3948+
syncFn(function() {
39493949
//res = ow.obj.rest.jsonSet(aURL, { "o": "ua", "k": k, "t": t }, v, aL, aP, aT);
39503950
res = $rest({
39513951
login: aL,
@@ -3957,9 +3957,9 @@ OpenWrap.ch.prototype.comms = {
39573957
}, aURL);
39583958
break;
39593959
case "set" :
3960-
sync(function() { ow.ch.comms.__counter[na]++; }, ow.ch.comms.__counter[na]);
3960+
syncFn(function() { ow.ch.comms.__counter[na]++; }, ow.ch.comms.__counter[na]);
39613961
var res;
3962-
sync(function() {
3962+
syncFn(function() {
39633963
//res = ow.obj.rest.jsonSet(aURL, { "o": "e", "k": ak, "t": t }, av, aL, aP, aT);
39643964
res = $rest({
39653965
login: aL,
@@ -3971,9 +3971,9 @@ OpenWrap.ch.prototype.comms = {
39713971
}, aURL);
39723972
break;
39733973
case "unset" :
3974-
sync(function() { ow.ch.comms.__counter[na]++; }, ow.ch.comms.__counter[na]);
3974+
syncFn(function() { ow.ch.comms.__counter[na]++; }, ow.ch.comms.__counter[na]);
39753975
var res;
3976-
sync(function() {
3976+
syncFn(function() {
39773977
//res = ow.obj.rest.jsonRemove(aURL, { "o": "e", "k": ak, "t": t }, aL, aP, aT);
39783978
res = $rest({
39793979
login: aL,
@@ -3986,7 +3986,7 @@ OpenWrap.ch.prototype.comms = {
39863986
break;
39873987
default :
39883988
var res, resk;
3989-
sync(function() {
3989+
syncFn(function() {
39903990
//res = ow.obj.rest.jsonGet(aURL, { "o": "e", "k": ak }, aL, aP, aT);
39913991
//res = ow.obj.rest.jsonGet(aURL, { "o": "a" }, aL, aP, aT);
39923992
res = $rest({
@@ -4303,7 +4303,7 @@ OpenWrap.ch.prototype.server = {
43034303

43044304
function restSet(k, v) {
43054305
var cc;
4306-
sync(function() {
4306+
syncFn(function() {
43074307
if (isUnDef(ow.ch.server.__counter[aName])) {
43084308
ow.ch.server.__counter[aName] = 0; cc = 0;
43094309
}
@@ -4314,15 +4314,15 @@ OpenWrap.ch.prototype.server = {
43144314
case "a":
43154315
//if (k.t < $ch(aName).getVersion()) return undefined;
43164316
if (isArray(k.k) && isArray(v)) {
4317-
sync(function() { cc = ++ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
4317+
syncFn(function() { cc = ++ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
43184318
var rt = $ch(aName).setAll(k.k, v, k.t, aaUUID, aRequest);
43194319
return { "c": cc, "r": rt };
43204320
}
43214321
break;
43224322
case "ua":
43234323
//if (k.t < $ch(aName).getVersion()) return undefined;
43244324
if (isArray(k.k) && isArray(v)) {
4325-
sync(function() { cc = --ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
4325+
syncFn(function() { cc = --ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
43264326
var rt = $ch(aName).unsetAll(k.k, v, k.t, aaUUID, aRequest);
43274327
return { "c": cc, "r": rt };
43284328
}
@@ -4340,18 +4340,18 @@ OpenWrap.ch.prototype.server = {
43404340
return ak;
43414341
});
43424342

4343-
sync(function() { ow.ch.server.__counter[aName] = 0; cc = 0; }, ow.ch.server.__counter);
4343+
syncFn(function() { ow.ch.server.__counter[aName] = 0; cc = 0; }, ow.ch.server.__counter);
43444344
var rt = $ch(aName).setAll(k.k, v, k.t, aaUUID, aRequest);
43454345
return { "c": cc, "r": rt };
43464346
}
43474347
break;
43484348
case "e":
43494349
//if (k.t < $ch(aName).getVersion()) return undefined;
4350-
sync(function() { cc = ++ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
4350+
syncFn(function() { cc = ++ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
43514351
var rt = $ch(aName).set(k.k, v, k.t, aaUUID, aRequest);
43524352
return { "c": cc, "r": rt };
43534353
case "es":
4354-
sync(function() { cc = ++ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
4354+
syncFn(function() { cc = ++ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
43554355
var rt = $ch(aName).getSet(k.m, k.k, v, k.t, aaUUID, aRequest);
43564356
return { "c": cc, "r": rt };
43574357
}
@@ -4362,7 +4362,7 @@ OpenWrap.ch.prototype.server = {
43624362
var cc;
43634363
//if (k.t < $ch(aName).getVersion()) return undefined;
43644364

4365-
sync(function() {
4365+
syncFn(function() {
43664366
if (isUnDef(ow.ch.server.__counter[aName])) {
43674367
ow.ch.server.__counter[aName] = 0; cc = 0;
43684368
}
@@ -4371,7 +4371,7 @@ OpenWrap.ch.prototype.server = {
43714371
if (isDef(k.o)) {
43724372
if (k.o == "e") {
43734373
//if (k.t < $ch(aName).getVersion()) return undefined;
4374-
sync(function() { cc = ++ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
4374+
syncFn(function() { cc = ++ow.ch.server.__counter[aName]; }, ow.ch.server.__counter);
43754375
var rt = $ch(aName).unset(k.k, k.t, aaUUID, aRequest);
43764376
return { "c": cc, "r": rt };
43774377
}

js/owrap.format.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,18 +616,18 @@ OpenWrap.format.prototype.streamSH = function(aFunc, anEncoding) {
616616

617617
/**
618618
* <odoc>
619-
* <key>ow.format.streamSHPrefix(aPrefix, anEncoding) : Function</key>
619+
* <key>ow.format.streamSHPrefix(aPrefix, anEncoding, aSeperator) : Function</key>
620620
* To be used with sh, af.sh or ssh.exec as the callbackFunc. Returns a function that will prefix each line with aPrefix
621621
* and used the returned string with print and printErr.
622622
* </odoc>
623623
*/
624-
OpenWrap.format.prototype.streamSHPrefix = function(aPrefix, anEncoding) {
624+
OpenWrap.format.prototype.streamSHPrefix = function(aPrefix, anEncoding, aSeparator) {
625625
if (isUnDef(aPrefix)) aPrefix = "";
626626
return function(o, e) {
627627
$doWait(
628628
$doAll([
629-
$do(() => { ioStreamReadLines(o, (f) => { ansiStart(); print(ansiColor("BOLD,BLACK", "[" + aPrefix + "] ") + af.toEncoding(String(f.replace(/[\n\r]+/g, "")), anEncoding)); ansiStop(); }, __, false, __); }),
630-
$do(() => { ioStreamReadLines(e, (f) => { ansiStart(); printErr(ansiColor("RED", "[" + aPrefix + "] ") + af.toEncoding(String(f.replace(/[\n\r]+/g, "")), anEncoding)); ansiStop(); }, __, false, anEncoding); })
629+
$do(() => { ioStreamReadLines(o, (f) => { ansiStart(); print(ansiColor("BOLD,BLACK", "[" + aPrefix + "] ") + af.toEncoding(String(f.replace(/[\n\r]+/g, "")), anEncoding)); ansiStop(); }, aSeparator, false, __); }),
630+
$do(() => { ioStreamReadLines(e, (f) => { ansiStart(); printErr(ansiColor("RED", "[" + aPrefix + "] ") + af.toEncoding(String(f.replace(/[\n\r]+/g, "")), anEncoding)); ansiStop(); }, aSeparator, false, anEncoding); })
631631
])
632632
);
633633
};
@@ -819,6 +819,38 @@ OpenWrap.format.prototype.toBytesAbbreviation = function (bytes, precision) {
819819
return bytes.toPrecision(precision) + " " + sizes[posttxt];
820820
}
821821

822+
/**
823+
* <odoc>
824+
* <key>ow.format.fromBytesAbbreviation(aStr) : Number</key>
825+
* Tries to reverse the ow.format.toBytesAbbreviation from aStr (string) back to the original value in bytes.\
826+
* (available after ow.loadFormat())
827+
* </odoc>
828+
*/
829+
OpenWrap.format.prototype.fromBytesAbbreviation = function(aStr) {
830+
ow.loadFormat();
831+
832+
_$(aStr, "aStr").isString().$_();
833+
834+
var sizes = ['BYTES', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
835+
836+
aStr = aStr.trim();
837+
var arr = aStr.split(/\s+/), unit, value;
838+
if (arr.length >= 2) {
839+
unit = String(arr[arr.length - 1]);
840+
value = Number(arr[arr.length - 2]);
841+
} else {
842+
unit = "";
843+
value = parseFloat(aStr);
844+
}
845+
846+
var vfactor = 1;
847+
for(var ii = 1; ii <= sizes.indexOf(unit.toUpperCase()); ii++) {
848+
vfactor *= 1024;
849+
}
850+
851+
return Math.round(value * vfactor);
852+
}
853+
822854
/**
823855
* <odoc>
824856
* <key>ow.format.toSLON(aObj, cTheme) : String</key>

0 commit comments

Comments
 (0)