Tools: use Python 3, improve import checks

In more detail:
- Change shebang to Python 3.
- Suggest installation using pip3 as user.
This commit is contained in:
Julian Oes 2020-01-15 10:27:15 +01:00
parent e98fa891fe
commit b04f68553e
7 changed files with 63 additions and 36 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Open a shell over MAVLink.
@ -11,16 +11,27 @@ from __future__ import print_function
import sys, select
import termios
from timeit import default_timer as timer
from argparse import ArgumentParser
try:
from pymavlink import mavutil
import serial
except:
print("Failed to import pymavlink.")
print("You may need to install it with 'pip install pymavlink pyserial'")
except ImportError as e:
print("Failed to import pymavlink: " + e)
print("")
raise
from argparse import ArgumentParser
print("You may need to install it with:")
print(" pip3 install --user pymavlink")
print("")
sys.exit(1)
try:
import serial
except ImportError as e:
print("Failed to import pyserial: " + e)
print("")
print("You may need to install it with:")
print(" pip3 install --user pyserial")
print("")
sys.exit(1)
class MavlinkSerialPort():

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Stream ULog data over MAVLink.
@ -12,15 +12,17 @@ import sys, select, os
import datetime
from timeit import default_timer as timer
os.environ['MAVLINK20'] = '1' # The commands require mavlink 2
from argparse import ArgumentParser
try:
from pymavlink import mavutil
except:
print("Failed to import pymavlink.")
print("You may need to install it with 'pip install pymavlink pyserial'")
except ImportError as e:
print("Failed to import pymavlink: " + e)
print("")
raise
from argparse import ArgumentParser
print("You may need to install it with:")
print(" pip3 install --user pymavlink")
print("")
sys.exit(1)
class MavlinkLogStreaming():

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
############################################################################
#
# Copyright (c) 2012-2017 PX4 Development Team. All rights reserved.
@ -742,7 +742,10 @@ def main():
if not pyserial_installed:
print("Error: pyserial not installed!")
print(" (Install using: sudo pip install pyserial)")
print("")
print("You may need to install it using:")
print(" pip3 install --user pyserial")
print("")
sys.exit(1)
# Load the firmware file

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python
#!/usr/bin/env python3
""" Script to generate Serial (UART) parameters and the ROMFS startup script """
from __future__ import print_function
@ -11,11 +11,13 @@ from jinja2 import Environment, FileSystemLoader
try:
import yaml
except:
print("Failed to import yaml.")
print("You may need to install it with 'sudo pip install pyyaml'")
except ImportError as e:
print("Failed to import yaml: " + e)
print("")
raise
print("You may need to install it using:")
print(" pip3 install --user pyyaml")
print("")
sys.exit(1)
## Configuration

View File

@ -8,6 +8,7 @@ import codecs
import re
import colorsys
import json
import sys
parser = argparse.ArgumentParser(
@ -609,11 +610,13 @@ if args.output == 'json':
elif args.output == 'graphviz':
try:
from graphviz import Digraph
except:
print("Failed to import graphviz.")
print("You may need to install it with 'pip install graphviz'")
except ImportError as e:
print("Failed to import graphviz: " + e)
print("")
raise
print("You may need to install it with:")
print(" pip3 install --user graphviz")
print("")
sys.exit(1)
output_graphviz = OutputGraphviz(graph)
engine='fdp' # use neato or fdp
output_graphviz.write(args.file+'.fv', engine=engine)

View File

@ -16,11 +16,13 @@ import sys
try:
import requests
except:
print("Failed to import requests.")
print("You may need to install it with 'pip install requests'")
except ImportError as e:
print("Failed to import requests: " + e)
print("")
raise
print("You may need to install it using:")
print(" pip3 install --user requests")
print("")
sys.exit(1)
SERVER = 'https://logs.px4.io'

View File

@ -9,19 +9,23 @@ import sys
try:
import yaml
except:
print("Failed to import yaml.")
print("You may need to install it with 'sudo pip install pyyaml'")
except ImportError as e:
print("Failed to import yaml: " + e)
print("")
raise
print("You may need to install it using:")
print(" pip3 install --user pyyaml")
print("")
sys.exit(1)
try:
import cerberus
except:
print("Failed to import cerberus.")
print("You may need to install it with 'sudo pip install cerberus'")
except ImportError as e:
print("Failed to import cerberus: " + e)
print("")
raise
print("You may need to install it using:")
print(" pip3 install --user cerberus")
print("")
sys.exit(1)
parser = argparse.ArgumentParser(description='Validate YAML file(s) against a schema')