def get_contents(side): if side not in ('a', 'b'): return error('invalid side', 'Side must be "a" or "b", got %s' % side) # TODO: switch to index? might be simpler path = request.form.get('path', '') if not path: return error('incomplete', 'Incomplete request (need path)') idx = diff.find_diff_index(DIFF, side, path) if idx is None: return error('not found', 'Invalid path on side %s: %s' % (side, path)) d = DIFF[idx] abs_path = d.a_path if side == 'a' else d.b_path try: is_binary = util.is_binary_file(abs_path) if is_binary: size = os.path.getsize(abs_path) contents = "Binary file (%d bytes)" % size else: contents = open(abs_path).read() return Response(contents, mimetype='text/plain') except Exception: return error('read-error', 'Unable to read %s' % abs_path)
def get_contents(side): assert side in ('a', 'b') path = request.form.get('path', '') if not path: e = {"code": "incomplete", "message": "Incomplete request (need path)"} response = jsonify(e) response.status_code = 400 return response try: abs_path = os.path.join(A_DIR if side == 'a' else B_DIR, path) is_binary = util.is_binary_file(abs_path) if is_binary: size = os.path.getsize(abs_path) contents = "Binary file (%d bytes)" % size else: contents = open(abs_path).read() return Response(contents, mimetype='text/plain') except Exception: e = {"code": "read-error", "message": "Unable to read %s" % abs_path} response = jsonify(e) response.status_code = 400 return response