2020-02-19-django-screencast¶
screencast¶
changes¶
This new version is going to be more portable and the web interface will be detatchable.
Command line apps can be automated, typically using a docer image and a shell script
1 2 3 | app do this app do that --parameter=12345 etc. |
This app reminds me of jupyter which runs code in a browser
the first version¶
First one was built for windoows platform and got too bloated, this one will be primarily for linux, but I might add .net core if I run into a demand for it.
The original also used celery distributed job scheduler and another standalone python scheduler, have to find the link for that one...
It also had scaffolding & deployment tools, and monitoring built in.
I doubt I'll migrate those features over, it's overkill for anything I am working at the moment and I'm having more fun working on micro projects rather than big monoliths which generall become clunky slow and not fun.
snippets¶
this is the messy django view, it does 3 things right now
- list the folders
- lists the files
- lists the contents of the file
later it will
- detect the language using the file extension
- have a db model so you can select a server to run the code against
- the run button will work which will execute the code from a command line
- a copy to clipboard button on all snippets
- have a rules model where you can stack them up in sequence (many to many)
views.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | from django.shortcuts import render from django.http import HttpResponse import sys import os SCRIPTFOLDER = "/home/shanenull/testui/testui/sql-scripts/" def file_get_contents(filename): """contents of one file""" with open(filename) as f: return f.read() def getprojectfolder(project): """list one project folder""" projectfolder = os.path.join(os.getcwd(), project) return projectfolder def showfiles(SCRIPTFOLDER): for path in os.listdir(SCRIPTFOLDER): full_path = os.path.join(SCRIPTFOLDER, path) outstring += "<hr>" if os.path.isfile(full_path): content = file_get_contents(full_path) outstring += "<h4> %s </h4>" % full_path outstring += "<br>" outstring += "<pre> <code language='sql'>" outstring += content outstring += "</code> </pre>" outstring += "<br>" button = """ <!-- Raised button with ripple --> <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect"> Run </button> """ outstring += button return outstring # views def home(request): """view script folders""" directories = next(os.walk(SCRIPTFOLDER))[1] return render(request, "sqltests/directories.html", {"directories": directories}) def view_folder(request, folder): """list files in one folder""" # workpath = os.path.normpath("e:/"+ymd+"/"+box) # html = "<br> %s - date <br>%s - box <br>%s - workpath " % (ymd, box, workpath) foldername = folder folder = SCRIPTFOLDER + folder html = r"<h3>%s</h3> " % folder html += "<hr>" if os.path.isdir(folder): onlyfiles = [ f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f)) ] for f in onlyfiles: html += "<br>\n" html += '<a class="mdl-button " href=%s>%s</a>' % (f, f) else: html += "<br>none " return render(request, "sqltests/folder.html", {"html": html, "folder": folder,}) def view_file(request, folder, file): """show one file""" html = "<h3>%s</h3>" % folder html += "<h3>%s</h3>" % file contents = file_get_contents(SCRIPTFOLDER + "/" + folder + "/" + file) html_end = ( '<a class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect "\ href=%s>%s</a>' % ("", "run") ) return render( request, "sqltests/file.html", {"html": html, "html_end": html_end, "contents": contents}, ) |