def get_attributes(e): result = {} i = e while (i): key = dumps(car(i)) assert (key.startswith(":")) value = dumps(car(cdr(i))) result[key] = value i = cdr(cdr(i)) return result
def node_and_port(self, e): if dumps(e) == "__": return ["__", ""] else: node = dumps(car(e)) port = dumps(car(cdr(e))) return [node, port]
def _generate_reasoning_graph_from_sexp(self): edges = set([]) assert (dumps(car(self._sexp)) == STRING_CONSTANTS.GRAPH) graph_name_and_def = cdr(self._sexp) graph_def = cdr(graph_name_and_def) node_defs = car(graph_def) edge_defs = car(cdr(graph_def)) for e in node_defs: assert (is_node_sexp(e)) node_sexp_body = cdr(e) node = self._generate_node_from_sexp(node_sexp_body) self._nodes_dict_by_name[node.name] = node for e in edge_defs: assert (is_edge_sexp(e)) edge_sexp_body = cdr(e) self._generate_and_add_edge_from_sexp(edge_sexp_body)
def gen_entity_multi_handler(entity_dict): defargs = [] has_count = False rpc_method_name = car(entity_dict['rpc_method']).value() for arg in car(cdr(entity_dict['rpc_method'])): if type(arg) is sexpdata.Symbol: if arg.value() == '!count': has_count = True else: defargs.append(arg.value()) else: defargs.append(arg) rpc_method = with_multi_args(getattr(smoked_rpc, rpc_method_name), defargs) max_count = entity_dict['max_datums'] def handler_with_count(request): if 'count' in request.raw_args.keys(): count = int(request.raw_args['count']) if count > max_count: count = max_count else: count = max_count resp = rpc_method(count) return response.json(resp) def handler_without_count(request): resp = rpc_method() return response.json(resp) if has_count: return handler_with_count else: return handler_without_count
def enabled_probes(contents): # pylint: disable=too-many-branches probes = [] if isinstance(contents, Symbol): pass elif isinstance(contents, basestring): pass elif isinstance(contents, (int, float)): pass elif isinstance(contents, Quoted): return enabled_probes(contents.value()) elif car(contents) == Symbol('pr-update-probe'): probe_name = None probe_enabled = False for item in cdr(contents): if isinstance(item, Quoted): item = item.value() for child in item: if car(child) == 'name': probe_name = cdr(child) elif car(child) == 'enabled': probe_enabled = cdr(child) if probe_name is not None and probe_enabled and (probe_name in probes) is False: probes.append(probe_name) else: for item in contents: found_probes = enabled_probes(item) for found in found_probes: if (found in probes) is False: probes.append(found) if 'Label' in probes: probes.remove('Label') if 'NfcProbe' in probes: probes.remove('NfcProbe') return probes
def _get_type_name_src_dest_label_encoding_of_edge_from_sexp(self, e): first = car(e) second = car(cdr(e)) third = car(cdr(cdr(e))) rest = cdr(cdr(cdr(e))) edge_name = dumps(first) src_node_name, src_port_name = self.node_and_port(second) dest_node_name, dest_port_name = self.node_and_port(third) attributes = get_attributes(rest) edge_type = EdgeType.from_string( attributes[STRING_CONSTANTS.ATTRIBUTE_TYPE]) label = attributes[STRING_CONSTANTS.ATTRIBUTE_CONTENT] encoding = attributes[STRING_CONSTANTS.ATTRIBUTE_ENCODING] if src_node_name == "__": start_node_name = "start" + str(len(self._start_nodes)) src = StartNode(start_node_name, self) self._nodes_dict_by_name[start_node_name] = src dest = self._nodes_dict_by_name[dest_node_name] self._start_nodes.add(src) elif dest_node_name == "__": done_node_name = "done" + str(len(self._done_nodes)) src = self._nodes_dict_by_name[src_node_name] dest = DoneNode(done_node_name, self) self._nodes_dict_by_name[done_node_name] = dest self._done_nodes.add(dest) else: src = self._nodes_dict_by_name[src_node_name] dest = self._nodes_dict_by_name[dest_node_name] return edge_type, edge_name, src, src_port_name, dest, dest_port_name, label, encoding
def enabled_probes(contents): probes = [] if isinstance(contents, Symbol): pass elif isinstance(contents, basestring): pass elif isinstance(contents, (int, float)): pass elif isinstance(contents, Quoted): return enabled_probes(contents.value()) elif car(contents) == Symbol('pr-update-probe'): probe_name = None probe_enabled = False for item in cdr(contents): if isinstance(item, Quoted): item = item.value() for child in item: if car(child) == 'name': probe_name = cdr(child) elif car(child) == 'enabled': probe_enabled = cdr(child) if probe_name is not None and probe_enabled and (probe_name in probes) is False: probes.append(probe_name) else: for item in contents: found_probes = enabled_probes(item) for found in found_probes: if (found in probes) is False: probes.append(found) return probes
def _generate_node_from_sexp(self, e): node_name = dumps(car(e)) node_type_str = dumps(car(cdr(e))) node_type = NodeType.from_string(node_type_str) if node_type is NodeType.ENTAILMENT: result = EntailmentNode(node_name, self) elif node_type is NodeType.AND: result = AndNode(node_name, self) elif node_type is NodeType.DONE: result = DoneNode(node_name, self) elif node_type is NodeType.MODEL_CHECKING: result = ModelCheckingNode(node_name, self) elif node_type is NodeType.DELAY_ANALYSIS: result = DelayAnalysisNode(node_name, self) else: assert (False) return result
def gen_entity_single_handler(entity_dict): defargs = [] has_id = False rpc_method_name = car(entity_dict['rpc_method']).value() for arg in car(cdr(entity_dict['rpc_method'])): if type(arg) is sexpdata.Symbol: if arg.value() == '!id': has_id = True else: defargs.append(arg.value()) else: defargs.append(arg) rpc_method = with_multi_args(getattr(smoked_rpc, rpc_method_name), defargs) def handler_with_id(request, name): resp = rpc_method(name) return response.json(resp) def handler_without_id(request): resp = rpc_method() return response.json(resp) if has_id: return handler_with_id return handler_without_id
def process_data(self, pkg_db, data, common_config, config): """ Process downloaded and parsed data and generate tree. Args: pkg_db: Package database. data: Dictionary with data, keys are file names. common_config; Backend config. config: Repository config. """ archive_contents = data['archive-contents'] repo_uri = config["repo_uri"] if sexpdata.car(archive_contents) != 1: raise SyncError('sync failed: ' \ + repo_uri + ' bad archive contents format') category = 'app-emacs' pkg_db.add_category(category) common_data = {'eclasses' : ['g-sorcery', 'gs-elpa'], 'maintainer' : [{'email' : '*****@*****.**', 'name' : 'Jauhien Piatlicki'}], 'homepage' : repo_uri, 'repo_uri' : repo_uri } pkg_db.set_common_data(category, common_data) PKG_INFO = 2 PKG_NAME = 0 INFO_VERSION = 0 INFO_DEPENDENCIES = 1 INFO_DESCRIPTION = 2 INFO_SRC_TYPE = 3 DEP_NAME = 0 #DEP_VERSION = 1 #we do not use it at the moment for entry in sexpdata.cdr(archive_contents): desc = entry[PKG_INFO].value() realname = entry[PKG_NAME].value() if self.in_config([common_config, config], "exclude", realname): continue pkg = Package("app-emacs", realname, '.'.join(map(str, desc[INFO_VERSION]))) source_type = desc[INFO_SRC_TYPE].value() allowed_ords = set(range(ord('a'), ord('z'))) \ | set(range(ord('A'), ord('Z'))) | \ set(range(ord('0'), ord('9'))) | set(list(map(ord, ['+', '_', '-', ' ', '.', '(', ')', '[', ']', '{', '}', ',']))) description = "".join([x for x in desc[INFO_DESCRIPTION] if ord(x) in allowed_ords]) deps = desc[INFO_DEPENDENCIES] #fix for crappy arhive-contents that have "No commentary." #in place of dependency if isinstance(deps, basestring): deps = [] dependencies = serializable_elist(separator="\n\t") for dep in deps: dep = self.convert_dependency([common_config, config], dep[DEP_NAME].value(), external = False) if dep: dependencies.append(dep) properties = {'source_type' : source_type, 'description' : description, 'dependencies' : dependencies, 'depend' : dependencies, 'rdepend' : dependencies, 'realname' : realname, 'longdescription' : description } pkg_db.add_package(pkg, properties)
print("In dune file " + dune + ", the preprocessing clause does not contain " + (sexpdata.dumps(ppx))) global exit_code exit_code = 1 for dune in dune_paths: with open(dune) as fp: # wrap in parens to get list of top-level clauses sexps = sexpdata.loads('(' + fp.read() + ')') for sexp in sexps: if isinstance( sexp, list) and len(sexp) > 0 and sexpdata.car(sexp) == library: clauses = sexpdata.cdr(sexp) found_preprocess = False for clause in clauses: if sexpdata.car(clause) == preprocess: found_preprocess = True subclause = sexpdata.car(sexpdata.cdr(clause)) if subclause == no_preprocessing: # error if no preprocessing explicitly no_ppx_error(dune, ppx_lint) elif sexpdata.car(subclause) == pps: ppxs = sexpdata.cdr(subclause) lint_ppx_ndx = get_ppx_ndx(dune, ppxs, ppx_lint) if found_preprocess == False: # error if no preprocessing implicitly missing_ppx_error(dune, ppx_lint)
archive_conns = { "marmalade": httplib.HTTPSConnection("marmalade-repo.org", context=ssl._create_unverified_context()), "elpa": httplib.HTTPConnection("elpa.gnu.org"), "melpa": httplib.HTTPConnection("melpa.org") } for repo_name, conn in archive_conns.iteritems(): conn.connect() conn.request("GET", "/packages/archive-contents") response = conn.getresponse() if response.status == 200: data = response.read() conn.close() archive_list = loads(data) package_list = cdr(archive_list) for package in package_list: name = package[0].value() version_array = car(package[2].value()) version = ".".join(map(lambda x: str(x), version_array)) package_type = package[2].value()[3].value() extension = {"single": "el", "tar": "tar"}.get(package_type) filename = "%s-%s.%s" % (name, version, extension) package_uri = "/packages/%s" % (filename) conn.connect() conn.request("GET", package_uri) package_response = conn.getresponse()