forked from platformio/platformio-core
Use native open/io.open for file contents reading/writing
This commit is contained in:
@@ -252,12 +252,14 @@ def is_prog_obsolete(prog_path):
|
||||
break
|
||||
shasum.update(data)
|
||||
new_digest = shasum.hexdigest()
|
||||
old_digest = (
|
||||
fs.get_file_contents(prog_hash_path) if isfile(prog_hash_path) else None
|
||||
)
|
||||
old_digest = None
|
||||
if isfile(prog_hash_path):
|
||||
with open(prog_hash_path) as fp:
|
||||
old_digest = fp.read()
|
||||
if new_digest == old_digest:
|
||||
return False
|
||||
fs.write_file_contents(prog_hash_path, new_digest)
|
||||
with open(prog_hash_path, "w") as fp:
|
||||
fp.write(new_digest)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import glob
|
||||
import io
|
||||
import os
|
||||
import shutil
|
||||
from functools import cmp_to_key
|
||||
@@ -66,7 +67,8 @@ class OSRPC(object):
|
||||
if uri.startswith("http"):
|
||||
return self.fetch_content(uri, data, headers, cache_valid)
|
||||
if os.path.isfile(uri):
|
||||
return fs.get_file_contents(uri, encoding="utf8")
|
||||
with io.open(uri, encoding="utf-8") as fp:
|
||||
return fp.read()
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -244,7 +244,8 @@ class ProjectRPC(object):
|
||||
return project_dir
|
||||
if not os.path.isdir(src_dir):
|
||||
os.makedirs(src_dir)
|
||||
fs.write_file_contents(main_path, main_content.strip())
|
||||
with open(main_path, "w") as fp:
|
||||
fp.write(main_content.strip())
|
||||
return project_dir
|
||||
|
||||
def import_arduino(self, board, use_arduino_libs, arduino_project_dir):
|
||||
|
||||
@@ -187,9 +187,9 @@ def init_base_project(project_dir):
|
||||
|
||||
|
||||
def init_include_readme(include_dir):
|
||||
fs.write_file_contents(
|
||||
os.path.join(include_dir, "README"),
|
||||
"""
|
||||
with open(os.path.join(include_dir, "README"), "w") as fp:
|
||||
fp.write(
|
||||
"""
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
@@ -229,14 +229,14 @@ Read more about using header files in official GCC documentation:
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
""",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def init_lib_readme(lib_dir):
|
||||
# pylint: disable=line-too-long
|
||||
fs.write_file_contents(
|
||||
os.path.join(lib_dir, "README"),
|
||||
"""
|
||||
with open(os.path.join(lib_dir, "README"), "w") as fp:
|
||||
fp.write(
|
||||
"""
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
@@ -283,13 +283,13 @@ libraries scanning project source files.
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
""",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def init_test_readme(test_dir):
|
||||
fs.write_file_contents(
|
||||
os.path.join(test_dir, "README"),
|
||||
"""
|
||||
with open(os.path.join(test_dir, "README"), "w") as fp:
|
||||
fp.write(
|
||||
"""
|
||||
This directory is intended for PIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
@@ -301,16 +301,16 @@ in the development cycle.
|
||||
More information about PIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
||||
""",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def init_ci_conf(project_dir):
|
||||
conf_path = os.path.join(project_dir, ".travis.yml")
|
||||
if os.path.isfile(conf_path):
|
||||
return
|
||||
fs.write_file_contents(
|
||||
conf_path,
|
||||
"""# Continuous Integration (CI) is the practice, in software
|
||||
with open(conf_path, "w") as fp:
|
||||
fp.write(
|
||||
"""# Continuous Integration (CI) is the practice, in software
|
||||
# engineering, of merging all developer working copies with a shared mainline
|
||||
# several times a day < https://docs.platformio.org/page/ci/index.html >
|
||||
#
|
||||
@@ -378,14 +378,15 @@ def init_ci_conf(project_dir):
|
||||
# script:
|
||||
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
|
||||
""",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def init_cvs_ignore(project_dir):
|
||||
conf_path = os.path.join(project_dir, ".gitignore")
|
||||
if os.path.isfile(conf_path):
|
||||
return
|
||||
fs.write_file_contents(conf_path, ".pio\n")
|
||||
with open(conf_path, "w") as fp:
|
||||
fp.write(".pio\n")
|
||||
|
||||
|
||||
def fill_project_envs(
|
||||
|
||||
@@ -222,7 +222,8 @@ def device_monitor(ctx, **kwargs):
|
||||
sleep(0.1)
|
||||
if not t.is_alive():
|
||||
return
|
||||
kwargs["port"] = fs.get_file_contents(sock_file)
|
||||
with open(sock_file) as fp:
|
||||
kwargs["port"] = fp.read()
|
||||
ctx.invoke(device.device_monitor, **kwargs)
|
||||
t.join(2)
|
||||
finally:
|
||||
|
||||
@@ -53,9 +53,12 @@ def clean_build_dir(build_dir, config):
|
||||
|
||||
if isdir(build_dir):
|
||||
# check project structure
|
||||
if isfile(checksum_file) and fs.get_file_contents(checksum_file) == checksum:
|
||||
return
|
||||
if isfile(checksum_file):
|
||||
with open(checksum_file) as fp:
|
||||
if fp.read() == checksum:
|
||||
return
|
||||
fs.rmtree(build_dir)
|
||||
|
||||
makedirs(build_dir)
|
||||
fs.write_file_contents(checksum_file, checksum)
|
||||
with open(checksum_file, "w") as fp:
|
||||
fp.write(checksum)
|
||||
|
||||
@@ -19,7 +19,7 @@ from string import Template
|
||||
|
||||
import click
|
||||
|
||||
from platformio import exception, fs
|
||||
from platformio import exception
|
||||
|
||||
TRANSPORT_OPTIONS = {
|
||||
"arduino": {
|
||||
@@ -195,6 +195,7 @@ class TestProcessorBase(object):
|
||||
data = Template(tpl).substitute(baudrate=self.get_baudrate())
|
||||
|
||||
tmp_file = join(test_dir, "output_export.cpp")
|
||||
fs.write_file_contents(tmp_file, data)
|
||||
with open(tmp_file, "w") as fp:
|
||||
fp.write(data)
|
||||
|
||||
atexit.register(delete_tmptest_file, tmp_file)
|
||||
|
||||
Reference in New Issue
Block a user