2020-02-19-django-screencast

screencast

what is this?

I'm rebuilding an old django app that I have.

This one will be command line apps which you can also manage from a web interface.

  • add servers
  • add local command line repos which work standalone as command line apps
  • create rules that stack the scripts and apps to make end to end tests or features for example
  • call the rules as command line apps from a web interface

I have not decided if the rules would be designed in the web interface then exported, or if the web app should just import the rules form a file...

This also reminds me of jupyter

the first version

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

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},
    )

Comments