mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-29 16:45:13 +02:00
create custom ls python script
This commit is contained in:
parent
4c18ddd76a
commit
b7bd3a6b6b
@ -31,6 +31,8 @@
|
||||
<body>
|
||||
<div class="flex-col outer-container">
|
||||
<div class="flex-row">
|
||||
<button class="pf-c-button pf-m-secondary" id="nav-up-dir-btn">🡡</button>
|
||||
<div class="horizontal-spacer"></div>
|
||||
<div class="navigation-bar" id="pwd">
|
||||
/current/dir
|
||||
</div>
|
||||
|
@ -58,14 +58,12 @@ class NavDir extends NavEntry {
|
||||
}
|
||||
async get_children(nav_window_ref) {
|
||||
var children = [];
|
||||
var data = await cockpit.spawn(["/usr/share/cockpit/navigator/scripts/ls-no-fail.sh", this.path_str()], {err:"ignore"});
|
||||
var entries = data.split("\n");
|
||||
entries = entries.splice(1, entries.length - 2);
|
||||
var data = await cockpit.spawn(["/usr/share/cockpit/navigator/scripts/ls-no-fail.py", this.path_str()], {err:"ignore"});
|
||||
var entries = JSON.parse(data);
|
||||
entries.forEach(entry => {
|
||||
var entry_array = entry.split(/\s+/);
|
||||
var filename = entry_array[entry_array.length - 1];
|
||||
var filename = entry["filename"];
|
||||
var path = (this.path.length >= 1 && this.path[0]) ? [... this.path, filename] : [filename];
|
||||
if(entry[0] == 'd')
|
||||
if(entry["isdir"])
|
||||
children.push(new NavDir(path, nav_window_ref));
|
||||
else
|
||||
children.push(new NavFile(path));
|
||||
@ -109,19 +107,23 @@ class NavWindow {
|
||||
window.alert(new_dir.path_str() + " is inaccessible.");
|
||||
});
|
||||
}
|
||||
up() {
|
||||
console.log("up");
|
||||
if(this.path_stack.length > 1)
|
||||
this.path_stack.pop();
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
let nav_window = new NavWindow();
|
||||
|
||||
function set_up_buttons() {
|
||||
document.getElementById("nav-up-dir-btn").addEventListener("click", nav_window.up.bind(nav_window));
|
||||
}
|
||||
|
||||
async function main() {
|
||||
nav_window.refresh();
|
||||
await nav_window.refresh();
|
||||
set_up_buttons();
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
// setTimeout(function(){
|
||||
// while(files.length){
|
||||
// var file = files.pop();
|
||||
// file.destroy();
|
||||
// }
|
||||
// }, 5000);
|
22
navigator/scripts/ls-no-fail.py
Executable file
22
navigator/scripts/ls-no-fail.py
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
|
||||
def main():
|
||||
if(len(sys.argv) < 2):
|
||||
sys.exit(1)
|
||||
try:
|
||||
nodes = os.listdir(sys.argv[1])
|
||||
except:
|
||||
print("No such file or directory")
|
||||
sys.exit(1)
|
||||
response = []
|
||||
for node in nodes:
|
||||
response.append({"filename": node, "isdir": os.path.isdir(sys.argv[1] + "/" + node)})
|
||||
print(json.dumps(response, indent=4))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,8 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ls -lL "$1"
|
||||
|
||||
if [[ "$?" != "2" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
Loading…
x
Reference in New Issue
Block a user