2017-07-02 09:43:13 -03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
############################################################################
|
|
|
|
#
|
2020-04-20 10:19:18 -03:00
|
|
|
# Copyright (c) 2017-2020 PX4 Development Team. All rights reserved.
|
2017-07-02 09:43:13 -03:00
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. 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.
|
|
|
|
# 3. Neither the name PX4 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.
|
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
2020-04-20 10:19:18 -03:00
|
|
|
"""
|
|
|
|
Basic central executable for PX4 maintenance.
|
2020-04-20 12:46:13 -03:00
|
|
|
Used by PX4 Homebrew formulae - https://github.com/PX4/homebrew-px4.
|
2020-04-20 10:19:18 -03:00
|
|
|
"""
|
2017-07-02 09:43:13 -03:00
|
|
|
|
2020-04-20 10:19:18 -03:00
|
|
|
# For python2.7 compatibility
|
2017-07-02 09:43:13 -03:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import argparse
|
2020-04-20 10:19:18 -03:00
|
|
|
import array
|
|
|
|
import base64
|
2017-07-02 09:43:13 -03:00
|
|
|
import binascii
|
2020-04-20 10:19:18 -03:00
|
|
|
import json
|
|
|
|
import os
|
2017-07-02 09:43:13 -03:00
|
|
|
import serial
|
|
|
|
import socket
|
|
|
|
import struct
|
2020-04-20 10:19:18 -03:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2017-07-02 09:43:13 -03:00
|
|
|
import time
|
2020-04-20 10:19:18 -03:00
|
|
|
import zlib
|
2017-07-02 09:43:13 -03:00
|
|
|
|
|
|
|
from sys import platform as _platform
|
|
|
|
|
2020-04-20 10:19:18 -03:00
|
|
|
|
|
|
|
def get_version():
|
|
|
|
"""
|
|
|
|
Get PX4 Firmware latest Git tag.
|
|
|
|
"""
|
|
|
|
px4_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
|
|
if os.path.isdir(os.path.join(px4_dir, '.git')):
|
2020-04-20 10:37:14 -03:00
|
|
|
# If inside a clone PX4 Firmware repository, get version from "git describe"
|
|
|
|
cmd = 'git describe --abbrev=0 --tags'
|
2020-04-20 10:19:18 -03:00
|
|
|
try:
|
|
|
|
version = subprocess.check_output(
|
2020-04-20 10:37:14 -03:00
|
|
|
cmd, cwd=px4_dir, shell=True).decode().strip()
|
2020-04-20 10:19:18 -03:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print('Unable to get version number from git tags')
|
|
|
|
exit(1)
|
2020-04-20 10:37:14 -03:00
|
|
|
else:
|
|
|
|
# Else, get it from remote repo tags (requires network access)
|
|
|
|
cmd = "git ls-remote --tags git://github.com/PX4/Firmware.git | cut -d/ -f3- | sort -n -t. -k1,1 -k2,2 -k3,3 | awk '/^v[^{]*$/{version=$1}END{print version}'"
|
2020-04-20 10:19:18 -03:00
|
|
|
|
2020-04-20 10:37:14 -03:00
|
|
|
try:
|
|
|
|
version = subprocess.check_output(
|
|
|
|
cmd, cwd=px4_dir, shell=True).decode().strip()
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print('Unable to get version number from git remote tags')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
return version
|
2020-04-20 10:19:18 -03:00
|
|
|
|
|
|
|
|
2017-07-02 09:43:13 -03:00
|
|
|
# Detect python version
|
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
runningPython3 = False
|
|
|
|
else:
|
|
|
|
runningPython3 = True
|
|
|
|
|
2020-04-20 10:19:18 -03:00
|
|
|
|
2017-07-02 09:43:13 -03:00
|
|
|
def main():
|
2020-04-20 10:19:18 -03:00
|
|
|
print("PX4 release", get_version())
|
2017-07-02 09:43:13 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|