forked from platformio/platformio-core
Fix Python 2.6 support
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.platformio
|
||||
- $HOME/.platformio
|
||||
|
||||
language: python
|
||||
python:
|
||||
@ -9,7 +9,8 @@ python:
|
||||
env:
|
||||
- TOX_ENV=docs
|
||||
- TOX_ENV=lint
|
||||
- TOX_ENV=py27
|
||||
- TOX_ENV=py26
|
||||
- TOX_ENV=py27
|
||||
|
||||
install:
|
||||
- pip install tox
|
||||
|
@ -4,7 +4,6 @@
|
||||
from email.utils import parsedate_tz
|
||||
from math import ceil
|
||||
from os.path import getsize, join
|
||||
from subprocess import check_output
|
||||
from time import mktime
|
||||
|
||||
from click import progressbar
|
||||
@ -12,7 +11,7 @@ from requests import get
|
||||
|
||||
from platformio.exception import (FDSHASumMismatch, FDSizeMismatch,
|
||||
FDUnrecognizedStatusCode)
|
||||
from platformio.util import change_filemtime
|
||||
from platformio.util import change_filemtime, exec_command
|
||||
|
||||
|
||||
class FileDownloader(object):
|
||||
@ -67,10 +66,12 @@ class FileDownloader(object):
|
||||
|
||||
dlsha1 = None
|
||||
try:
|
||||
dlsha1 = check_output(["sha1sum", self._destination])
|
||||
result = exec_command(["sha1sum", self._destination])
|
||||
dlsha1 = result['out']
|
||||
except OSError:
|
||||
try:
|
||||
dlsha1 = check_output(["shasum", "-a", "1", self._destination])
|
||||
result = exec_command(["shasum", "-a", "1", self._destination])
|
||||
dlsha1 = result['out']
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
@ -90,7 +90,7 @@ class LibraryManager(object):
|
||||
|
||||
info = self.get_info(id_)
|
||||
rename(tmplib_dir, join(self.lib_dir, "%s_ID%d" % (
|
||||
re.sub(r"[^\da-z]+", "_", info['name'], flags=re.I), id_)))
|
||||
re.sub(r"[^\da-zA-Z]+", "_", info['name']), id_)))
|
||||
|
||||
telemetry.on_event(
|
||||
category="LibraryManager", action="Install",
|
||||
|
@ -146,14 +146,14 @@ def exec_command(*args, **kwargs):
|
||||
result['out'], result['err'] = p.communicate()
|
||||
result['returncode'] = p.returncode
|
||||
except KeyboardInterrupt:
|
||||
raise exception.AbortedByUser()
|
||||
finally:
|
||||
for s in ("stdout", "stderr"):
|
||||
if isinstance(kwargs[s], AsyncPipe):
|
||||
kwargs[s].close()
|
||||
raise exception.AbortedByUser()
|
||||
|
||||
for s in ("stdout", "stderr"):
|
||||
if isinstance(kwargs[s], AsyncPipe):
|
||||
kwargs[s].close()
|
||||
result[s[3:]] = "\n".join(kwargs[s].get_buffer())
|
||||
|
||||
for k, v in result.iteritems():
|
||||
|
@ -2,13 +2,14 @@
|
||||
# See LICENSE for details.
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from subprocess import check_output
|
||||
from platform import system
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
|
||||
CURINTERPRETER_PATH = os.path.normpath(sys.executable)
|
||||
IS_WINDOWS = sys.platform.startswith("win")
|
||||
IS_WINDOWS = system() == "Windows"
|
||||
|
||||
|
||||
def fix_winpython_pathenv():
|
||||
@ -51,8 +52,21 @@ def fix_winpython_pathenv():
|
||||
return True
|
||||
|
||||
|
||||
def exec_command(*args, **kwargs):
|
||||
kwargs['stdout'] = subprocess.PIPE
|
||||
kwargs['stderr'] = subprocess.PIPE
|
||||
kwargs['shell'] = IS_WINDOWS
|
||||
|
||||
p = subprocess.Popen(*args, **kwargs)
|
||||
out, err = p.communicate()
|
||||
|
||||
if p.returncode != 0:
|
||||
raise Exception(err)
|
||||
return out
|
||||
|
||||
|
||||
def exec_python_cmd(args):
|
||||
return check_output([CURINTERPRETER_PATH] + args, shell=IS_WINDOWS).strip()
|
||||
return exec_command([CURINTERPRETER_PATH] + args, shell=IS_WINDOWS).strip()
|
||||
|
||||
|
||||
def install_pip():
|
||||
@ -74,7 +88,10 @@ def install_pip():
|
||||
|
||||
def install_pypi_packages(packages):
|
||||
for pipargs in packages:
|
||||
print (exec_python_cmd(["-m", "pip", "install", "-U"] + pipargs))
|
||||
print (exec_python_cmd([
|
||||
"-m",
|
||||
"pip.__main__" if sys.version_info < (2, 7, 0) else "pip",
|
||||
"install", "-U"] + pipargs))
|
||||
|
||||
|
||||
def main():
|
||||
@ -113,10 +130,13 @@ def main():
|
||||
"successfully FINISHED! <==\n")
|
||||
|
||||
try:
|
||||
print (check_output("platformio", shell=IS_WINDOWS))
|
||||
print (exec_command("platformio", shell=IS_WINDOWS))
|
||||
except:
|
||||
try:
|
||||
print (exec_python_cmd(["-m", "platformio"]))
|
||||
print (exec_python_cmd([
|
||||
"-m",
|
||||
"platformio.__main__" if sys.version_info < (2, 7, 0) else
|
||||
"platformio"]))
|
||||
finally:
|
||||
print ("\n Please RESTART your Terminal Application and run "
|
||||
"`platformio --help` command.")
|
||||
|
@ -40,13 +40,15 @@ def test_init_special_board(platformio_setup, clirunner, validate_cliresult):
|
||||
uno = util.get_boards("uno")
|
||||
config = util.get_project_config()
|
||||
expected_result = [
|
||||
('platform', uno['platform']),
|
||||
('framework', uno['framework']),
|
||||
('board', 'uno'),
|
||||
('targets', 'upload')
|
||||
("platform", str(uno['platform'])),
|
||||
("framework", str(uno['framework'])),
|
||||
("board", "uno"),
|
||||
("targets", "upload")
|
||||
]
|
||||
|
||||
assert config.has_section("env:autogen_uno")
|
||||
assert config.items("env:autogen_uno") == expected_result
|
||||
assert len(set(expected_result).symmetric_difference(
|
||||
set(config.items("env:autogen_uno")))) == 0
|
||||
|
||||
|
||||
def test_init_disable_auto_uploading(platformio_setup, clirunner,
|
||||
@ -58,12 +60,13 @@ def test_init_disable_auto_uploading(platformio_setup, clirunner,
|
||||
validate_pioproject(getcwd())
|
||||
config = util.get_project_config()
|
||||
expected_result = [
|
||||
('platform', 'atmelavr'),
|
||||
('framework', 'arduino'),
|
||||
('board', 'uno')
|
||||
("platform", "atmelavr"),
|
||||
("framework", "arduino"),
|
||||
("board", "uno")
|
||||
]
|
||||
assert config.has_section("env:autogen_uno")
|
||||
assert config.items("env:autogen_uno") == expected_result
|
||||
assert len(set(expected_result).symmetric_difference(
|
||||
set(config.items("env:autogen_uno")))) == 0
|
||||
|
||||
|
||||
def test_init_incorrect_board(clirunner):
|
||||
|
Reference in New Issue
Block a user