mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 18:17:13 +02:00
Implement "get_file_contents" helper
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import codecs
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -74,13 +75,7 @@ class LibBuilderFactory(object):
|
|||||||
if not env.IsFileWithExt(
|
if not env.IsFileWithExt(
|
||||||
fname, piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT):
|
fname, piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT):
|
||||||
continue
|
continue
|
||||||
content = ""
|
content = util.get_file_contents(join(root, fname))
|
||||||
try:
|
|
||||||
with open(join(root, fname)) as f:
|
|
||||||
content = f.read()
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
with open(join(root, fname), encoding="latin-1") as f:
|
|
||||||
content = f.read()
|
|
||||||
if not content:
|
if not content:
|
||||||
continue
|
continue
|
||||||
if "Arduino.h" in content and include_re.search(content):
|
if "Arduino.h" in content and include_re.search(content):
|
||||||
@ -481,7 +476,8 @@ class ArduinoLibBuilder(LibBuilderBase):
|
|||||||
manifest = {}
|
manifest = {}
|
||||||
if not isfile(join(self.path, "library.properties")):
|
if not isfile(join(self.path, "library.properties")):
|
||||||
return manifest
|
return manifest
|
||||||
with open(join(self.path, "library.properties")) as fp:
|
manifest_path = join(self.path, "library.properties")
|
||||||
|
with codecs.open(manifest_path, encoding="utf-8") as fp:
|
||||||
for line in fp.readlines():
|
for line in fp.readlines():
|
||||||
if "=" not in line:
|
if "=" not in line:
|
||||||
continue
|
continue
|
||||||
|
@ -76,8 +76,7 @@ class InoToCPPConverter(object):
|
|||||||
def process(self, contents):
|
def process(self, contents):
|
||||||
out_file = self._main_ino + ".cpp"
|
out_file = self._main_ino + ".cpp"
|
||||||
assert self._gcc_preprocess(contents, out_file)
|
assert self._gcc_preprocess(contents, out_file)
|
||||||
with open(out_file) as fp:
|
contents = util.get_file_contents(out_file)
|
||||||
contents = fp.read()
|
|
||||||
contents = self._join_multiline_strings(contents)
|
contents = self._join_multiline_strings(contents)
|
||||||
with open(out_file, "w") as fp:
|
with open(out_file, "w") as fp:
|
||||||
fp.write(self.append_prototypes(contents))
|
fp.write(self.append_prototypes(contents))
|
||||||
|
@ -202,7 +202,7 @@ def device_monitor(ctx, **kwargs):
|
|||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
if not t.is_alive():
|
if not t.is_alive():
|
||||||
return
|
return
|
||||||
kwargs['port'] = open(sock_file).read()
|
kwargs['port'] = util.get_file_contents(sock_file)
|
||||||
ctx.invoke(cmd_device_monitor, **kwargs)
|
ctx.invoke(cmd_device_monitor, **kwargs)
|
||||||
t.join(2)
|
t.join(2)
|
||||||
finally:
|
finally:
|
||||||
|
@ -122,10 +122,8 @@ class ProjectGenerator(object):
|
|||||||
contents.encode("utf8") if util.PY2 else contents)
|
contents.encode("utf8") if util.PY2 else contents)
|
||||||
|
|
||||||
def _render_tpl(self, tpl_path):
|
def _render_tpl(self, tpl_path):
|
||||||
content = ""
|
return bottle.template(
|
||||||
with open(tpl_path) as f:
|
util.get_file_contents(tpl_path), **self._tplvars)
|
||||||
content = f.read()
|
|
||||||
return bottle.template(content, **self._tplvars)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _merge_contents(dst_path, contents):
|
def _merge_contents(dst_path, contents):
|
||||||
|
@ -852,6 +852,15 @@ def ensure_udev_rules():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_file_contents(path):
|
||||||
|
try:
|
||||||
|
with open(path) as f:
|
||||||
|
return f.read()
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
with open(path, encoding="latin-1") as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
|
||||||
def rmtree_(path):
|
def rmtree_(path):
|
||||||
|
|
||||||
def _onerror(_, name, __):
|
def _onerror(_, name, __):
|
||||||
|
Reference in New Issue
Block a user