Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/studio/studio.py
diff options
context:
space:
mode:
Diffstat (limited to 'studio/studio.py')
-rw-r--r--studio/studio.py130
1 files changed, 0 insertions, 130 deletions
diff --git a/studio/studio.py b/studio/studio.py
deleted file mode 100644
index d3c9fe9..0000000
--- a/studio/studio.py
+++ /dev/null
@@ -1,130 +0,0 @@
-import os
-import sys
-from flask import Flask,request,url_for,redirect
-from flaskext.genshi import Genshi, render_response
-
-studio = Flask(__name__)
-studio.debug = True
-genshi = Genshi(studio)
-
-def shutdown_server():
- func = request.environ.get('werkzeug.server.shutdown')
- if func is None:
- raise RuntimeError('Not running with the Werkzeug Server')
- func()
-
-def list_files(directory):
- files=os.listdir(directory)
- print "showing %s" % directory
- return files
-
-def identify(filename):
- icon = 'document-generic.png'
- mode = ''
- directory=os.path.dirname(filename)
- icon = 'document-generic.png'
- href = '/edit/%s' % filename
- if filename.endswith('.py'):
- icon = 'text-x-python.png'
- mode = 'python'
- if filename.endswith('.html'):
- icon = 'text-uri-list.png'
- mode = 'html'
- if filename.endswith('.css'):
- icon = 'text-uri-list.png'
- mode = 'css'
- if filename.endswith('.js'):
- icon = 'text-uri-list.png'
- mode = 'javascript'
- if os.path.isdir(filename):
- icon = 'folder.png'
- href = '/files/%s' % filename
- mode = 'dir'
- if filename.endswith('.xo'):
- href = '#'
- return icon,mode,href
-
-@studio.route('/')
-def index():
- return vsplit()
-
-@studio.route('/edit/')
-@studio.route('/edit/<path:filename>')
-def edit(filename="activity.py"):
- icon, mode, href = identify(filename)
- content = open(filename).read().decode('utf-8')
- tmpl = 'editor.html'
- directory=os.path.dirname(filename)
- return render_response(tmpl, dict(content=content, icon=icon,basename=os.path.basename(filename),
- filename=filename, absdir=os.path.normpath(directory), mode=mode, directory=directory))
-
-@studio.route('/save', methods=['POST'])
-def save():
- filename = request.form['filename']
- f=open(filename,"wb")
- content = request.form['content']
- content = content.replace('\r\n', '\n').replace('\r', '\n') # HACK - Ace seems to be confused about newlines
- f.write(content.encode('utf-8'))
- print "saving content: %s" % filename
- f.close()
- directory = os.path.dirname(filename)
- return redirect(url_for('help'))
-
-@studio.route('/files/')
-@studio.route('/files/<path:directory>')
-def browse(directory="."):
- filelist = list_files(directory)
- files = []
- if not os.path.abspath(directory)==os.path.abspath("."):
- files.append( { 'name': '..',
- 'icon': 'folder.png',
- 'mode': 'dir',
- 'href': '/files/%s' % os.path.join(directory,"..") })
- for filename in sorted(filelist):
- icon, mode, href = identify(directory + "/" + filename)
- if filename.startswith('.'): #hidden files
- continue
- if filename.endswith('.pyc'): #lets avoid confusion
- continue
- files.append( { 'name': filename,
- 'icon': icon,
- 'mode': mode,
- 'href': href } )
- return render_response('filer.html', dict(files=files, absdir=os.path.normpath(directory)))
-
-@studio.route('/delete/<path:filename>')
-def delete(filename):
- os.unlink(filename)
- directory = os.path.dirname(filename)
- return redirect(url_for('browse', directory=directory))
-
-@studio.route('/shutdown')
-def shutdown():
- shutdown_server()
- return 'Goodbye'
-
-@studio.route('/help')
-def help():
- port = request.environ.get('SERVER_PORT')
- return render_response('help.html', dict(port=port))
-
-def vsplit(frame1='/help', frame2='/files/studio'):
- return render_response('split-view.html', dict(frame1=frame1, frame2=frame2))
-
-@studio.route('/split')
-def split():
- return vsplit()
-
-@studio.route('/debug')
-def debug():
- raise Warning("Welcome to the debugger. Note an interactive interpreter is available at each line. You may raise an exception at any time in your controller to examine its environment.")
-
-if __name__=="__main__":
- try:
- port=int(sys.argv[1])
- except IndexError:
- port=5000
- import webbrowser
- webbrowser.open("http://localhost:%s/" % port)
- studio.run(port=port) # for local only
- #studio.run(host='0.0.0.0', port=port) # open for all