summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Gordon <assafgordon@gmail.com>2014-08-20 03:13:31 (GMT)
committerA. Gordon <assafgordon@gmail.com>2014-08-20 03:13:31 (GMT)
commitb822ea928e33f80bcef726351cfe5ad4b76b80be (patch)
tree98e8c4a3ac1c0f20779d9545785c2f738077cd0f
parentb128a68c38f5bd1d6276a031b941ed1e8c034255 (diff)
downloadgsv-eval-b822ea928e33f80bcef726351cfe5ad4b76b80be.zip
gsv-eval-b822ea928e33f80bcef726351cfe5ad4b76b80be.tar.gz
gsv-eval-b822ea928e33f80bcef726351cfe5ad4b76b80be.tar.bz2
website test
-rwxr-xr-xwebsite/gnu_eval_flask.py92
-rw-r--r--website/gnu_eval_worker.py52
-rw-r--r--website/templates/home.html32
-rw-r--r--website/templates/not_ready.html12
4 files changed, 188 insertions, 0 deletions
diff --git a/website/gnu_eval_flask.py b/website/gnu_eval_flask.py
new file mode 100755
index 0000000..b682559
--- /dev/null
+++ b/website/gnu_eval_flask.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2014 Assaf Gordon <assafgordon@gmail.com>
+#
+# This file is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file. If not, see <http://www.gnu.org/licenses/>.
+#
+# Written by Assaf Gordon
+
+from flask import Flask, url_for, request, redirect, jsonify, render_template, make_response, send_file
+from werkzeug import secure_filename
+import string
+import datetime
+import random
+import json
+import requests
+import re
+import sys
+import os
+import csv
+import datetime
+import httplib
+from redis import Redis
+from subprocess import Popen,PIPE
+from rq import Queue
+
+from gnu_eval_worker import do_gnu_eval
+
+app = Flask(__name__)
+app.debug = True
+
+redis_connection=Redis()
+q = Queue(connection=redis_connection)
+
+results_dir = "/tmp/"
+
+@app.route("/")
+def splash():
+ return render_template("home.html")
+
+@app.route("/eval", methods=['POST'])
+def eval():
+ if not 'project_name' in request.form:
+ return "Error: missing project name"
+ project_name = request.form['project_name'].strip()
+ project_name = re.sub(r"[^A-Za-z0-9\.\-\_]","",project_name);
+
+ if not 'source_url' in request.form:
+ return "Error: missing source URL"
+ source_url = request.form['source_url'].strip()
+
+ tarball_url_re = re.compile ('^(http|ftp|https)://[A-Za-z0-9\-]+\.[A-Za-z0-9\.]+/[A-Za-z0-9\/\-\_\.]+(\.tar\.(gz|bz2|xz)|\.git)$')
+ git_url_re = re.compile('^git://[A-Za-z0-9\-]+\.[A-Za-z0-9\.]+/[A-Za-z0-9\/\-\_\.]+$');
+ if not tarball_url_re.match(source_url) and not git_url_re.match(source_url):
+ return "Error: Source URL (%s) does not match allowed patternas. Only simple URLs are allowed (no CGI parameters)" % (source_url)
+
+ job_id = redis_connection.incr("gnu_eval_job_num");
+ job = q.enqueue(do_gnu_eval, job_id, results_dir, project_name, source_url)
+
+ link = url_for('show',jobid=job_id)
+ return redirect(link)
+
+@app.route('/show/<jobid>')
+def show(jobid):
+ try:
+ jobid = int(jobid)
+ except:
+ return "error: invalid ID"
+
+ max_job = redis_connection.get("gnu_eval_job_num");
+ print "max_job = %s, job_id = %s\n" % ( max_job, jobid)
+ if int(jobid) > int(max_job):
+ return "error: no such job"
+
+ result_file = results_dir + "/" + str(jobid) + ".html"
+ if not os.path.isfile(result_file) or os.path.getsize(result_file)==0:
+ return render_template('not_ready.html')
+
+ return send_file(result_file)
+
+if __name__ == "__main__":
+ app.run(host='0.0.0.0',port=5106)
diff --git a/website/gnu_eval_worker.py b/website/gnu_eval_worker.py
new file mode 100644
index 0000000..8092310
--- /dev/null
+++ b/website/gnu_eval_worker.py
@@ -0,0 +1,52 @@
+# Copyright (C) 2014 Assaf Gordon <assafgordon@gmail.com>
+#
+# This file is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file. If not, see <http://www.gnu.org/licenses/>.
+#
+# Written by Assaf Gordon
+
+import re
+from subprocess import Popen, PIPE
+import os
+import pprint
+
+def do_gnu_eval(idnum,output_dir,project_name,source_url):
+ try:
+ idnum = int(idnum)
+ except ValueError:
+ return "error: invalid idnum (%s) parameter" % (idnum)
+ if not project_name:
+ project_name = "(unamed project)"
+ if not output_dir:
+ return "error: output directory is empty"
+ if not os.path.isdir(output_dir):
+ return "error: output directory (%s) is not a valid directory" % (output_dir)
+ p = re.compile ('^(http|ftp|https|git)://[A-Za-z0-9\-]+\.[A-Za-z0-9\.]+/')
+ if not p.match(source_url):
+ return "error: Source URL (%s) does not match allowed pattern" % (source_url)
+
+ project_name = str(project_name)
+ source_url = str(source_url)
+ idnum = str(idnum)
+
+ eval_script = "../gnu_eval_remote.sh"
+ args = [ eval_script, output_dir, idnum, project_name, source_url ]
+
+ child = Popen(args, shell=False, stdout=PIPE, stderr=PIPE)
+ output = child.communicate();
+ pp = pprint.PrettyPrinter(indent=4)
+ exitcode = child.returncode
+ if exitcode == 0:
+ return "ok"
+ else:
+ return output[1] # stderr
diff --git a/website/templates/home.html b/website/templates/home.html
new file mode 100644
index 0000000..e67cb5c
--- /dev/null
+++ b/website/templates/home.html
@@ -0,0 +1,32 @@
+<html>
+<head>
+</head>
+<body>
+<h1>Online Free-Software Copyright and License Evalutor</h1>
+Designed for GNU Savannah proejct evaluation, but useful for general copyright and license evaluation of any project.
+<br/>
+
+<strong>THIS PROJECT IS IN ALPHA STAGE.</strong><br/>
+<br/>
+
+To review a project, enter a URL of a tarball or GIT repostory.</br>
+Example: <code>git://git.savannah.gnu.org/hello.git</code>
+<br/>
+<br/>
+NOTE:</br>
+All information will be made public for everyone to see.</br>
+<br/>
+<br/>
+
+<form method="post" action="{{ url_for("eval") }}" enctype="multipart/form-data">
+Remote Source URL (git/tarball):
+<input type=text name="source_url" size="50" />
+<br/>
+Project Name (optional):
+<input type=text name="project_name" />
+<br/>
+<input type=submit value="Go" />
+</form>
+
+</body>
+</html>
diff --git a/website/templates/not_ready.html b/website/templates/not_ready.html
new file mode 100644
index 0000000..3550515
--- /dev/null
+++ b/website/templates/not_ready.html
@@ -0,0 +1,12 @@
+<html>
+<head>
+<meta http-equiv="refresh" content="5">
+</head>
+<body>
+<h1> GNU Savannah Copyright and License Evaluation </h1>
+This job is not done yet (or hasn't even started, depending on server load).
+<br/>
+This script will reload itself in 5 seconds.
+<br/>
+</body>
+</html>