def post(self): project_name = self.get_argument("project_name", "").strip() LOG.debug("project_name: %s", project_name) projects = Projects() data = {} data["nodes"] = [] data["tree"] = [] data["project"] = project_name nodes = [] project = Project() project.parse_dict(projects.get(project_name)) data["project_path"] = project.project_path data["main_path"] = project.main_path data["go_path"] = project.go_path dirs, files = project.listdir() if dirs != [] or files != []: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "directory"} else: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "file"} for d in dirs: nodes.append({"id": os.path.join(project.project_path, d["name"]), "parent": project.project_path, "text": d["name"].replace("<", "<").replace(">", ">"), "type": "directory"}) for f in files: nodes.append({"id": os.path.join(project.project_path, f["name"]), "parent": project.project_path, "text": f["name"].replace("<", "<").replace(">", ">"), "type": "file"}) nodes.insert(0, parent) data["nodes"] = nodes self.write(data)
def post(self): query_str = self.get_argument("query", "[]").strip() query = json.loads(query_str) project_name = self.get_argument("project_name", "").strip() LOG.debug("query: %s, project_name: %s", query, project_name) nodes = [] tree = [] projects = Projects() if project_name != "" and projects.get(project_name): project = Project() project.parse_dict(projects.get(project_name)) for q_id in query: dirs, files = project.listdir(q_id) if dirs != [] or files != []: tree.append({"id": q_id}) for d in dirs: nodes.append({"id": os.path.join(q_id, d["name"]), "parent": q_id, "text": d["name"].replace("<", "<").replace(">", ">"), "type": "directory"}) for f in files: nodes.append({"id": os.path.join(q_id, f["name"]), "parent": q_id, "text": f["name"].replace("<", "<").replace(">", ">"), "type": "file"}) data = {} data["nodes"] = nodes data["tree"] = tree self.write(data)
def post(self): data = {} try: project_name = self.get_argument("project_name", "").strip() LOG.debug("reindex project: project_name %s", project_name) data["project"] = project_name projects = Projects() if project_name != "": project_import = ProjectImport(CONFIG["process_num"]) project = Project() project.parse_dict(projects.get(project_name)) project.hash() SEARCH_IX.delete(project_name) flag = SEARCH_IX.add(project_name) if flag: flag = yield project_import.import_project(project) if flag: LOG.info("Reindex Project[%s] Success", project_name) else: LOG.info("Reindex Project[%s] Failed", project_name) raise errors.ReindexProjectError except Exception, e: LOG.exception(e) data["exception"] = "%s" % e
def post(self): file_path = self.get_argument("file_path", "").strip() query = self.get_argument("q", "").strip() line = self.get_argument("line", "0").strip() ch = self.get_argument("ch", "0").strip() project_name = self.get_argument("project_name", "").strip() line = int(line) ch = int(ch) LOG.debug("project_name: %s, q: %s, line: %s, ch: %s", project_name, query, line, ch) projects = Projects() data = {} data["project"] = project_name data["file_path"] = "" data["desc"] = "" project = Project() project.parse_dict(projects.get(project_name)) os.environ["GOPATH"] = project.go_path LOG.debug("GOPATH: %s", project.go_path) r = get_definition_from_guru(file_path, line, ch) if r: if r.has_key("definition") and r["definition"].has_key("objpos"): data["file_path"] = r["definition"]["objpos"] elif r.has_key("objpos"): data["file_path"] = r["objpos"] else: data["file_path"] = "" data["desc"] = r["definition"]["desc"] if r.has_key("definition") and r["definition"].has_key("desc") else "" LOG.debug("GoToDefinition: %s", data) self.write(data)
def get(self): projects = Projects() data = {} data["nodes"] = [] data["tree"] = [] data["projects"] = [v for v in projects.all().itervalues()] data["projects"].sort(lambda x,y : cmp(x['project_name'], y['project_name'])) if len(data["projects"]) > 0: nodes = [] data["project"] = data["projects"][0]["project_name"] project = Project() project.parse_dict(data["projects"][0]) data["project_path"] = project.project_path data["main_path"] = project.main_path data["go_path"] = project.go_path dirs, files = project.listdir() if dirs != [] or files != []: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "directory"} else: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "file"} for d in dirs: nodes.append({"id": os.path.join(project.project_path, d["name"]), "parent": project.project_path, "text": escape_html(d["name"]), "type": "directory"}) for f in files: nodes.append({"id": os.path.join(project.project_path, f["name"]), "parent": project.project_path, "text": escape_html(f["name"]), "type": "file"}) nodes.insert(0, parent) data["nodes"] = nodes self.render("call/call_tree.html", current_nav = "View", version = CONFIG["version"], result = json.dumps(data))
def post(self): data = {} try: project_name = self.get_argument("project_name", "").strip() LOG.debug("project_name: %s", project_name) projects = Projects() data["nodes"] = [] data["tree"] = [] data["project"] = "" projects.delete(project_name) data["projects"] = [v for v in projects.all().itervalues()] data["projects"].sort(lambda x,y : cmp(x['project_name'], y['project_name'])) if len(data["projects"]) > 0: nodes = [] data["project"] = data["projects"][0]["project_name"] project = Project() project.parse_dict(data["projects"][0]) data["project_path"] = project.project_path data["main_path"] = project.main_path data["go_path"] = project.go_path dirs, files = project.listdir() if dirs != [] or files != []: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "directory"} else: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "file"} for d in dirs: nodes.append({"id": os.path.join(project.project_path, d["name"]), "parent": project.project_path, "text": d["name"].replace("<", "<").replace(">", ">"), "type": "directory"}) for f in files: nodes.append({"id": os.path.join(project.project_path, f["name"]), "parent": project.project_path, "text": f["name"].replace("<", "<").replace(">", ">"), "type": "file"}) nodes.insert(0, parent) data["nodes"] = nodes except Exception, e: LOG.exception(e) data["exception"] = "%s" % e
def post(self): file_path = self.get_argument("file_path", "").strip() query = self.get_argument("q", "").strip() line = self.get_argument("line", "0").strip() ch = self.get_argument("ch", "0").strip() project_name = self.get_argument("project_name", "").strip() line = int(line) ch = int(ch) LOG.debug("project_name: %s, q: %s, line: %s, ch: %s", project_name, query, line, ch) projects = Projects() data = {} data["project"] = project_name data["file_path"] = "" data["desc"] = "" data["refs"] = [] project = Project() project.parse_dict(projects.get(project_name)) os.environ["GOPATH"] = project.go_path LOG.debug("GOPATH: %s", project.go_path) r = get_referrers_from_guru(file_path, line, ch) if isinstance(r, list): data["file_path"] = r[0]["objpos"] if len(r) > 0 and r[0].has_key("objpos") else "" data["desc"] = r[0]["desc"] if len(r) > 0 and r[0].has_key("desc") else "" data["refs"] = [] if len(r) > 1: for package in r[1:]: if package.has_key("refs"): for ref in package["refs"]: if ref.has_key("pos"): data["refs"].append(ref["pos"]) elif isinstance(r, dict): data["file_path"] = r["referrers"]["objpos"] if r.has_key("referrers") and r["referrers"].has_key("objpos") else "" data["desc"] = r["referrers"]["desc"] if r.has_key("referrers") and r["referrers"].has_key("desc") else "" data["refs"] = r["referrers"]["refs"] if r.has_key("referrers") and r["referrers"].has_key("refs") else [] LOG.debug("FindReferrers: %s", data) self.write(data)
def post(self): data = {} try: project_name = self.get_argument("project_name", "").strip() project_path = self.get_argument("project_path", "").strip() project_path = project_path.rstrip("/") if project_path != "/" else "/" go_path = self.get_argument("go_path", "").strip() go_path = go_path.rstrip("/") if go_path != "/" else "/" main_path = self.get_argument("main_path", "").strip() LOG.debug("add project: project_name %s, project_path: %s, go_path: %s, main_path: %s", project_name, project_path, go_path, main_path) if not validate_params(project_name, project_path, go_path, main_path): raise errors.InvalidParamsError data["nodes"] = [] data["tree"] = [] data["project"] = "" projects = Projects() if project_name != "" and projects.exist(project_name): raise errors.ExistProjectError elif project_name != "" and not projects.exist(project_name): project = Project() project.go_path = go_path project.main_path = main_path project.project_path = project_path project.project_name = project_name project.hash() flag = projects.add(project) data["projects"] = [v for v in projects.all().itervalues()] data["projects"].sort(lambda x,y : cmp(x['project_name'], y['project_name'])) if flag: project_import = ProjectImport(CONFIG["process_num"]) data["project"] = project_name nodes = [] project = Project() project.parse_dict(projects.get(project_name)) project.hash() data["project_path"] = project.project_path data["main_path"] = project.main_path data["go_path"] = project.go_path SEARCH_IX.delete(project_name) flag = SEARCH_IX.add(project_name) if flag: flag = yield project_import.import_project(project) if flag: LOG.info("Add Project[%s] Success", project_name) else: LOG.info("Add Project[%s] Failed", project_name) flag = projects.delete(project.project_name) if flag: LOG.info("Delete Project[%s] (by add project failed) Success", project_name) else: LOG.error("Delete Project[%s] (by add project failed) Failed", project_name) raise errors.AddProjectError dirs, files = project.listdir() if dirs != [] or files != []: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "directory"} else: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "file"} for d in dirs: nodes.append({"id": os.path.join(project.project_path, d["name"]), "parent": project.project_path, "text": d["name"].replace("<", "<").replace(">", ">"), "type": "directory"}) for f in files: nodes.append({"id": os.path.join(project.project_path, f["name"]), "parent": project.project_path, "text": f["name"].replace("<", "<").replace(">", ">"), "type": "file"}) nodes.insert(0, parent) data["nodes"] = nodes elif len(data["projects"]) > 0: nodes = [] data["project"] = data["projects"][0]["project_name"] project = Project() project.parse_dict(data["projects"][0]) data["project_path"] = project.project_path data["main_path"] = project.main_path data["go_path"] = project.go_path dirs, files = project.listdir() if dirs != [] or files != []: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "directory"} else: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "file"} for d in dirs: nodes.append({"id": os.path.join(project.project_path, d["name"]), "parent": project.project_path, "text": d["name"].replace("<", "<").replace(">", ">"), "type": "directory"}) for f in files: nodes.append({"id": os.path.join(project.project_path, f["name"]), "parent": project.project_path, "text": f["name"].replace("<", "<").replace(">", ">"), "type": "file"}) nodes.insert(0, parent) data["nodes"] = nodes else: data["projects"] = [v for v in projects.all().itervalues()] data["projects"].sort(lambda x,y : cmp(x['project_name'], y['project_name'])) nodes = [] data["project"] = data["projects"][0]["project_name"] project = Project() project.parse_dict(data["projects"][0]) data["project_path"] = project.project_path data["main_path"] = project.main_path data["go_path"] = project.go_path dirs, files = project.listdir() if dirs != [] or files != []: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "directory"} else: parent = {"id": project.project_path, "parent": "#", "text": os.path.split(project.project_path)[-1], "type": "file"} for d in dirs: nodes.append({"id": os.path.join(project.project_path, d["name"]), "parent": project.project_path, "text": d["name"].replace("<", "<").replace(">", ">"), "type": "directory"}) for f in files: nodes.append({"id": os.path.join(project.project_path, f["name"]), "parent": project.project_path, "text": f["name"].replace("<", "<").replace(">", ">"), "type": "file"}) nodes.insert(0, parent) data["nodes"] = nodes except Exception, e: LOG.exception(e) data["exception"] = "%s" % e