Add functions to trace_processor_http corresponding to various HTTP API endpoints.

Add functions corresponding to the /notify_eof, /status, and /parse endpoints available in the HTTP API of trace_processor.

Change-Id: I204a23cfe258ec9e26dcdcf20067a0c2782ed2a4
diff --git a/src/trace_processor/python/api_main.py b/src/trace_processor/python/api_main.py
index cdab397..b4be75d 100644
--- a/src/trace_processor/python/api_main.py
+++ b/src/trace_processor/python/api_main.py
@@ -13,11 +13,28 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import argparse
+
 from trace_processor_http import TraceProcessorHttp
 
 
 def main():
-  tp = TraceProcessorHttp()
+  # Parse arguments passed from command line
+  args = parser.parse_args()
+  parser = argparse.ArgumentParser()
+  parser.add_argument(
+      "-a",
+      "--address",
+      help="Address at which trace_processor is being run, e.g. 127.0.0.1:9001",
+      type=str)
+  parser.add_argument("-f", "--file", help="Absolute path to trace", type=str)
+
+  # TODO(@aninditaghosh): Load trace into trace_processor_shell
+
+  # Call functions on the loaded trace
+  tp = TraceProcessorHttp(args.address)
+  tp.notify_eof()
+  print(tp.status())
 
 
 if __name__ == "__main__":
diff --git a/src/trace_processor/python/trace_processor_http.py b/src/trace_processor/python/trace_processor_http.py
index 510d1f8..fbe1f85 100644
--- a/src/trace_processor/python/trace_processor_http.py
+++ b/src/trace_processor/python/trace_processor_http.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (C) 2020 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +13,25 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from urllib import request
+
 
 class TraceProcessorHttp:
 
-  def __init__(self):
-    pass
+  def __init__(self, url):
+    self.url = 'http://' + url
+
+  def parse(self, chunk):
+    req = request.Request(self.url + '/parse', data=chunk)
+    with request.urlopen(req) as f:
+      return f.read()
+
+  def notify_eof(self):
+    req = request.Request(self.url + '/notify_eof')
+    with request.urlopen(req) as f:
+      return f.read()
+
+  def status(self):
+    req = request.Request(self.url + '/status')
+    with request.urlopen(req) as f:
+      return f.read()