starting rospkg port, py3k
This commit is contained in:
parent
116e7fa247
commit
ccf48ec9cc
|
@ -33,27 +33,17 @@
|
|||
#
|
||||
# Revision $Id$
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import roslib.rosenv
|
||||
import roslib.packages
|
||||
|
||||
def print_warning(msg):
|
||||
"""print warning to screen (bold red)"""
|
||||
print >> sys.stderr, '\033[31m%s\033[0m'%msg
|
||||
print('\033[31m%s\033[0m'%msg, file=sys.stderr)
|
||||
|
||||
def on_ros_path(p):
|
||||
"""
|
||||
@param p: path
|
||||
@type p: str
|
||||
@return: True if p is on the ROS path (ROS_ROOT, ROS_PACKAGE_PATH)
|
||||
"""
|
||||
pkg = os.path.realpath(roslib.rosenv.resolve_path(p))
|
||||
paths = [p for p in roslib.packages.get_package_paths()]
|
||||
paths = [os.path.realpath(roslib.rosenv.resolve_path(x)) for x in paths]
|
||||
return bool([x for x in paths if pkg == x or pkg.startswith(x + os.sep)])
|
||||
|
||||
# utility to compute logged in user name
|
||||
def author_name():
|
||||
import getpass
|
||||
|
@ -70,10 +60,7 @@ def author_name():
|
|||
|
||||
def read_template(tmplf):
|
||||
p = os.path.join(roslib.packages.get_pkg_dir('roscreate'), tmplf)
|
||||
f = open(p, 'r')
|
||||
try:
|
||||
with open(p, 'r') as f:
|
||||
t = f.read()
|
||||
finally:
|
||||
f.close()
|
||||
return t
|
||||
|
||||
|
|
|
@ -33,15 +33,19 @@
|
|||
#
|
||||
# Revision $Id$
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import roslib; roslib.load_manifest('roscreate')
|
||||
|
||||
NAME='roscreate-pkg'
|
||||
|
||||
import os
|
||||
import sys
|
||||
import roslib.packages
|
||||
|
||||
from roscreate.core import read_template, author_name, on_ros_path
|
||||
import roslib.names
|
||||
|
||||
from roscreate.core import read_template, author_name
|
||||
from rospkg import on_ros_path, RosPack, ResourceNotFound
|
||||
|
||||
def get_templates():
|
||||
templates = {}
|
||||
|
@ -57,21 +61,21 @@ def instantiate_template(template, package, brief, description, author, depends)
|
|||
def create_package(package, author, depends, uses_roscpp=False, uses_rospy=False):
|
||||
p = os.path.abspath(package)
|
||||
if os.path.exists(p):
|
||||
print >> sys.stderr, "%s already exists, aborting"%p
|
||||
print("%s already exists, aborting"%p, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
os.makedirs(p)
|
||||
print "Created package directory", p
|
||||
print("Created package directory", p)
|
||||
|
||||
if uses_roscpp:
|
||||
# create package/include/package and package/src for roscpp code
|
||||
cpp_path = os.path.join(p, 'include', package)
|
||||
try:
|
||||
os.makedirs(cpp_path)
|
||||
print "Created include directory", cpp_path
|
||||
print("Created include directory", cpp_path)
|
||||
cpp_path = os.path.join(p, 'src')
|
||||
os.makedirs(cpp_path)
|
||||
print "Created cpp source directory", cpp_path
|
||||
print("Created cpp source directory", cpp_path)
|
||||
except:
|
||||
# file exists
|
||||
pass
|
||||
|
@ -80,7 +84,7 @@ def create_package(package, author, depends, uses_roscpp=False, uses_rospy=False
|
|||
py_path = os.path.join(p, 'src')
|
||||
try:
|
||||
os.makedirs(py_path)
|
||||
print "Created python source directory", py_path
|
||||
print("Created python source directory", py_path)
|
||||
except:
|
||||
# file exists
|
||||
pass
|
||||
|
@ -88,14 +92,11 @@ def create_package(package, author, depends, uses_roscpp=False, uses_rospy=False
|
|||
templates = get_templates()
|
||||
for filename, template in templates.iteritems():
|
||||
contents = instantiate_template(template, package, package, package, author, depends)
|
||||
try:
|
||||
p = os.path.abspath(os.path.join(package, filename))
|
||||
f = open(p, 'w')
|
||||
p = os.path.abspath(os.path.join(package, filename))
|
||||
with open(p, 'w') as f:
|
||||
f.write(contents)
|
||||
print "Created package file", p
|
||||
finally:
|
||||
f.close()
|
||||
print "\nPlease edit %s/manifest.xml and mainpage.dox to finish creating your package"%package
|
||||
print("Created package file", p)
|
||||
print("\nPlease edit %s/manifest.xml and mainpage.dox to finish creating your package"%package)
|
||||
|
||||
def roscreatepkg_main():
|
||||
from optparse import OptionParser
|
||||
|
@ -112,17 +113,18 @@ def roscreatepkg_main():
|
|||
depends = args[1:]
|
||||
uses_roscpp = 'roscpp' in depends
|
||||
uses_rospy = 'rospy' in depends
|
||||
|
||||
|
||||
rospack = RosPack()
|
||||
for d in depends:
|
||||
try:
|
||||
roslib.packages.get_pkg_dir(d)
|
||||
except roslib.packages.InvalidROSPkgException:
|
||||
print >> sys.stderr, "ERROR: dependency [%s] cannot be found"%d
|
||||
rospack.get_path(d)
|
||||
except ResourceNotFound:
|
||||
print("ERROR: dependency [%s] cannot be found"%d, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
depends = ''.join([' <depend package="%s"/>\n'%d for d in depends])
|
||||
|
||||
if not on_ros_path(os.getcwd()):
|
||||
print >> sys.stderr, '!'*80+"\nWARNING: current working directory is not on ROS_PACKAGE_PATH!\nPlease update your ROS_PACKAGE_PATH environment variable.\n"+'!'*80
|
||||
print('!'*80+"\nWARNING: current working directory is not on ROS_PACKAGE_PATH!\nPlease update your ROS_PACKAGE_PATH environment variable.\n"+'!'*80, file=sys.stderr)
|
||||
create_package(package, author_name(), depends, uses_roscpp=uses_roscpp, uses_rospy=uses_rospy)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -40,7 +40,7 @@ The focus of this module is on supporting the command-line tool. The
|
|||
code API of this module is *not* stable.
|
||||
"""
|
||||
|
||||
from __future__ import with_statement
|
||||
from __future__ import print_function
|
||||
import roslib; roslib.load_manifest('roscreate')
|
||||
|
||||
NAME='roscreate-stack'
|
||||
|
@ -52,7 +52,8 @@ import roslib.packages
|
|||
import roslib.stacks
|
||||
import roslib.stack_manifest
|
||||
|
||||
from roscreate.core import read_template, author_name, print_warning, on_ros_path
|
||||
from roscreate.core import read_template, author_name, print_warning
|
||||
from rospkg import on_ros_path
|
||||
|
||||
def get_templates():
|
||||
"""
|
||||
|
@ -98,7 +99,7 @@ def create_stack(stack, stack_dir, stack_manifest, author, depends, licenses, sh
|
|||
"""
|
||||
|
||||
if show_deps:
|
||||
print ''.join([' <depend stack="%s"/> <!-- %s --> \n'%(s, ', '.join(set(pkgs))) for s, pkgs in depends.iteritems()])
|
||||
print(''.join([' <depend stack="%s"/> <!-- %s --> \n'%(s, ', '.join(set(pkgs))) for s, pkgs in depends.iteritems()]))
|
||||
return
|
||||
|
||||
# load existing properties
|
||||
|
@ -119,7 +120,7 @@ def create_stack(stack, stack_dir, stack_manifest, author, depends, licenses, sh
|
|||
|
||||
p = os.path.abspath(stack_dir)
|
||||
if not os.path.exists(p):
|
||||
print "Creating stack directory", p
|
||||
print("Creating stack directory", p)
|
||||
os.makedirs(p)
|
||||
|
||||
templates = get_templates()
|
||||
|
@ -127,10 +128,10 @@ def create_stack(stack, stack_dir, stack_manifest, author, depends, licenses, sh
|
|||
contents = instantiate_template(template, stack, brief, description, author, depends, licenses, review)
|
||||
p = os.path.abspath(os.path.join(stack_dir, filename))
|
||||
if not os.path.exists(filename) or filename == 'stack.xml':
|
||||
print "Creating stack file", p
|
||||
print("Creating stack file", p)
|
||||
with open(p, 'w') as f:
|
||||
f.write(contents.encode('utf-8'))
|
||||
print "\nPlease edit %s/stack.xml to finish creating your stack"%stack
|
||||
print("\nPlease edit %s/stack.xml to finish creating your stack"%stack)
|
||||
|
||||
def compute_stack_depends_and_licenses(stack_dir):
|
||||
"""
|
||||
|
@ -202,13 +203,13 @@ def roscreatestack_main():
|
|||
stack = os.path.basename(os.path.abspath(stack_dir))
|
||||
|
||||
if not on_ros_path(stack_dir):
|
||||
print >> sys.stderr, "ERROR: roscreate-stack only work in directories in ROS_PACKAGE_PATH\nPlease update your ROS_PACKAGE_PATH environment variable."
|
||||
print("ERROR: roscreate-stack only work in directories in ROS_PACKAGE_PATH\nPlease update your ROS_PACKAGE_PATH environment variable.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
depends, licenses = compute_stack_depends_and_licenses(stack_dir)
|
||||
except roslib.packages.InvalidROSPkgException, e:
|
||||
print >> sys.stderr, str(e)
|
||||
except roslib.packages.InvalidROSPkgException as e:
|
||||
print(str(e), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# defaults
|
||||
|
@ -221,7 +222,7 @@ def roscreatestack_main():
|
|||
if os.path.exists(stack_xml_path):
|
||||
import shutil
|
||||
stack_xml_path_bak = os.path.join(stack_dir, 'stack.xml.bak')
|
||||
print 'Backing up existing stack.xml to %s'%(stack_xml_path_bak)
|
||||
print('Backing up existing stack.xml to %s'%(stack_xml_path_bak))
|
||||
shutil.copyfile(stack_xml_path, stack_xml_path_bak)
|
||||
|
||||
# load existing stack.xml properties
|
||||
|
|
Loading…
Reference in New Issue