core.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2009, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 
00034 from __future__ import print_function
00035 
00036 import os
00037 import sys
00038 
00039 import rospkg
00040 import pkg_resources
00041 
00042 def print_warning(msg):
00043     """print warning to screen (bold red)"""
00044     print('\033[31m%s\033[0m'%msg, file=sys.stderr)
00045     
00046 def author_name():
00047     """
00048     Utility to compute logged in user name
00049     
00050     :returns: name of current user, ``str``
00051     """
00052     import getpass
00053     name = getpass.getuser()
00054     try:
00055         import pwd
00056         login = name
00057         name = pwd.getpwnam(login)[4]
00058         name = ''.join(name.split(',')) # strip commas
00059         # in case pwnam is not set
00060         if not name:
00061             name = login
00062     except:
00063         #pwd failed
00064         pass
00065     if type(name) == str:
00066         name = name.decode('utf-8')
00067     return name
00068 
00069 def read_template(tmplf):
00070     """
00071     Read resource template from egg installation, or fallback on rospkg otherwise.
00072 
00073     :returns: text of template file
00074     """
00075     if pkg_resources.resource_exists('roscreate', tmplf):
00076         f = pkg_resources.resource_stream('roscreate', tmplf)
00077         t = f.read()
00078     else:
00079         # fallback on rospkg
00080         r = rospkg.RosPack()
00081         with open(os.path.join(r.get_path('roscreate'), 'templates', tmplf)) as f:
00082             t = f.read()
00083     if type(t) == str:
00084         t = t.decode('utf-8')
00085     return t
00086 
00087     


roscreate
Author(s): Ken Conley
autogenerated on Thu Aug 27 2015 14:46:45