mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Python 3 compatibility
This commit is contained in:
parent
55e5bdfc6c
commit
1092b42e12
10
tools/get.py
10
tools/get.py
@ -4,7 +4,6 @@
|
|||||||
# Written by Ivan Grokhotkov, 2015.
|
# Written by Ivan Grokhotkov, 2015.
|
||||||
#
|
#
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import urllib
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import errno
|
import errno
|
||||||
@ -16,6 +15,11 @@ import sys
|
|||||||
import tarfile
|
import tarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
import re
|
import re
|
||||||
|
if sys.version_info[0] == 3:
|
||||||
|
from urllib.request import urlretrieve
|
||||||
|
else:
|
||||||
|
# Not Python 3 - today, it is most likely to be Python 2
|
||||||
|
from urllib import urlretrieve
|
||||||
|
|
||||||
dist_dir = 'dist/'
|
dist_dir = 'dist/'
|
||||||
|
|
||||||
@ -54,7 +58,7 @@ def unpack(filename, destination):
|
|||||||
raise NotImplementedError('Unsupported archive type')
|
raise NotImplementedError('Unsupported archive type')
|
||||||
|
|
||||||
# a little trick to rename tool directories so they don't contain version number
|
# a little trick to rename tool directories so they don't contain version number
|
||||||
rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).encode('ascii').strip('-')
|
rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).strip('-')
|
||||||
if rename_to != dirname:
|
if rename_to != dirname:
|
||||||
print('Renaming {0} to {1}'.format(dirname, rename_to))
|
print('Renaming {0} to {1}'.format(dirname, rename_to))
|
||||||
if os.path.isdir(rename_to):
|
if os.path.isdir(rename_to):
|
||||||
@ -68,7 +72,7 @@ def get_tool(tool):
|
|||||||
real_hash = tool['checksum'].split(':')[1]
|
real_hash = tool['checksum'].split(':')[1]
|
||||||
if not os.path.isfile(local_path):
|
if not os.path.isfile(local_path):
|
||||||
print('Downloading ' + archive_name);
|
print('Downloading ' + archive_name);
|
||||||
urllib.urlretrieve(url, local_path, report_progress)
|
urlretrieve(url, local_path, report_progress)
|
||||||
sys.stdout.write("\rDone\n")
|
sys.stdout.write("\rDone\n")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user