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