From 22c2ba09793523e38fbcdd6446e7e0cd66c10d4f Mon Sep 17 00:00:00 2001 From: Ken Conley Date: Tue, 28 Feb 2012 18:44:35 +0000 Subject: [PATCH] #3866: author_name() wasn't strict about returning unicode. Converted everything to be unicode-centric to fix these issues --- tools/roscreate/src/roscreate/core.py | 6 ++++-- tools/roscreate/src/roscreate/roscreatepkg.py | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/roscreate/src/roscreate/core.py b/tools/roscreate/src/roscreate/core.py index 3bf80730..fbccd76d 100644 --- a/tools/roscreate/src/roscreate/core.py +++ b/tools/roscreate/src/roscreate/core.py @@ -59,11 +59,11 @@ def author_name(): # in case pwnam is not set if not name: name = login - elif type(name) == str: - name = name.decode('utf-8') except: #pwd failed pass + if type(name) == str: + name = name.decode('utf-8') return name def read_template(tmplf): @@ -80,6 +80,8 @@ def read_template(tmplf): r = rospkg.RosPack() with open(os.path.join(r.get_path('roscreate'), 'templates', tmplf)) as f: t = f.read() + if type(t) == str: + t = t.decode('utf-8') return t diff --git a/tools/roscreate/src/roscreate/roscreatepkg.py b/tools/roscreate/src/roscreate/roscreatepkg.py index 8c91886d..45a49b5f 100755 --- a/tools/roscreate/src/roscreate/roscreatepkg.py +++ b/tools/roscreate/src/roscreate/roscreatepkg.py @@ -91,7 +91,7 @@ def create_package(package, author, depends, uses_roscpp=False, uses_rospy=False contents = instantiate_template(template, package, package, package, author, depends) p = os.path.abspath(os.path.join(package, filename)) with open(p, 'w') as f: - f.write(contents) + f.write(contents.encode('utf-8')) print("Created package file", p) print("\nPlease edit %s/manifest.xml and mainpage.dox to finish creating your package"%package) @@ -118,8 +118,11 @@ def roscreatepkg_main(): except ResourceNotFound: print("ERROR: dependency [%s] cannot be found"%d, file=sys.stderr) sys.exit(1) - depends = ''.join([' \n'%d for d in depends]) + + depends = u''.join([u' \n'%d for d in depends]) if not on_ros_path(os.getcwd()): 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) + if type(package) == str: + package = package.decode('utf-8') create_package(package, author_name(), depends, uses_roscpp=uses_roscpp, uses_rospy=uses_rospy)