Fix "TypeError: TypeError: write() argument 1 must be unicode" when generating project on Windows/Python 2

This commit is contained in:
Ivan Kravets
2020-02-12 15:14:58 +02:00
parent 0bc872eafd
commit d0a6861369
4 changed files with 18 additions and 8 deletions

View File

@ -265,7 +265,7 @@ class GDBClient(BaseProcess): # pylint: disable=too-many-instance-attributes
telemetry.encode_run_environment(self.env_options),
last_erros,
)
telemetry.send_exception("DebugInitError: %s" % err, is_fatal=True)
telemetry.send_exception("DebugInitError: %s" % err)
self.transport.loseConnection()
def _kill_previous_session(self):

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import io
import codecs
import os
import sys
from os.path import basename, isdir, isfile, join, realpath, relpath
@ -129,18 +129,18 @@ class ProjectGenerator(object):
dst_dir = join(self.project_dir, tpl_relpath)
if not isdir(dst_dir):
os.makedirs(dst_dir)
file_name = basename(tpl_path)[:-4]
contents = self._render_tpl(tpl_path, tpl_vars)
self._merge_contents(join(dst_dir, file_name), contents)
@staticmethod
def _render_tpl(tpl_path, tpl_vars):
return bottle.template(fs.get_file_contents(tpl_path), **tpl_vars)
with codecs.open(tpl_path, "r", encoding="utf8") as fp:
return bottle.SimpleTemplate(fp.read()).render(**tpl_vars)
@staticmethod
def _merge_contents(dst_path, contents):
if basename(dst_path) == ".gitignore" and isfile(dst_path):
return
with io.open(dst_path, "w", encoding="utf8") as fp:
with codecs.open(dst_path, "w", encoding="utf8") as fp:
fp.write(contents)

View File

@ -5,8 +5,9 @@
% recommendations = set(["platformio.platformio-ide"])
% previous_json = os.path.join(project_dir, ".vscode", "extensions.json")
% if os.path.isfile(previous_json):
% with open(previous_json) as fp:
% contents = re.sub(r"^\s*//.*$", "", fp.read(), flags=re.M).strip()
% fp = open(previous_json)
% contents = re.sub(r"^\s*//.*$", "", fp.read(), flags=re.M).strip()
% fp.close()
% if contents:
% recommendations |= set(json.loads(contents).get("recommendations", []))
% end

View File

@ -78,6 +78,7 @@ class MeasurementProtocol(TelemetryBase):
self._prefill_screen_name()
self._prefill_appinfo()
self._prefill_sysargs()
self._prefill_custom_data()
def __getitem__(self, name):
@ -102,6 +103,15 @@ class MeasurementProtocol(TelemetryBase):
dpdata.append("IDE/%s" % os.getenv("PLATFORMIO_IDE"))
self["an"] = " ".join(dpdata)
def _prefill_sysargs(self):
args = []
for arg in sys.argv[1:]:
arg = str(arg).lower()
if "@" in arg or os.path.exists(arg):
arg = "***"
args.append(arg)
self["cd3"] = " ".join(args)
def _prefill_custom_data(self):
def _filter_args(items):
result = []
@ -118,7 +128,6 @@ class MeasurementProtocol(TelemetryBase):
caller_id = str(app.get_session_var("caller_id"))
self["cd1"] = util.get_systype()
self["cd2"] = "Python/%s %s" % (platform.python_version(), platform.platform())
# self['cd3'] = " ".join(_filter_args(sys.argv[1:]))
self["cd4"] = (
1 if (not util.is_ci() and (caller_id or not is_container())) else 0
)