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>
|
<body>
|
||||||
<div class="flex-col outer-container">
|
<div class="flex-col outer-container">
|
||||||
<div class="flex-row">
|
<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">
|
<div class="navigation-bar" id="pwd">
|
||||||
/current/dir
|
/current/dir
|
||||||
</div>
|
</div>
|
||||||
|
@ -58,14 +58,12 @@ class NavDir extends NavEntry {
|
|||||||
}
|
}
|
||||||
async get_children(nav_window_ref) {
|
async get_children(nav_window_ref) {
|
||||||
var children = [];
|
var children = [];
|
||||||
var data = await cockpit.spawn(["/usr/share/cockpit/navigator/scripts/ls-no-fail.sh", this.path_str()], {err:"ignore"});
|
var data = await cockpit.spawn(["/usr/share/cockpit/navigator/scripts/ls-no-fail.py", this.path_str()], {err:"ignore"});
|
||||||
var entries = data.split("\n");
|
var entries = JSON.parse(data);
|
||||||
entries = entries.splice(1, entries.length - 2);
|
|
||||||
entries.forEach(entry => {
|
entries.forEach(entry => {
|
||||||
var entry_array = entry.split(/\s+/);
|
var filename = entry["filename"];
|
||||||
var filename = entry_array[entry_array.length - 1];
|
|
||||||
var path = (this.path.length >= 1 && this.path[0]) ? [... this.path, filename] : [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));
|
children.push(new NavDir(path, nav_window_ref));
|
||||||
else
|
else
|
||||||
children.push(new NavFile(path));
|
children.push(new NavFile(path));
|
||||||
@ -109,19 +107,23 @@ class NavWindow {
|
|||||||
window.alert(new_dir.path_str() + " is inaccessible.");
|
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();
|
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() {
|
async function main() {
|
||||||
nav_window.refresh();
|
await nav_window.refresh();
|
||||||
|
set_up_buttons();
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
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