def connect_file(self, message): path = message.content.path query = message.content.query newfile = True if query == "new" else False try: data_json = open_file_as_json(path, query) except EnvironmentError: raise tornado.web.HTTPError(404) my_format = fmt.define_format(data_json) formatter = fmt.FileFormatter(my_format, data=data_json, newfile=newfile) # TODO: figure out this line self.save_formatter(formatter) return formatter.get_data(), "connected"
def get(self, uri: str): lpath = local_path(urlparse(uri).path) self.set_header("Content-Type", "application/json") newfile = False if os.path.isdir(lpath): # intent is to make completely new file from default template lpath = path_to_template() newfile = True try: with open(lpath) as data_file: # TODO read data. convert raw data to {nodes, links, tabs, metadata} dict # TODO formatter will know what to do data_json = json.load(data_file) format = fmt.define_format(data_json) formatter = fmt.FileFormatter(format, data=data_json, newfile=newfile) self.write(json.dumps(formatter.get_data())) self.save_formatter(formatter) # self.write(data_file.read()) except EnvironmentError: raise tornado.web.HTTPError(404)