mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 04:13:34 +08:00
Python 2.7 compatibility
This commit is contained in:
@@ -4,10 +4,17 @@
|
||||
# Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
#
|
||||
|
||||
from __future__ import division, absolute_import, print_function, unicode_literals
|
||||
import sys, os, logging, errno
|
||||
from mako.template import Template
|
||||
from pyuavcan import dsdl
|
||||
|
||||
# Python 2.7 compatibility
|
||||
try:
|
||||
str = unicode
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
OUTPUT_FILE_EXTENSION = 'hpp'
|
||||
OUTPUT_FILE_PERMISSIONS = 0o444 # Read only for all
|
||||
TEMPLATE_FILENAME = os.path.join(os.path.dirname(__file__), 'data_type_template.tmpl')
|
||||
@@ -22,7 +29,7 @@ logger = logging.getLogger(__name__)
|
||||
def run(source_dirs, include_dirs, output_dir):
|
||||
assert isinstance(source_dirs, list)
|
||||
assert isinstance(include_dirs, list)
|
||||
assert isinstance(output_dir, str)
|
||||
output_dir = str(output_dir)
|
||||
|
||||
types = run_parser(source_dirs, include_dirs + source_dirs)
|
||||
if not types:
|
||||
@@ -44,7 +51,10 @@ def type_output_filename(t):
|
||||
|
||||
def makedirs(path):
|
||||
try:
|
||||
os.makedirs(path, exist_ok=True) # May throw "File exists" when executed as root, which is wrong
|
||||
try:
|
||||
os.makedirs(path, exist_ok=True) # May throw "File exists" when executed as root, which is wrong
|
||||
except TypeError:
|
||||
os.makedirs(path) # Python 2.7 compatibility
|
||||
except OSError as ex:
|
||||
if ex.errno != errno.EEXIST: # http://stackoverflow.com/questions/12468022
|
||||
raise
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# UAVCAN DSDL compiler for libuavcan
|
||||
# Written in Python 3, compatible with Python 2.7
|
||||
#
|
||||
# Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
#
|
||||
|
||||
from __future__ import division, absolute_import, print_function, unicode_literals
|
||||
import os, sys, logging, argparse
|
||||
|
||||
RUNNING_FROM_SRC_DIR = os.path.abspath(__file__).endswith(os.path.join('libuavcan', 'dsdl_compiler', 'libuavcan_dsdlc'))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python
|
||||
|
||||
from distutils.core import setup
|
||||
|
||||
|
||||
Reference in New Issue
Block a user