Skip to content
Snippets Groups Projects
Commit 810c3d8e authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Optionally include newest-file-in-archive date/time and other features

parent 1ccd56fc
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -12,9 +12,22 @@ function datestr(t) ...@@ -12,9 +12,22 @@ function datestr(t)
return system.datestr(t); return system.datestr(t);
} }
function archive_date(file)
{
try {
var list = Archive(file).list();
} catch(e) {
return file_date(file);
}
var t = 0;
for(var i = 0; i < list.length; i++)
t = Math.max(list[i].time, t);
return t;
}
var sort_prop = "name"; var sort_prop = "name";
var exclude_list = []; var exclude_list = [];
var options = { sort: false}; var options = { sort: false, case_sensitive: true };
var json_space; var json_space;
var detail = -1; var detail = -1;
var dir_list = []; var dir_list = [];
...@@ -55,19 +68,21 @@ for(var i = 0; i < argc; i++) { ...@@ -55,19 +68,21 @@ for(var i = 0; i < argc; i++) {
writeln(" -lib=<name> list files in all directories of specified library"); writeln(" -lib=<name> list files in all directories of specified library");
writeln(" -ex=<filespec> add filename or spec to excluded filename list"); writeln(" -ex=<filespec> add filename or spec to excluded filename list");
writeln(" -hdr include header for each directory"); writeln(" -hdr include header for each directory");
writeln(" -sort[=prop] enable case-sensitive output sorting"); writeln(" -sort[=prop] enable/configure file sorting");
writeln(" -isort[=prop] enable case-insensitive output sorting"); writeln(" -i perform case-insensitive global sorting");
writeln(" -reverse reverse the sort order"); writeln(" -reverse reverse the sort order");
writeln(" -json[=spaces] use JSON formatted output"); writeln(" -json[=spaces] use JSON formatted output");
writeln(" -new=<days> include new files uploaded in past <days>"); writeln(" -new=<days> include new files uploaded in past <days>");
writeln(" -p=[list] specify comma-separated list of property names to print"); writeln(" -p=<list> specify comma-separated list of property names to print");
writeln(" -cdt include credit value instead of file size");
writeln(" -ext include extended file descriptions"); writeln(" -ext include extended file descriptions");
writeln(" -ext=<prefix> specify extended file description prefix"); writeln(" -ext=<prefix> specify extended file description prefix");
writeln(" -fmt=<fmt> specify output format string (printf syntax)"); writeln(" -fmt=<fmt> specify output format string (printf syntax)");
writeln(" -date=<fmt> specify date/time display format (strftime syntax)"); writeln(" -date=<fmt> specify date/time display format (strftime syntax)");
writeln(" -size=<fmt> specify size/byte display format (0-" + (size_fmts.length - 1) + ")"); writeln(" -size=<fmt> specify size/byte display format (0-" + (size_fmts.length - 1) + ")");
writeln(" -name=<len> specify filename length"); writeln(" -name=<len> specify filename length (default: 12)");
writeln(" -pad pad filename with spaces"); writeln(" -pad pad filename with spaces");
writeln(" -adate use latest archived file date/time instead of file time");
writeln(" -v increase verbosity (detail) of output"); writeln(" -v increase verbosity (detail) of output");
exit(0); exit(0);
} }
...@@ -108,9 +123,8 @@ for(var i = 0; i < argc; i++) { ...@@ -108,9 +123,8 @@ for(var i = 0; i < argc; i++) {
options.sort = true; options.sort = true;
continue; continue;
} }
if(opt.indexOf("isort=") == 0) { if(opt == "i") {
sort_prop = opt.slice(6); options.case_sensitive = false;
options.isort = true;
continue; continue;
} }
if(opt[0] == 'v') { if(opt[0] == 'v') {
...@@ -190,6 +204,11 @@ if(fmt != "json") { ...@@ -190,6 +204,11 @@ if(fmt != "json") {
offset += size_fmts[size_fmt][2] + 1; offset += size_fmts[size_fmt][2] + 1;
} }
} }
if(detail > FileBase.DETAIL.EXTENDED) {
props.push("time");
f += " %-8s";
offset += 9;
}
if(detail >= FileBase.DETAIL.NORM) { if(detail >= FileBase.DETAIL.NORM) {
props.push("desc"); props.push("desc");
f += " %-58s"; f += " %-58s";
...@@ -226,13 +245,17 @@ for(var i = 0; i < dir_list.length; i++) { ...@@ -226,13 +245,17 @@ for(var i = 0; i < dir_list.length; i++) {
if(!base.open()) if(!base.open())
throw new Error(base.last_error); throw new Error(base.last_error);
if(detail < 0) if(detail < 0)
file_list = file_list.concat(base.get_names(filespec, since, /* sort: */false)); file_list = file_list.concat(base.get_names(filespec, since, options.sort));
else { else {
var list = base.get_list(filespec, detail, since, /* sort: */false); var list = base.get_list(filespec, detail, since, options.sort);
for(var j = 0; j < list.length; j++) { for(var j = 0; j < list.length; j++) {
list[j].dir = dir_code; list[j].dir = dir_code;
if(list[j].extdesc) if(list[j].extdesc)
list[j].extdesc = "\n" + list[j].extdesc; list[j].extdesc = "\n" + list[j].extdesc;
if(options.adate)
list[j].time = archive_date(base.get_path(list[j]));
if(options.cdt)
list[j].size = list[j].cost;
} }
file_list = file_list.concat(list); file_list = file_list.concat(list);
} }
...@@ -242,7 +265,8 @@ for(var i = 0; i < dir_list.length; i++) { ...@@ -242,7 +265,8 @@ for(var i = 0; i < dir_list.length; i++) {
if(!file_list.length) if(!file_list.length)
exit(0); exit(0);
if(options.isort) { if(!options.hdr && options.sort) {
if(options.case_sensitive) {
log("Sorting " + file_list.length + " files..."); log("Sorting " + file_list.length + " files...");
if(typeof file_list[0] == "string") if(typeof file_list[0] == "string")
file_list.sort( file_list.sort(
...@@ -264,7 +288,7 @@ if(options.isort) { ...@@ -264,7 +288,7 @@ if(options.isort) {
); );
} }
} }
else if(options.sort) { else {
log("Sorting " + file_list.length + " files..."); log("Sorting " + file_list.length + " files...");
if(typeof file_list[0] == "string") if(typeof file_list[0] == "string")
file_list.sort(); file_list.sort();
...@@ -278,6 +302,7 @@ else if(options.sort) { ...@@ -278,6 +302,7 @@ else if(options.sort) {
); );
} }
} }
}
if(options.reverse) if(options.reverse)
file_list.reverse(); file_list.reverse();
...@@ -351,6 +376,9 @@ function list_file(file, fmt, props) ...@@ -351,6 +376,9 @@ function list_file(file, fmt, props)
var p = file[name]; var p = file[name];
switch(typeof p) { switch(typeof p) {
case "undefined": case "undefined":
if(name == 'desc')
a.push(file.name);
else
a.push(''); a.push('');
break; break;
case "string": case "string":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment