Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter
- CitrineOS core extracted (CSMS OCPP 2.0.1) - OpenOCPP extracted (firmware OCPP 1.6J/2.0.1) - ShapeShifter library installed (pip install -e) - ShapeShifter specification extracted - EVerest extracted TODO updated with progress
This commit is contained in:
17
tools/EVerest-main/applications/utils/scripts/README.md
Normal file
17
tools/EVerest-main/applications/utils/scripts/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Utility Scripts
|
||||
|
||||
This directory contains useful scripts for working with EVerest and meta-everest
|
||||
|
||||
_cargolock2bb.py_ converts a Cargo.lock file, that can also be loaded via an URL, into a .bb file
|
||||
|
||||
_check_dependency_versions.py_ parses a snapshot.yaml file and checks if there are new versions of the listed dependencies available
|
||||
|
||||
_config2cmake.py_ parses a EVerest yaml config and prints a CMake command line to only include the modules needed by this config
|
||||
|
||||
_create_snapshot.py_ uses EDM to create an snapshot in a temporary subdirectory and postprocesses it to fix common problems
|
||||
|
||||
_parsebb.py_ parses .bb files and returns a json object containing the repository link, branch, revision and direct link to a file relative to the repo link
|
||||
|
||||
_replace_license.py_ parses C++ files and replaces license headers with up2date Apache 2.0 headers used in EVerest
|
||||
|
||||
_snapshot2bb.py_ parses a snapshot.yaml file and modifies the corresponding recipe .bb files
|
||||
80
tools/EVerest-main/applications/utils/scripts/cargolock2bb.py
Executable file
80
tools/EVerest-main/applications/utils/scripts/cargolock2bb.py
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright Pionix GmbH and Contributors to EVerest
|
||||
#
|
||||
"""
|
||||
author: kai-uwe.hermann@pionix.de
|
||||
Convert Cargo.lock files (that can also be provided as an URL) into a .bb file
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import requests
|
||||
import toml
|
||||
|
||||
|
||||
def read_cargo_lock_file(cargo_lock_path):
|
||||
try:
|
||||
cargo_lock_file = open(cargo_lock_path, 'r')
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
with cargo_lock_file:
|
||||
return toml.load(cargo_lock_file)
|
||||
|
||||
|
||||
def read_cargo_lock_from_url(cargo_lock_url):
|
||||
try:
|
||||
req = requests.get(cargo_lock_url, timeout=5)
|
||||
return toml.loads(req.text)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def print_bb_output(cargo_lock, skip_packages):
|
||||
if not cargo_lock or 'package' not in cargo_lock:
|
||||
print('# No packages in Cargo.lock file')
|
||||
return
|
||||
|
||||
print(f'SRC_URI += " \\')
|
||||
for package in cargo_lock['package']:
|
||||
if package['name'] in skip_packages:
|
||||
continue
|
||||
print(f' crate://crates.io/{package["name"]}/{package["version"]} \\')
|
||||
print(' "')
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='converts Cargo.lock files to bitbake recipe output')
|
||||
|
||||
parser.add_argument('--input',
|
||||
dest='in_cargo_lock',
|
||||
default='Cargo.lock',
|
||||
help='Path to the Cargo.lock file')
|
||||
parser.add_argument('--url',
|
||||
dest='url_cargo_lock',
|
||||
default=None,
|
||||
help='URL to the Cargo.lock file')
|
||||
parser.add_argument('--skip',
|
||||
dest='in_skip',
|
||||
default='',
|
||||
type=str,
|
||||
help='List of packages to skip, using \',\' as delimiter.')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
in_cargo_lock = os.path.realpath(os.path.expanduser(args.in_cargo_lock))
|
||||
in_cargo_lock_url = args.url_cargo_lock
|
||||
in_skip_packages = [entry for entry in args.in_skip.split(',')]
|
||||
|
||||
if in_cargo_lock_url:
|
||||
cargo_lock = read_cargo_lock_from_url(in_cargo_lock_url)
|
||||
else:
|
||||
cargo_lock = read_cargo_lock_file(in_cargo_lock)
|
||||
|
||||
print_bb_output(cargo_lock, in_skip_packages)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
124
tools/EVerest-main/applications/utils/scripts/check_dependency_versions.py
Executable file
124
tools/EVerest-main/applications/utils/scripts/check_dependency_versions.py
Executable file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright Pionix GmbH and Contributors to EVerest
|
||||
#
|
||||
"""
|
||||
author: kai-uwe.hermann@pionix.de
|
||||
Parse snapshot.yaml files check if dependency versions are up2date by checking for newer git tags
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import yaml
|
||||
import subprocess
|
||||
from packaging.version import Version
|
||||
|
||||
def get_remote_tags(remote_url: str) -> list:
|
||||
"""Return the remote tags of the repo at path, or an empty list."""
|
||||
remote_tags = []
|
||||
try:
|
||||
result = subprocess.run(["git", "-c", "versionsort.suffix=-", "ls-remote", "--tags", "--sort=-v:refname", "--refs", "--quiet", remote_url],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
|
||||
result_list = result.stdout.decode("utf-8").split("\n")
|
||||
for entry in result_list:
|
||||
ref_and_tag = entry.split("\t")
|
||||
if len(ref_and_tag) > 1:
|
||||
remote_tags.append(ref_and_tag[1].replace("refs/tags/", ""))
|
||||
except subprocess.CalledProcessError:
|
||||
return remote_tags
|
||||
|
||||
return remote_tags
|
||||
|
||||
|
||||
def parse_curl_version(curl_version):
|
||||
parsed_curl_version = curl_version.removeprefix("tiny-curl-")
|
||||
parsed_curl_version = parsed_curl_version.removeprefix("curl-")
|
||||
parsed_curl_version = parsed_curl_version.replace("_", ".")
|
||||
return parsed_curl_version
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='get updated dependency versions from snapshot.yaml')
|
||||
|
||||
parser.add_argument('--input',
|
||||
dest='in_snapshot',
|
||||
help='Path to the snapshot.yaml file')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
in_snapshot = os.path.realpath(os.path.expanduser(args.in_snapshot))
|
||||
|
||||
snapshot = None
|
||||
with open(in_snapshot, encoding='utf-8') as snapshot_file:
|
||||
try:
|
||||
snapshot = yaml.safe_load(snapshot_file)
|
||||
except yaml.YAMLError as e:
|
||||
print(f"Error parsing yaml of {in_snapshot}: {e}")
|
||||
return
|
||||
|
||||
if not snapshot:
|
||||
print(f"snapshot empty?")
|
||||
return
|
||||
|
||||
output = {}
|
||||
|
||||
branch_re = re.compile(r'branch=([^;|^"|\s]*)')
|
||||
|
||||
for key, entry in snapshot.items():
|
||||
branch = entry['branch']
|
||||
git_rev = entry['git_rev']
|
||||
git_tag = entry['git_tag']
|
||||
version = git_tag.removeprefix('wip-release-')
|
||||
version = version.removeprefix('v')
|
||||
version_without_rc, _vsep, _rc = version.partition('-rc')
|
||||
# todo: maybe even strip something like "wip-release-" from git_tag to keep versions sane?
|
||||
# or just do not modify the version if this cannot be parsed properly?
|
||||
# print(f"version: {version} without-rc: {version_without_rc}")
|
||||
git_url = entry['git']
|
||||
remote_tags = get_remote_tags(git_url)
|
||||
tags = []
|
||||
for original_remote_tag in remote_tags:
|
||||
remote_tag = original_remote_tag.removeprefix("v")
|
||||
if key == "libcurl":
|
||||
# special handling for curl
|
||||
remote_tag = parse_curl_version(remote_tag)
|
||||
if key == "pugixml":
|
||||
if remote_tag == "latest":
|
||||
continue
|
||||
|
||||
tags.append((original_remote_tag, remote_tag))
|
||||
|
||||
remote_versions = []
|
||||
version_mapping = {}
|
||||
for (original_remote_tag, remote_tag) in tags:
|
||||
try:
|
||||
ver = Version(remote_tag)
|
||||
version_mapping[ver] = original_remote_tag
|
||||
remote_versions.append(ver)
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
remote_versions.sort(reverse=True)
|
||||
|
||||
try:
|
||||
remote_version = remote_versions[0]
|
||||
parsed_version = ""
|
||||
if key == "libcurl":
|
||||
parsed_version = Version(parse_curl_version(version))
|
||||
else:
|
||||
parsed_version = Version(version)
|
||||
if parsed_version != remote_version:
|
||||
print(f" {key}: remote version is different from version in snapshot! Check if you want to update.")
|
||||
print(f" snapshot version: {version}")
|
||||
print(f" remote version: {remote_version}, original tag: {version_mapping[remote_version]}")
|
||||
except Exception as e:
|
||||
print(f" {key}: cannot parse remote version, please check manually!")
|
||||
print(f" snapshot version: {version}")
|
||||
print(f" thrown exception: {e}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
66
tools/EVerest-main/applications/utils/scripts/config2cmake.py
Executable file
66
tools/EVerest-main/applications/utils/scripts/config2cmake.py
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright Pionix GmbH and Contributors to EVerest
|
||||
#
|
||||
"""
|
||||
author: kai-uwe.hermann@pionix.de
|
||||
Parse a EVerest config and return a CMake command line to build only those modules
|
||||
"""
|
||||
import argparse
|
||||
import yaml
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_modules(config_yaml_path: Path):
|
||||
try:
|
||||
config = yaml.safe_load(config_yaml_path.read_text())
|
||||
module_names = set()
|
||||
for _key, value in config['active_modules'].items():
|
||||
module_names.add(value['module'])
|
||||
modules = ';'.join(sorted(module_names))
|
||||
return f'-DEVEREST_INCLUDE_MODULES="{modules}"'
|
||||
except yaml.YAMLError as err:
|
||||
raise Exception(f'Could not parse config file {config_yaml_path}') from err
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description='parse EVerest configs and extract modules')
|
||||
|
||||
parser.add_argument('config',
|
||||
help='Path to EVerest config',
|
||||
nargs=1)
|
||||
parser.add_argument('--full',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Set this flag if you want a full cmake command line (with "build" as default build-dir)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
config_path = Path(args.config[0]).expanduser().resolve()
|
||||
|
||||
try:
|
||||
modules = get_modules(config_path)
|
||||
if args.full:
|
||||
print(f'cmake -S . -B build {modules}')
|
||||
else:
|
||||
print(modules)
|
||||
except Exception as err:
|
||||
print(f'Could not generate CMake command line: {err}')
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
return_value = 1
|
||||
try:
|
||||
return_value = main()
|
||||
except Exception as e:
|
||||
print(f'Error: {e}')
|
||||
return_value = 1
|
||||
sys.exit(return_value)
|
||||
149
tools/EVerest-main/applications/utils/scripts/create_snapshot.py
Executable file
149
tools/EVerest-main/applications/utils/scripts/create_snapshot.py
Executable file
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright Pionix GmbH and Contributors to EVerest
|
||||
#
|
||||
"""
|
||||
author: kai-uwe.hermann@pionix.de
|
||||
Use edm to create a snapshot of the current directory without polluting the current working dir
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import yaml
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import string
|
||||
|
||||
|
||||
def get_tags(path: Path) -> list:
|
||||
"""Return a list of tags the HEAD points to of the repo at path, or an empty list."""
|
||||
tags = []
|
||||
try:
|
||||
result = subprocess.run(["git", "-C", path, "tag", "--points-at", "HEAD"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
|
||||
tags = result.stdout.decode("utf-8").splitlines()
|
||||
except subprocess.CalledProcessError:
|
||||
return tag
|
||||
|
||||
return tags
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='create an isolated snapshot with edm')
|
||||
|
||||
parser.add_argument('--working-dir', '-wd', type=str,
|
||||
help='Working directory containing the EVerest workspace (default: .)', default=str(Path.cwd()))
|
||||
parser.add_argument('--temp-dir', '-td', type=str,
|
||||
help='Temporary directory for creating the snapshot in (default: working-dir/tmp-for-snapshot)', default=None)
|
||||
parser.add_argument('--version', type=str,
|
||||
help='dependency version to override, format is: dependency1:version,dependency2:version2', default=None)
|
||||
parser.add_argument('--git-version', action='store_true', help='Use "git" as version when encountering a git hash')
|
||||
parser.add_argument('--allow-relative-to-working-dir', action='store_true', help='Allow temporary directory to be relative to working dir (dangerous!)')
|
||||
parser.add_argument('--post-process', action='store_true', help='Postprocess existing snapshot')
|
||||
parser.add_argument('--include-external-deps', action='store_true', help='Include external dependencies in snapshot')
|
||||
parser.add_argument('--exclude-dir', action='append', dest='excluded_dirs', type=str, help='Exclude specified directory from snapshot (can be used multiple times)', default=[])
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
working_dir = Path(args.working_dir).expanduser().resolve()
|
||||
|
||||
tmp_dir = working_dir / 'tmp-for-snapshot'
|
||||
|
||||
if args.temp_dir:
|
||||
tmp_dir = Path(args.temp_dir).expanduser().resolve()
|
||||
|
||||
if working_dir == tmp_dir:
|
||||
print(f'Temporary directory cannot be equal to working directory: {tmp_dir}')
|
||||
return 1
|
||||
|
||||
if tmp_dir.is_relative_to(working_dir) and tmp_dir.parent != working_dir and not args.allow_relative_to_working_dir:
|
||||
print(f'Temporary directory cannot be relative to working directory: {tmp_dir}')
|
||||
return 1
|
||||
|
||||
excluded_paths = []
|
||||
for excluded_dir in args.excluded_dirs:
|
||||
excluded_path = working_dir / excluded_dir
|
||||
excluded_path = excluded_path.expanduser().resolve()
|
||||
excluded_paths.append(excluded_path)
|
||||
|
||||
if not args.post_process and tmp_dir.exists():
|
||||
print(f'Temporary directory dir already exists, deleting it: {tmp_dir}')
|
||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||
if not args.post_process:
|
||||
tmp_dir.mkdir()
|
||||
|
||||
subdirs = list(working_dir.glob('*/'))
|
||||
for subdir in subdirs:
|
||||
subdir_path = Path(subdir)
|
||||
if not subdir_path.is_dir():
|
||||
print(f'{subdir_path} is not a dir, ignoring')
|
||||
continue
|
||||
if subdir_path == tmp_dir:
|
||||
print(f'{subdir_path} is tmp dir, ignoring')
|
||||
continue
|
||||
if subdir_path in excluded_paths:
|
||||
print(f'{subdir_path} is excluded, ignoring')
|
||||
continue
|
||||
print(f'Copying {subdir_path} to {tmp_dir}')
|
||||
destdir = tmp_dir / subdir_path.name
|
||||
|
||||
shutil.copytree(subdir_path, destdir, ignore=shutil.ignore_patterns('build*'))
|
||||
|
||||
print('Running edm snaphot --recursive')
|
||||
cmd_line = ['edm']
|
||||
if args.include_external_deps:
|
||||
cmd_line.append('--external-in-config')
|
||||
cmd_line.extend(['snapshot', '--recursive'])
|
||||
with subprocess.Popen(cmd_line, stderr=subprocess.PIPE, cwd=tmp_dir) as edm:
|
||||
for line in edm.stderr:
|
||||
print(line.decode('utf-8'), end='')
|
||||
in_snapshot = tmp_dir / 'snapshot.yaml'
|
||||
snapshot = None
|
||||
with open(in_snapshot, mode='r', encoding='utf-8') as snapshot_file:
|
||||
try:
|
||||
snapshot = yaml.safe_load(snapshot_file)
|
||||
except yaml.YAMLError as e:
|
||||
print(f'Error parsing yaml of {in_snapshot}: {e}')
|
||||
if snapshot:
|
||||
# check if git_tag is a 40 character hex string and assume it is a git_rev
|
||||
if args.git_version:
|
||||
for dependency, entry in snapshot.items():
|
||||
git_tag = ''
|
||||
if 'git_tag' in entry:
|
||||
git_tag = entry['git_tag']
|
||||
elif 'git_rev' in entry:
|
||||
git_tag = entry['git_rev']
|
||||
if len(git_tag) == 40 and all(character in string.hexdigits for character in git_tag):
|
||||
snapshot[dependency]['git_tag'] = 'git'
|
||||
if args.version:
|
||||
versions = args.version.split(',')
|
||||
for dep_versions in versions:
|
||||
dependency, version = dep_versions.split(':')
|
||||
if dependency in snapshot:
|
||||
print(f'Overriding {dependency} version {snapshot[dependency]["git_tag"]} to {version}')
|
||||
snapshot[dependency]['git_tag'] = version
|
||||
for dependency, entry in snapshot.items():
|
||||
git_tag = ''
|
||||
if 'git_tag' in entry:
|
||||
git_tag = entry['git_tag']
|
||||
if git_tag == 'latest':
|
||||
print(f'{dependency} has tag "latest", check if there is a version tag as well')
|
||||
dependency_path = tmp_dir / dependency
|
||||
tags = get_tags(dependency_path)
|
||||
tags.remove('latest')
|
||||
if len(tags) == 1:
|
||||
print(' Fixing "latest" tag in snapshot')
|
||||
snapshot[dependency]['git_tag'] = tags[0]
|
||||
else:
|
||||
print(f' List of tags with "latest" removed: "{tags}" is not directly usable...')
|
||||
|
||||
with open(in_snapshot, mode='w', encoding='utf-8') as snapshot_file:
|
||||
yaml.safe_dump(snapshot, snapshot_file, indent=2, sort_keys=False, width=120)
|
||||
print('Done')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
137
tools/EVerest-main/applications/utils/scripts/fix_dco_signoff.py
Executable file
137
tools/EVerest-main/applications/utils/scripts/fix_dco_signoff.py
Executable file
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright Pionix GmbH and Contributors to EVerest
|
||||
#
|
||||
"""
|
||||
author: andreas.heinrich@rwth-aachen.de
|
||||
Fix author and signoff of commits to match DCO requirements.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
|
||||
def get_git_author_string(args: argparse.Namespace) -> str:
|
||||
try:
|
||||
name = subprocess.run(
|
||||
['git', '-C', str(args.git_root), 'config', 'user.name'],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
).stdout.strip()
|
||||
|
||||
email = subprocess.run(
|
||||
['git', '-C', str(args.git_root), 'config', 'user.email'],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
).stdout.strip()
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f'Git config failed with error: {e.stderr}')
|
||||
exit(1)
|
||||
|
||||
result = f"{name} <{email}>"
|
||||
return result
|
||||
|
||||
|
||||
def remove_signoffs(args: argparse.Namespace) -> str:
|
||||
try:
|
||||
msg_result = subprocess.run(
|
||||
['git', '-C', str(args.git_root), 'log', '-1', '--pretty=%B'],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f'Git log failed with error: {e.stderr}')
|
||||
exit(1)
|
||||
|
||||
current_msg = msg_result.stdout
|
||||
lines = current_msg.splitlines()
|
||||
filtered_lines = [
|
||||
line for line in lines
|
||||
if not line.strip().startswith('Signed-off-by:')
|
||||
]
|
||||
clean_msg = "\n".join(filtered_lines).strip()
|
||||
return clean_msg
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Fix author and signoff of latest commit to match DCO requirements.')
|
||||
|
||||
parser.add_argument(
|
||||
'--author', '-a',
|
||||
type=str,
|
||||
help='Author name and email in the format "Name <email>"',
|
||||
default=None
|
||||
)
|
||||
parser.add_argument(
|
||||
'--git-root', '-g',
|
||||
type=str,
|
||||
help='Git root directory (default: .)',
|
||||
default=str(Path.cwd())
|
||||
)
|
||||
parser.add_argument(
|
||||
'--remove-existing-signoffs', '--rm',
|
||||
action='store_true',
|
||||
help='Remove existing Signed-off-by trailers before adding the new one',
|
||||
default=False
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
args.git_root = Path(args.git_root).expanduser().resolve()
|
||||
|
||||
if args.author is None:
|
||||
print(
|
||||
"\033[93m"
|
||||
"Warning:\n"
|
||||
" You are overriding the author information with yourself as author.\n"
|
||||
" Please make sure that you are the original author of the commit\n"
|
||||
" or give credits to the original author in commit message by for example\n"
|
||||
" adding a 'Co-authored-by: Original Author <email>' trailer to the commit message.\n"
|
||||
"\033[0m"
|
||||
)
|
||||
args.author = get_git_author_string(args)
|
||||
else:
|
||||
print(
|
||||
"\033[93m"
|
||||
"Warning:\n"
|
||||
" You are overriding the author information with a custom value.\n"
|
||||
" You are not allowed to signoff a commit for another person,\n"
|
||||
" except if you are the original author and have the right to do so\n"
|
||||
" or if you are a maintainer fixing the commit for the original author.\n"
|
||||
" For example in case of mismatching user.name and user.email in\n"
|
||||
" case of using github's web based git operations"
|
||||
"\033[0m"
|
||||
)
|
||||
|
||||
|
||||
subprocess_args = [
|
||||
'git', '-C', str(args.git_root),
|
||||
'commit', '--amend', '--no-edit',
|
||||
'--author', args.author,
|
||||
'--trailer', 'Signed-off-by: ' + args.author
|
||||
]
|
||||
if args.remove_existing_signoffs:
|
||||
clean_msg = remove_signoffs(args)
|
||||
subprocess_args.extend(['-m', clean_msg])
|
||||
try:
|
||||
subprocess.run(
|
||||
subprocess_args,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f'Git amend failed with error:: {e.stderr}')
|
||||
exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
67
tools/EVerest-main/applications/utils/scripts/parsebb.py
Executable file
67
tools/EVerest-main/applications/utils/scripts/parsebb.py
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright Pionix GmbH and Contributors to EVerest
|
||||
#
|
||||
"""
|
||||
author: kai-uwe.hermann@pionix.de
|
||||
Parse .bb files and extract git information as json
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='extracts git url and rev from .bb files')
|
||||
|
||||
parser.add_argument('--input',
|
||||
dest='in_bb',
|
||||
help='Path to the .bb file')
|
||||
parser.add_argument('--file',
|
||||
dest='in_file',
|
||||
help='Relative path to the repo')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
in_bb = os.path.realpath(os.path.expanduser(args.in_bb))
|
||||
in_rel_path = args.in_file
|
||||
|
||||
bb = None
|
||||
try:
|
||||
bb_file = open(in_bb, 'r')
|
||||
except Exception:
|
||||
return
|
||||
|
||||
output = {}
|
||||
|
||||
with bb_file as f:
|
||||
bb = f.read()
|
||||
bbvars = re.findall(r'^.+=[^=]+\n', bb, flags=re.MULTILINE)
|
||||
for variable in bbvars:
|
||||
variable_search = re.search(r'([a-zA-Z_]*)\s?=\s?\"([^\s]*)', variable)
|
||||
if variable_search:
|
||||
name = variable_search.group(1)
|
||||
value = variable_search.group(2)
|
||||
if name == 'SRC_URI':
|
||||
src_uri_search = re.search(r'git:\/\/([^;]*);branch=([^;]*)', value)
|
||||
if src_uri_search:
|
||||
repo = f'https://{src_uri_search.group(1)}'
|
||||
branch = src_uri_search.group(2)
|
||||
output['repo'] = repo
|
||||
output['branch'] = branch
|
||||
if name == 'SRCREV':
|
||||
src_rev_search = re.search(r'([^;]*)\"', value)
|
||||
if src_rev_search:
|
||||
rev = src_rev_search.group(1)
|
||||
output['rev'] = rev
|
||||
output['url'] = output['repo'].replace('.git', '/').replace('github.com/', 'raw.githubusercontent.com/')
|
||||
output['url'] += output['rev'] + '/' + in_rel_path
|
||||
print(f'{json.dumps(output)}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
80
tools/EVerest-main/applications/utils/scripts/replace_license.py
Executable file
80
tools/EVerest-main/applications/utils/scripts/replace_license.py
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright Pionix GmbH and Contributors to EVerest
|
||||
#
|
||||
"""
|
||||
author: kai-uwe.hermann@pionix.de
|
||||
Replace licenses with Apache 2.0
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='replaces licenses with Apache 2.0')
|
||||
|
||||
parser.add_argument('--working-dir', '-wd', type=str,
|
||||
help='Working directory (default: .)', default=str(Path.cwd()))
|
||||
parser.add_argument('--no-year', action='store_true', help='Do not include years in license header')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
working_dir = Path(args.working_dir).expanduser().resolve()
|
||||
|
||||
files = [file for file in working_dir.rglob('*') if file.suffix in ['.cpp', '.hpp']]
|
||||
|
||||
year = ''
|
||||
if not args.no_year:
|
||||
year = f'2020 - {date.today().year} '
|
||||
|
||||
license_text = f"""// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright {year}Pionix GmbH and Contributors to EVerest
|
||||
"""
|
||||
|
||||
success = 0
|
||||
failure = 0
|
||||
count = len(files)
|
||||
|
||||
for file in files:
|
||||
content = file.read_text()
|
||||
if content.startswith('/*'):
|
||||
needle = '*/\n'
|
||||
end = content.find(needle) + len(needle)
|
||||
new_content = license_text + content[end:]
|
||||
file.write_text(new_content)
|
||||
print(f'Modified {file} with new license header')
|
||||
success += 1
|
||||
else:
|
||||
content_lines = content.splitlines()
|
||||
end = 0
|
||||
for line in content_lines:
|
||||
if line.startswith('//'):
|
||||
end += 1
|
||||
else:
|
||||
break
|
||||
new_content = license_text + '\n'.join(content_lines[end:]) + '\n'
|
||||
file.write_text(new_content)
|
||||
success += 1
|
||||
|
||||
if success != count:
|
||||
print('ERROR during license replacement')
|
||||
else:
|
||||
print('Everything went well')
|
||||
|
||||
manifest_files = [file for file in working_dir.rglob('*') if file.name == 'manifest.yaml']
|
||||
for file in manifest_files:
|
||||
manifest = file.read_text()
|
||||
needle = 'license:'
|
||||
start = manifest.find(needle)
|
||||
end = manifest.find('\n', start+len(needle))
|
||||
new_manifest = manifest[:start] + 'license: https://opensource.org/licenses/Apache-2.0' + manifest[end:]
|
||||
file.write_text(new_manifest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
118
tools/EVerest-main/applications/utils/scripts/snapshot2bb.py
Executable file
118
tools/EVerest-main/applications/utils/scripts/snapshot2bb.py
Executable file
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright Pionix GmbH and Contributors to EVerest
|
||||
#
|
||||
"""
|
||||
author: kai-uwe.hermann@pionix.de
|
||||
Parse snapshot.yaml files and modify corresponding .bb recipes
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='modify .bb files based on a snapshot')
|
||||
|
||||
parser.add_argument('--input',
|
||||
dest='in_snapshot',
|
||||
help='Path to the snapshot.yaml file')
|
||||
parser.add_argument('--out',
|
||||
dest='out_dir',
|
||||
help='Relative path to meta-everest')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
in_snapshot = os.path.realpath(os.path.expanduser(args.in_snapshot))
|
||||
out_dir = Path(os.path.realpath(os.path.expanduser(args.out_dir)))
|
||||
|
||||
snapshot = None
|
||||
with open(in_snapshot, encoding='utf-8') as snapshot_file:
|
||||
try:
|
||||
snapshot = yaml.safe_load(snapshot_file)
|
||||
except yaml.YAMLError as e:
|
||||
print(f"Error parsing yaml of {in_snapshot}: {e}")
|
||||
return
|
||||
|
||||
if not snapshot:
|
||||
print(f"snapshot empty?")
|
||||
return
|
||||
|
||||
output = {}
|
||||
|
||||
print(f"got snapshot: {snapshot}")
|
||||
|
||||
recipes_core = out_dir / 'recipes-core'
|
||||
if not recipes_core.exists():
|
||||
print(f"cannot find recipes-core in {recipes_core}")
|
||||
return
|
||||
|
||||
# TODO: provide this via a file as a command line parameter
|
||||
mapping = {'Josev': 'josev/python3-iso15118',
|
||||
'everest-utils': 'everest-devtools/evcli',
|
||||
'EVerest': 'everest/everest-core',
|
||||
'everest-framework': 'everest/everest-framework',
|
||||
'everest-sqlite': 'everest/everest-sqlite',
|
||||
'libcbv2g': 'everest/libcbv2g',
|
||||
'libevse-security': 'everest/libevse-security',
|
||||
'libfsm': 'everest/libfsm',
|
||||
'libiso15118': 'everest/libiso15118',
|
||||
'liblog': 'everest/liblog',
|
||||
'libnfc-nci': 'everest/libnfc-nci',
|
||||
'libocpp': 'everest/libocpp',
|
||||
'libslac': 'everest/libslac',
|
||||
'libtimer': 'everest/libtimer'}
|
||||
|
||||
branch_re = re.compile(r'branch=([^;|^"|\s]*)')
|
||||
|
||||
for key, entry in snapshot.items():
|
||||
print(f"key: {key}")
|
||||
branch = entry['branch']
|
||||
git_rev = entry['git_rev']
|
||||
git_tag = entry['git_tag']
|
||||
version = git_tag.removeprefix('wip-release-')
|
||||
version = version.removeprefix('v')
|
||||
version_without_rc, _vsep, _rc = version.partition('-')
|
||||
# todo: maybe even strip something like "wip-release-" from git_tag to keep versions sane?
|
||||
# or just do not modify the version if this cannot be parsed properly?
|
||||
print(f"version: {version} without-rc: {version_without_rc}")
|
||||
if key in mapping:
|
||||
file_glob = f'{mapping[key]}_*.bb'
|
||||
files = list(recipes_core.glob(file_glob))
|
||||
if len(files) == 1:
|
||||
bb_path = files[0]
|
||||
|
||||
print(f"found a matching file: {bb_path}")
|
||||
with open(bb_path) as bb_file:
|
||||
bb_content = bb_file.read().splitlines()
|
||||
bb_content_modified = []
|
||||
for index, line in enumerate(bb_content):
|
||||
if line.startswith("SRC_URI"):
|
||||
def replace(match):
|
||||
return f'branch={branch}'
|
||||
line = branch_re.sub(replace, line)
|
||||
elif line.startswith("SRCREV"):
|
||||
line = f"SRCREV = \"{git_rev}\""
|
||||
|
||||
bb_content_modified.append(line)
|
||||
# create new filename
|
||||
prefix, sep, postfix = bb_path.name.partition('_')
|
||||
new_filename = f'{prefix}_{version_without_rc}.bb'
|
||||
new_bb_path = bb_path.parent / new_filename
|
||||
if bb_path != new_bb_path:
|
||||
print(f"filename is different, so remove the old one")
|
||||
bb_path.unlink(missing_ok=True)
|
||||
|
||||
print(f"writing bb file: {new_bb_path}")
|
||||
with open(new_bb_path, mode='w+') as new_bb_file:
|
||||
new_bb_file.write('\n'.join(bb_content_modified))
|
||||
new_bb_file.write('\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user