From dce6100348f92663f855b3c791031fd5a991844a Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Mon, 26 Oct 2015 19:51:54 +0100 Subject: Remove old Appengine application. --- extras/appengine/sqlformat/__init__.py | 19 --- extras/appengine/sqlformat/legacy.py | 166 --------------------- extras/appengine/sqlformat/templates/about.html | 46 ------ extras/appengine/sqlformat/templates/api.html | 66 -------- extras/appengine/sqlformat/templates/index.html | 120 --------------- extras/appengine/sqlformat/templates/master.html | 103 ------------- .../sqlformat/templates/python-client-example.html | 17 --- extras/appengine/sqlformat/templates/source.html | 60 -------- 8 files changed, 597 deletions(-) delete mode 100644 extras/appengine/sqlformat/__init__.py delete mode 100644 extras/appengine/sqlformat/legacy.py delete mode 100644 extras/appengine/sqlformat/templates/about.html delete mode 100644 extras/appengine/sqlformat/templates/api.html delete mode 100644 extras/appengine/sqlformat/templates/index.html delete mode 100644 extras/appengine/sqlformat/templates/master.html delete mode 100644 extras/appengine/sqlformat/templates/python-client-example.html delete mode 100644 extras/appengine/sqlformat/templates/source.html (limited to 'extras/appengine/sqlformat') diff --git a/extras/appengine/sqlformat/__init__.py b/extras/appengine/sqlformat/__init__.py deleted file mode 100644 index 11f4d9d..0000000 --- a/extras/appengine/sqlformat/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -from flask import Flask, make_response - -from sqlformat.legacy import legacy - - -app = Flask('sqlformat') - - -@app.route('/ping') -def ping(): - return make_response('pong') - -@app.route('/_ah/warmup') -def warmup(): - return make_response('polishing chrome') - - -# Register legacy URLs last so that newer URLs replace them. -app.register_blueprint(legacy) diff --git a/extras/appengine/sqlformat/legacy.py b/extras/appengine/sqlformat/legacy.py deleted file mode 100644 index 7f6c161..0000000 --- a/extras/appengine/sqlformat/legacy.py +++ /dev/null @@ -1,166 +0,0 @@ -"""Legacy URLs.""" - -# This module reflects the URLs and behavior of the former Django -# application. - -import logging -import os -import time - -from google.appengine.api import memcache - -from flask import Blueprint, make_response, render_template, Response, request - -from pygments import highlight -from pygments.formatters import HtmlFormatter -from pygments.lexers import SqlLexer, PythonLexer, PhpLexer - -import simplejson as json - -import sqlparse - - -legacy = Blueprint('', 'legacy') - - -EXAMPLES_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../examples')) - - -@legacy.route('/', methods=['POST', 'GET']) -def index(): - data = {'examples': _get_examples()} - extra = {'highlight': True, 'comments': False, - 'keywords': 'upper', 'idcase': '', - 'n_indents': '2', - 'lang': 'sql'} - sql_orig = 'select * from foo join bar on val1 = val2 where id = 123;' - if request.method == 'POST': - oformat = request.form.get('format', 'html') - extra['highlight'] = 'highlight' in request.form - extra['comments'] = 'remove_comments' in request.form - extra['keywords'] = request.form.get('keyword_case', '') - extra['idcase'] = request.form.get('identifier_case', '') - extra['n_indents'] = request.form.get('n_indents', '2') - extra['lang'] = request.form.get('output_format', 'sql') - sql = _get_sql(request.form, request.files) - sql_orig = sql - start = time.time() - data['output'] = _format_sql(sql, request.form, format=oformat) - data['proc_time'] = '%.3f' % (time.time()-start) - if oformat == 'json': - data['errors'] = '' - return make_response(Response(json.dumps(data), - content_type='text/x-json')) - elif oformat == 'text': - return make_response(Response(data['output'], content_type='text/plain')) - data['sql_orig'] = sql_orig - data['extra'] = extra - return render_template('index.html', **data) - - -@legacy.route('/source/') -def source(): - return render_template('source.html') - - -@legacy.route('/about/') -def about(): - return render_template('about.html') - -@legacy.route('/api/') -def api(): - return render_template('api.html') - - -@legacy.route('/format/', methods=['GET', 'POST']) -@legacy.route('/format', methods=['GET', 'POST']) -def format_(): - if request.method == 'POST': - sql = _get_sql(request.form, request.files) - data = request.form - else: - sql = _get_sql(request.args) - data = request.args - formatted = _format_sql(sql, data, format='text') - return make_response(Response(formatted, content_type='text/plain')) - - -@legacy.route('/load_example', methods=['GET', 'POST']) -def load_example(): - fname = request.form.get('fname') - if fname is None: - answer = 'Uups, I\'ve got no filename...' - elif fname not in _get_examples(): - answer = 'Hmm, I think you don\'t want to do that.' - else: - answer = open(os.path.join(EXAMPLES_DIR, fname)).read() - data = json.dumps({'answer': answer}) - return make_response(Response(data, content_type='text/x-json')) - - -def _get_examples(): - examples = memcache.get('legacy_examples') - if examples is None: - examples = os.listdir(EXAMPLES_DIR) - memcache.set('legacy_examples', examples) - return examples - - -def _get_sql(data, files=None): - sql = None - if files is not None and 'datafile' in files: - raw = files['datafile'].read() - try: - sql = raw.decode('utf-8') - except UnicodeDecodeError, err: - logging.error(err) - logging.debug(repr(raw)) - sql = (u'-- UnicodeDecodeError: %s\n' - u'-- Please make sure to upload UTF-8 encoded data for now.\n' - u'-- If you want to help improving this part of the application\n' - u'-- please file a bug with some demo data at:\n' - u'-- http://code.google.com/p/python-sqlparse/issues/entry\n' - u'-- Thanks!\n' % err) - if not sql: - sql = data.get('data') - return sql or '' - - -def _format_sql(sql, data, format='html'): - popts = {} - if data.get('remove_comments'): - popts['strip_comments'] = True - if data.get('keyword_case', 'undefined') not in ('undefined', ''): - popts['keyword_case'] = data.get('keyword_case') - if data.get('identifier_case', 'undefined') not in ('undefined', ''): - popts['identifier_case'] = data.get('identifier_case') - if data.get('n_indents', None) is not None: - val = data.get('n_indents') - try: - popts['indent_width'] = max(1, min(1000, int(val))) - popts['reindent'] = True - except (ValueError, TypeError): - pass - if (not 'indent_width' in popts and - data.get('reindent', '').lower() in ('1', 'true', 't')): - popts['indent_width'] = 2 - popts['reindent'] = True - if data.get('output_format', None) is not None: - popts['output_format'] = data.get('output_format') - logging.debug('Format: %s, POPTS: %r', format, popts) - logging.debug(sql) - sql = sqlparse.format(sql, **popts) - if format in ('html', 'json'): - if data.get('highlight', False): - if popts['output_format'] == 'python': - lexer = PythonLexer() - elif popts['output_format'] == 'php': - lexer = PhpLexer() - else: - lexer = SqlLexer() - sql = highlight(sql, lexer, HtmlFormatter()) - else: - sql = ('' - % sql) - return sql diff --git a/extras/appengine/sqlformat/templates/about.html b/extras/appengine/sqlformat/templates/about.html deleted file mode 100644 index 2d4e03e..0000000 --- a/extras/appengine/sqlformat/templates/about.html +++ /dev/null @@ -1,46 +0,0 @@ -{% extends "master.html" %} - -{% block title %}About{% endblock %} - -{% block main %} -

About this Application

-

- This application is a online SQL formatting tool. -

-

- Basically it's a playground for a Python module to parse and format - SQL statements. Sometimes it's easier to combine the available - options and to see the resulting output using a web front-end than - on the command line ;-) -

-

- To get started, enter a SQL statement in the text box on the top, - choose some options and click on "Format SQL" (Ctrl+F) - to see the result. -

-

- Note: The SQL formatter and parser is in an early stage - of development. If you're looking for a mature tool, try one of - these. -

-

Using it from the Command Line

-

- There are three ways to use this SQL formatter from the command line: -

-
    -
  1. Grab the sources and use the module in your - Python scripts.
  2. -
  3. - Write a little script in your favorite language that sends a POST - request to this application.
    - Read the API Documentation for more information. -
  4. -
  5. Use - Lynx - -
  6. -
- -{% endblock %} diff --git a/extras/appengine/sqlformat/templates/api.html b/extras/appengine/sqlformat/templates/api.html deleted file mode 100644 index 2b32cbb..0000000 --- a/extras/appengine/sqlformat/templates/api.html +++ /dev/null @@ -1,66 +0,0 @@ -{% extends "master.html" %} - -{% block title %}API{% endblock %} - -{% block main %} -

API Documentation

- -

- Using the API for this application is pretty simple. Just send a - request to -

-

- http://sqlformat.appspot.com/format/ -

- -

Options

-

- The server accepts various options to control formatting. Only - the data option is required. All others are optional.
- Either use GET and pack the options in the query string - or POST and submit your parameters as form data.
- When using POST make sure your request includes a - Content-Type: application/x-www-form-urlencoded header. -

- -
-
data
-
The SQL statement to format.
-
remove_comments
-
Set to 1 to remove comments.
-
keyword_case
-
How to convert keywords. Allowed values are 'lower', 'upper', - 'capitalize'.
-
identifier_case
-
How to convert identifiers. Allowed values are 'lower', 'upper', - 'capitalize'.
-
n_indents
-
An integer indicating the indendation depth.
-
right_margin
-
An integer indicating the maximum line length.
-
output_format
-
Transfer the statement into another programming language. - Allowed values are 'python', 'php'
-
- -

Example

-

- Here's a example in Python: -

-{% include "python-client-example.html" %} -

- Download sqlformat_example_client.py -

- -

- And another example using curl and a GET request: -

-
-$ curl "http://sqlformat.appspot.com/format?keyword_case=upper&reindent=true&data=select%20*%20from%20foo;"
-SELECT *
-FROM foo;
-$
-
- - -{% endblock %} diff --git a/extras/appengine/sqlformat/templates/index.html b/extras/appengine/sqlformat/templates/index.html deleted file mode 100644 index 22d6fdb..0000000 --- a/extras/appengine/sqlformat/templates/index.html +++ /dev/null @@ -1,120 +0,0 @@ -{% extends "master.html" %} - -{% block main %} - -{% if output %} - -{% endif %} - -
-
-
- Type your SQL here:
- -
-
- ...or upload a file: - -
-
-
- -
- {% if output %} -
{{output|safe}}
- {% else %} -
- {% endif %} -
- {% if proc_time %}Processed in {{proc_time}} seconds.{% endif %} -
-
- - -
- -
-
-

Options

-
General Options -
- - -
- - -
-
-
- Keywords & Identifiers -
- Keywords: -
-
- Identifiers: -
-
-
Indentation & Margins - -
- - spaces -
Empty field means leave indentation unchanged.
-
-
-
Output Format - - -
- -
This software is in development.
- -
- - - Flattr this - -
-
- -
-
-
-
- - -{% endblock %} - diff --git a/extras/appengine/sqlformat/templates/master.html b/extras/appengine/sqlformat/templates/master.html deleted file mode 100644 index 88a9d36..0000000 --- a/extras/appengine/sqlformat/templates/master.html +++ /dev/null @@ -1,103 +0,0 @@ - - - {% block title %}SQLFormat - Online SQL Formatter{% endblock %} - - - - - - - - - - - -
-

Keyboard Shortcuts

-

- H - Show / hide this help window
- Ctrl+F - Format SQL and display result
- O - Show / hide options
- T - Set focus on SQL input
-

-
- - - -
-
- {% block main %}MAIN CONTENT GOES HERE{% endblock %} -
-
- - - - - - - - - - diff --git a/extras/appengine/sqlformat/templates/python-client-example.html b/extras/appengine/sqlformat/templates/python-client-example.html deleted file mode 100644 index 68bf820..0000000 --- a/extras/appengine/sqlformat/templates/python-client-example.html +++ /dev/null @@ -1,17 +0,0 @@ -
#!/usr/bin/env python
-
-import urllib
-import urllib2
-
-payload = (
-    ('data', 'select * from foo join bar on val1 = val2 where id = 123;'),
-    ('format', 'text'),
-    ('keyword_case', 'upper'),
-    ('reindent', True),
-    ('n_indents', 2),
-    )
-
-response = urllib2.urlopen('http://sqlformat.appspot.com/format/',
-                           urllib.urlencode(payload))
-print response.read()
-
diff --git a/extras/appengine/sqlformat/templates/source.html b/extras/appengine/sqlformat/templates/source.html deleted file mode 100644 index a0ed89d..0000000 --- a/extras/appengine/sqlformat/templates/source.html +++ /dev/null @@ -1,60 +0,0 @@ -{% extends "master.html" %} - -{% block title %}Source code{% endblock %} - -{% block main %} -
-

Source Code

- -

Python Module

-

- The sources for the SQL parser and formatter module are - hosted on Google Code. - To clone the repository run: -

- hg clone http://python-sqlparse.googlecode.com/hg/ python-sqlparse -

-

- Visit the project page - | - Browse the sources online - | - API Documentation -

-

- Some relevant parts of the Python module contain code from the - pygments syntax highlighter. - The underlying Python module uses a non-validating SQL parser. - This approach makes it possible to parse even syntactically incorrect - SQL statements. -

- -

- Currently the parser module is used by - CrunchyFrog - a - database front-end for Gnome. -

- -

- The sqlparse module is released under the terms of the - New BSD License. -

- -

App Engine Application

-

- The source code for this App Engine application is available in the - examples directory of the Python module - (but it's really nothing special ;-). -

- -

Contributing

-

- Please file bug reports and feature requests on the project site at - http://code.google.com/p/python-sqlparse/issues/entry - or if you have code to contribute upload it to - http://codereview.appspot.com - and add albrecht.andi@googlemail.com as reviewer. -

- -
-{% endblock %} -- cgit v1.2.1