def get_used_frameworks(env, path): if any( isfile(join(path, fname)) for fname in ("library.properties", "keywords.txt")): return ["arduino"] if isfile(join(path, "module.json")): return ["mbed"] include_re = re.compile(r'^#include\s+(<|")(Arduino|mbed)\.h(<|")', flags=re.MULTILINE) # check source files for root, _, files in os.walk(path, followlinks=True): if "mbed_lib.json" in files: return ["mbed"] for fname in files: if not fs.path_endswith_ext( fname, piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT): continue content = get_file_contents(join(root, fname)) if not content: continue if "Arduino.h" in content and include_re.search(content): return ["arduino"] if "mbed.h" in content and include_re.search(content): return ["mbed"] return []
def process(self, contents): out_file = self._main_ino + ".cpp" assert self._gcc_preprocess(contents, out_file) contents = get_file_contents(out_file) contents = self._join_multiline_strings(contents) with open(out_file, "w") as fp: fp.write(self.append_prototypes(contents)) return out_file
def merge(self, nodes): assert nodes lines = [] for node in nodes: contents = get_file_contents(node.get_path()) _lines = [ '# 1 "%s"' % node.get_path().replace("\\", "/"), contents ] if self.is_main_node(contents): lines = _lines + lines self._main_ino = node.get_path() else: lines.extend(_lines) if not self._main_ino: self._main_ino = nodes[0].get_path() return "\n".join(["#include <Arduino.h>"] + lines) if lines else None
def device_monitor(ctx, **kwargs): def _tx_target(sock_dir): try: pioplus_call(sys.argv[1:] + ["--sock", sock_dir]) except exception.ReturnErrorCode: pass sock_dir = mkdtemp(suffix="pioplus") sock_file = join(sock_dir, "sock") try: t = threading.Thread(target=_tx_target, args=(sock_dir, )) t.start() while t.is_alive() and not isfile(sock_file): sleep(0.1) if not t.is_alive(): return kwargs['port'] = get_file_contents(sock_file) ctx.invoke(cmd_device_monitor, **kwargs) t.join(2) finally: util.rmtree_(sock_dir)
def _rules_to_set(rules_path): return set(l.strip() for l in get_file_contents(rules_path).split("\n") if l.strip() and not l.startswith("#"))
def _render_tpl(tpl_path, tpl_vars): return bottle.template(get_file_contents(tpl_path), **tpl_vars)