forked from espressif/esptool
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,767 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ local.mk | |
report.xml | ||
|
||
docs/_build/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import argparse | ||
import json | ||
import os | ||
import re | ||
import sys | ||
import datetime | ||
|
||
MANIFEST_DATA = { | ||
"name": "tool-esptoolpy", | ||
"description": "A serial utility to communicate & flash code to Espressif chips", | ||
"keywords": ["tools", "uploader", "tasmota", "espressif", "esp8266", "esp32"], | ||
"license": "GPL-2.0-or-later", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/tasmota/esptool", | ||
}, | ||
} | ||
|
||
|
||
def convert_version(version_string): | ||
"""A helper function that converts a custom version string | ||
to a suitable SemVer alternative. For example: | ||
'release/v5.1' becomes '5.1.0', | ||
'v7.7.7' becomes '7.7.7' | ||
""" | ||
|
||
regex_pattern = ( | ||
r"v(?P<MAJOR>0|[1-9]\d*)\.(?P<MINOR>0|[1-9]\d*)\.*(?P<PATCH>0|[1-9]\d*)*" | ||
) | ||
match = re.search(regex_pattern, version_string) | ||
if not match: | ||
sys.stderr.write( | ||
f"Failed to find a regex match for '{regex_pattern}' in '{version_string}'\n" | ||
) | ||
return "" | ||
|
||
major, minor, patch = match.groups() | ||
if not patch: | ||
patch = "0" | ||
|
||
return ".".join((major, minor, patch)) | ||
|
||
|
||
def main(dst_dir, version_string): | ||
|
||
converted_version = convert_version(version_string) | ||
if not converted_version: | ||
sys.stderr.write(f"Failed to convert version '{version_string}'\n") | ||
return -1 | ||
|
||
manifest_file_path = os.path.join(dst_dir, "package.json") | ||
build_date = datetime.date.today() | ||
with open(manifest_file_path, "w", encoding="utf8") as fp: | ||
MANIFEST_DATA["version"] = f"{converted_version}" | ||
MANIFEST_DATA["date"] = f"{build_date}" | ||
json.dump(MANIFEST_DATA, fp, indent=2) | ||
|
||
print( | ||
f"Generated esptool package.json '{manifest_file_path}' with '{converted_version}' version" | ||
) | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-o", | ||
"--dst-dir", | ||
dest="dst_dir", | ||
required=True, | ||
help="Destination folder where the 'package.json' manifest will be located", | ||
) | ||
parser.add_argument( | ||
"-s", | ||
"--version-string", | ||
dest="version_string", | ||
required=True, | ||
help="Version string in format v*.*.*", | ||
) | ||
args = parser.parse_args() | ||
|
||
sys.exit(main(args.dst_dir, args.version_string)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
|
||
import shutil | ||
import subprocess | ||
|
||
|
||
def main(): | ||
|
||
# remove not needed for plain python use | ||
shutil.rmtree("ci", ignore_errors=True) | ||
shutil.rmtree("docs", ignore_errors=True) | ||
shutil.rmtree("flasher_stub", ignore_errors=True) | ||
shutil.rmtree("test", ignore_errors=True) | ||
|
||
zipfile = "esptool.zip" | ||
|
||
print("Zip needed files into {}...".format(zipfile)) | ||
subprocess.run(["/usr/bin/7z", "a", "-mx=9", "-tzip", "-xr!.*", zipfile, "./"], check=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD | ||
# | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
import argparse | ||
import re | ||
|
||
LINE_RE = re.compile(r"^__version__ = ['\"]([^'\"]*)['\"]") | ||
NEW_LINE = '__version__ = "{}"\n' | ||
|
||
|
||
def patch_file(path, new_version): | ||
new_version = new_version.lstrip("v") | ||
|
||
with open(path, "r") as fin: | ||
lines = fin.readlines() | ||
|
||
for i, line in enumerate(lines, start=0): | ||
m = LINE_RE.search(line) | ||
if m: | ||
lines[i] = NEW_LINE.format(new_version) | ||
break | ||
|
||
with open(path, "w") as fout: | ||
fout.writelines(lines) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("file", help="Path to script with __version__") | ||
parser.add_argument( | ||
"--version", help="Version specifier to patch the version to" | ||
) | ||
args = parser.parse_args() | ||
patch_file(args.file, args.version) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Copyright (c) 2011, Bernhard Leiner | ||
# Copyright (c) 2013-2018 Alexander Belchenko | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, | ||
# with or without modification, are permitted provided | ||
# that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain | ||
# the above copyright notice, this list of conditions | ||
# and the following disclaimer. | ||
# * Redistributions in binary form must reproduce | ||
# the above copyright notice, this list of conditions | ||
# and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# * Neither the name of the author nor the names | ||
# of its contributors may be used to endorse | ||
# or promote products derived from this software | ||
# without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
# IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
'''Compatibility functions for python 2 and 3. | ||
@author Bernhard Leiner (bleiner AT gmail com) | ||
@author Alexander Belchenko (alexander belchenko AT gmail com) | ||
''' | ||
|
||
# ruff: noqa | ||
__docformat__ = "javadoc" | ||
|
||
|
||
import sys, array | ||
|
||
|
||
if sys.version_info[0] >= 3: | ||
# Python 3 | ||
Python = 3 | ||
|
||
def asbytes(s): | ||
if isinstance(s, bytes): | ||
return s | ||
return s.encode('latin1') | ||
def asstr(s): | ||
if isinstance(s, str): | ||
return s | ||
return s.decode('latin1') | ||
|
||
# for python >= 3.2 use 'tobytes', otherwise 'tostring' | ||
array_tobytes = array.array.tobytes if sys.version_info[1] >= 2 else array.array.tostring | ||
|
||
IntTypes = (int,) | ||
StrType = str | ||
UnicodeType = str | ||
|
||
range_g = range # range generator | ||
def range_l(*args): # range list | ||
return list(range(*args)) | ||
|
||
def dict_keys(dikt): # dict keys list | ||
return list(dikt.keys()) | ||
def dict_keys_g(dikt): # dict keys generator | ||
return dikt.keys() | ||
def dict_items_g(dikt): # dict items generator | ||
return dikt.items() | ||
|
||
from io import StringIO, BytesIO | ||
|
||
def get_binary_stdout(): | ||
return sys.stdout.buffer | ||
|
||
def get_binary_stdin(): | ||
return sys.stdin.buffer | ||
|
||
else: | ||
# Python 2 | ||
Python = 2 | ||
|
||
asbytes = str | ||
asstr = str | ||
|
||
array_tobytes = array.array.tostring | ||
|
||
IntTypes = (int, long) | ||
StrType = basestring | ||
UnicodeType = unicode | ||
|
||
#range_g = xrange # range generator | ||
def range_g(*args): | ||
# we want to use xrange here but on python 2 it does not work with long ints | ||
try: | ||
return xrange(*args) | ||
except OverflowError: | ||
start = 0 | ||
stop = 0 | ||
step = 1 | ||
n = len(args) | ||
if n == 1: | ||
stop = args[0] | ||
elif n == 2: | ||
start, stop = args | ||
elif n == 3: | ||
start, stop, step = args | ||
else: | ||
raise TypeError('wrong number of arguments in range_g call!') | ||
if step == 0: | ||
raise ValueError('step cannot be zero') | ||
if step > 0: | ||
def up(start, stop, step): | ||
while start < stop: | ||
yield start | ||
start += step | ||
return up(start, stop, step) | ||
else: | ||
def down(start, stop, step): | ||
while start > stop: | ||
yield start | ||
start += step | ||
return down(start, stop, step) | ||
|
||
range_l = range # range list | ||
|
||
def dict_keys(dikt): # dict keys list | ||
return dikt.keys() | ||
def dict_keys_g(dikt): # dict keys generator | ||
return dikt.keys() | ||
def dict_items_g(dikt): # dict items generator | ||
return dikt.items() | ||
|
||
from cStringIO import StringIO | ||
BytesIO = StringIO | ||
|
||
import os | ||
def _force_stream_binary(stream): | ||
"""Force binary mode for stream on Windows.""" | ||
if os.name == 'nt': | ||
f_fileno = getattr(stream, 'fileno', None) | ||
if f_fileno: | ||
fileno = f_fileno() | ||
if fileno >= 0: | ||
import msvcrt | ||
msvcrt.setmode(fileno, os.O_BINARY) | ||
return stream | ||
|
||
def get_binary_stdout(): | ||
return _force_stream_binary(sys.stdout) | ||
|
||
def get_binary_stdin(): | ||
return _force_stream_binary(sys.stdin) |
Oops, something went wrong.