From fcbef86f3ba44aa5da7e93acc3bc613ff01be2ac Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sun, 21 Jan 2018 11:20:42 +0100 Subject: [PATCH] base diff support --- diffido.py | 40 +++++++++++++++++++++++++---- dist/base.html | 2 ++ dist/diff.html | 65 ++++++++++++++++++++++++++++++++++++++++++++++- dist/history.html | 9 +++++++ 4 files changed, 110 insertions(+), 6 deletions(-) diff --git a/diffido.py b/diffido.py index 7cee627..3734812 100755 --- a/diffido.py +++ b/diffido.py @@ -124,7 +124,27 @@ def get_history(id_): delete = 0 history.append({'id': commit_id, 'message': message, 'insertions': insert, 'deletions': delete, 'changes': max(insert, delete)}) - return history + lastid = None + if history and 'id' in history[0]: + lastid = history[0]['id'] + for idx, item in enumerate(history): + item['seq'] = idx + 1 + return {'history': history, 'lastid': lastid} + + +def get_diff(id_, diff, oldid=None): + def _history(id_, diff, oldid, queue): + os.chdir('storage/%s' % id_) + p = subprocess.Popen([GIT_CMD, 'diff', diff, oldid or '%s~' % diff], stdout=subprocess.PIPE) + stdout, _ = p.communicate() + queue.put(stdout) + queue = multiprocessing.Queue() + p = multiprocessing.Process(target=_history, args=(id_, diff, oldid, queue)) + p.start() + res = queue.get().decode('utf-8') + p.join() + return {'diff': res} + def scheduler_update(scheduler, id_): schedule = get_schedule(id_, addID=False) @@ -302,7 +322,13 @@ class ResetSchedulesHandler(BaseHandler): class HistoryHandler(BaseHandler): @gen.coroutine def get(self, id_, *args, **kwargs): - self.write({'history': get_history(id_)}) + self.write(get_history(id_)) + + +class DiffHandler(BaseHandler): + @gen.coroutine + def get(self, id_, diff, oldid=None, *args, **kwargs): + self.write(get_diff(id_, diff, oldid)) class TemplateHandler(BaseHandler): @@ -347,13 +373,17 @@ def serve(): _reset_schedules_path = r'schedules/reset' _schedules_path = r'schedules/?(?P\d+)?' _history_path = r'history/?(?P\d+)' + _diff_path = r'diff/(?P\d+)/(?P\s+)/?(?P\s+)?' + _diff_path = r'diff/(?P\d+)/(?P[0-9a-f]+)/?(?P[0-9a-f]+)?/?' application = tornado.web.Application([ - ('/api/%s' % _reset_schedules_path, ResetSchedulesHandler, init_params), + (r'/api/%s' % _reset_schedules_path, ResetSchedulesHandler, init_params), (r'/api/v%s/%s' % (API_VERSION, _reset_schedules_path), ResetSchedulesHandler, init_params), - ('/api/%s' % _schedules_path, SchedulesHandler, init_params), + (r'/api/%s' % _schedules_path, SchedulesHandler, init_params), (r'/api/v%s/%s' % (API_VERSION, _schedules_path), SchedulesHandler, init_params), - ('/api/%s' % _history_path, HistoryHandler, init_params), + (r'/api/%s' % _history_path, HistoryHandler, init_params), (r'/api/v%s/%s' % (API_VERSION, _history_path), HistoryHandler, init_params), + (r'/api/%s' % _diff_path, DiffHandler, init_params), + (r'/api/v%s/%s' % (API_VERSION, _diff_path), DiffHandler, init_params), (r'/?(.*)', TemplateHandler, init_params), ], static_path=os.path.join(os.path.dirname(__file__), 'dist/static'), diff --git a/dist/base.html b/dist/base.html index 2ba811a..dc16df2 100644 --- a/dist/base.html +++ b/dist/base.html @@ -6,10 +6,12 @@ + + {% block body %}{% end %} diff --git a/dist/diff.html b/dist/diff.html index 775ea19..9453ab0 100644 --- a/dist/diff.html +++ b/dist/diff.html @@ -1,5 +1,68 @@ {% extends "base.html" %} {% block body %} -diff page {{ id }} +
+
+
+
+
+
+
+ + + {% end %} diff --git a/dist/history.html b/dist/history.html index 86f2070..6a63bbf 100644 --- a/dist/history.html +++ b/dist/history.html @@ -9,6 +9,11 @@

History

+ + (cur | prev) + ---- + + ${ item.id } ${ item.message } @@ -26,6 +31,9 @@ var app = new Vue({ delimiters: ['${', '}'], data: { history: [], + oldid: null, + diff: null, + lasstid: null, {% if isinstance(id, str) %} id: "{{id}}", {% else %} @@ -41,6 +49,7 @@ var app = new Vue({ var data = axios.get('/api/history/' + this.id).then(function(response) { console.log(response); self.history = response.data.history; + self.lastid = response.data.lastid; }); } }