I have some maintenance scripts in python, and was working to create a quick html interface to work with in order to kick the stuff off and handle configuration with a GUI.
I was thinking it would be as simple as ajax to a python file with some data params as follows:
$.ajax({
type:"POST",
url: "sample.py",
data: {json: self.json, filename: self.filename},
success: function(){ console.log("success"); },
error: function(){ console.log("error"); }
}).done(function(){ console.log("done"); });
and it found the file, but the response was the content of the python file, not an execution.
For the ease of use, sample.py is just as follows:
#!/usr/bin/python
import os
def main():
os.system("echo 'test file' > sampleFile.txt")
if __init__ == "__main__":
main()
the file runs independently, but i am having 2 issues:
1: How do i get the ajax file to make the python run? 2: How do i catch and process the params.
When looking at the file permissions, it says it has full control, so it doesnt seem to be something as easy as chmod +x sample.py
I didnt want to go through all the overhead of creating a Django application just to do this, as it is a single page html file, with an angularjs javascript implementation and bootstrap. Felt creating a whole Django or Flask app would have to much overhead, but i know those frameworks likely hide the key i need to get this all working.
EDIT
Part of me is thinking the following, but maybe my logic is off. 1- Spin up a SimpleHTTPServer 2- Set up a Socket listener on target port. 3- Catch information and execute scripts.
I noticed that when i ran an html file, it was assigning it a port by way of localhost, but obviously there would need to be a different mechanism to launch the html file if i need to spin up a server and set up a file which waits to intercept requests.