last changes, start uuid based project
parent
fef563f975
commit
4564cb6d15
@ -1,8 +1,9 @@
|
||||
PANDOC = "pandoc"
|
||||
EPUB_PATH = None
|
||||
MAKE = "make"
|
||||
|
||||
MAKEFILE = "/home/murtaugh/projects/DPT/hybrideditor/cgi-bin/makefile"
|
||||
PROJECT_PATH = "./projects"
|
||||
PROJECT_URL = "/projects/" # must end with /
|
||||
EDITOR_URL = "/cgi-bin/hype.cgi"
|
||||
|
||||
SAMPLE_PROJECT_PATH = "projects/sample"
|
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import cgitb; cgitb.enable()
|
||||
import os, cgi, sys, operator
|
||||
from settings import PROJECT_PATH, PROJECT_URL, EDITOR_URL, SAMPLE_PROJECT_PATH
|
||||
from urlparse import urljoin
|
||||
from urllib import urlencode
|
||||
from project import Project
|
||||
from uuid import uuid1
|
||||
from shutil import copytree
|
||||
|
||||
|
||||
method = os.environ.get("REQUEST_METHOD", "")
|
||||
|
||||
def redirect (url):
|
||||
print """Content-type: text/html; charset=utf-8"""
|
||||
print
|
||||
print """<!DOCTYPE html>
|
||||
<body style="margin:2em" >
|
||||
<a id="next" href="{0}">continue</a>
|
||||
</body>
|
||||
<script>
|
||||
var href = document.getElementById("next").getAttribute("href");
|
||||
window.location = href;
|
||||
</script>
|
||||
""".format(url)
|
||||
|
||||
errormsg = ""
|
||||
if method == "POST":
|
||||
fs = cgi.FieldStorage()
|
||||
project = uuid1().hex
|
||||
projpath = os.path.join(PROJECT_PATH, project)
|
||||
try:
|
||||
copytree(SAMPLE_PROJECT_PATH, projpath)
|
||||
proj = Project(project, create=True)
|
||||
redirect("{0}?{1}".format(EDITOR_URL, urlencode({'p': proj.path})))
|
||||
sys.exit(0)
|
||||
except OSError, e:
|
||||
errormsg = """An error occurred, check your project name (try without using special characters)<br>\n<div class="error">({0})</div>""".format(e)
|
||||
|
||||
projects = []
|
||||
for p in os.listdir(PROJECT_PATH):
|
||||
fp = os.path.join(PROJECT_PATH, p)
|
||||
if os.path.isdir(fp) and not p.startswith("."):
|
||||
projects.append(Project(p))
|
||||
projects.sort(key=operator.attrgetter("path"))
|
||||
|
||||
|
||||
print "Content-type:text/html;charset=utf-8"
|
||||
print
|
||||
print """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hybrid Publishing Editor</title>
|
||||
<link rel="stylesheet" type="text/css" href="/editor.css">
|
||||
</head>
|
||||
<body style="margin: 2em">
|
||||
<h1>Hybrid Publishing Editor</h1>
|
||||
"""
|
||||
if len(errormsg):
|
||||
print """<p class="error">{0}</p>""".format(errormsg).encode("utf-8")
|
||||
print """
|
||||
<p>Click the start project button below to start a new project.</p>
|
||||
<form method="post">
|
||||
<input type="submit" value="create" />
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
"""
|
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import cgitb; cgitb.enable()
|
||||
import os, sys, cgi, json
|
||||
from subprocess import PIPE, Popen
|
||||
from settings import PROJECT_PATH, PROJECT_URL, EDITOR_URL, MAKE
|
||||
from project import Project
|
||||
from time import sleep
|
||||
|
||||
method = os.environ.get("REQUEST_METHOD", "")
|
||||
fs = cgi.FieldStorage()
|
||||
project = fs.getvalue("p", "")
|
||||
paths = fs.getlist("f[]")
|
||||
|
||||
ret = {}
|
||||
passes = 0
|
||||
fails = 0
|
||||
|
||||
proj = Project(project)
|
||||
if len(paths) == 0:
|
||||
count = 1
|
||||
newname = "untitled_file.md"
|
||||
fp = os.path.join(proj.fullpath, newname)
|
||||
while os.path.exists(fp):
|
||||
count += 1
|
||||
newname = "untitled_file_{0}.md".format(count)
|
||||
fp = os.path.join(proj.fullpath, newname)
|
||||
sleep(0.001)
|
||||
|
||||
args = ["touch", fp]
|
||||
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=proj.fullpath)
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode == 0:
|
||||
passes += 1
|
||||
else:
|
||||
fails += 1
|
||||
else:
|
||||
for p in paths:
|
||||
fp = os.path.join(proj.fullpath, p)
|
||||
|
||||
# print >> sys.stderr, "*** rm", fp
|
||||
try:
|
||||
args = ["touch", fp]
|
||||
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=proj.fullpath)
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode == 0:
|
||||
passes += 1
|
||||
else:
|
||||
fails += 1
|
||||
except OSError, e:
|
||||
fails += 1
|
||||
|
||||
ret['passes'] = passes
|
||||
ret['fails'] = fails
|
||||
|
||||
print "Content-type: application/json"
|
||||
print
|
||||
print json.dumps(ret)
|
Loading…
Reference in New Issue