We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
roslaunch does not accept a package name if a file with the same name exists in the current directory
Reproduce with:

```
roscreate-pkg roslaunch_test
cd roslaunch_test
mkdir bin
mkdir launch
touch bin/roslaunch_test
echo "<launch/>" > launch/example.launch
cd bin
roslaunch roslaunch_test example.launch
```

Error output:

```
Usage: roslaunch [options] [package] <filename> [arg_name:=value...]

roslaunch: error: The following input files do not exist: example.launch
```

Without the file in `bin/` or with another working directory roslaunch executes without errors (and exits immediately as there are no nodes).

I am using roslaunch 1.9.47 installed from the binary package repository in ROS hydro.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tools/roslaunch/src/roslaunch/rlutil.py`
Content:
```
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2009, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 #  * Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 #  * Redistributions in binary form must reproduce the above
13 #    copyright notice, this list of conditions and the following
14 #    disclaimer in the documentation and/or other materials provided
15 #    with the distribution.
16 #  * Neither the name of Willow Garage, Inc. nor the names of its
17 #    contributors may be used to endorse or promote products derived
18 #    from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 """
34 Uncategorized utility routines for roslaunch.
35 
36 This API should not be considered stable.
37 """
38 
39 from __future__ import print_function
40 
41 import os
42 import sys
43 import time
44 
45 import roslib.packages
46 
47 import rosclean
48 import rospkg
49 import rosgraph
50 
51 import roslaunch.core
52 import roslaunch.config
53 import roslaunch.depends
54 from rosmaster import DEFAULT_MASTER_PORT
55 
56 def check_log_disk_usage():
57     """
58     Check size of log directory. If high, print warning to user
59     """
60     try:
61         d = rospkg.get_log_dir()
62         roslaunch.core.printlog("Checking log directory for disk usage. This may take awhile.\nPress Ctrl-C to interrupt") 
63         disk_usage = rosclean.get_disk_usage(d)
64         # warn if over a gig
65         if disk_usage > 1073741824:
66             roslaunch.core.printerrlog("WARNING: disk usage in log directory [%s] is over 1GB.\nIt's recommended that you use the 'rosclean' command."%d)
67         else:
68             roslaunch.core.printlog("Done checking log file disk usage. Usage is <1GB.")            
69     except:
70         pass
71 
72 def resolve_launch_arguments(args):
73     """
74     Resolve command-line args to roslaunch filenames.
75 
76     :returns: resolved filenames, ``[str]``
77     """
78 
79     # strip remapping args for processing
80     args = rosgraph.myargv(args)
81     
82     # user can either specify:
83     #  - filename + launch args
84     #  - package + relative-filename + launch args
85     if not args:
86         return args
87     resolved_args = None
88     top = args[0]
89     if os.path.isfile(top):
90         resolved_args = [top] + args[1:]
91     elif len(args) == 1:
92         raise roslaunch.core.RLException("[%s] does not exist. please specify a package and launch file"%(top))
93     else:
94         try:
95             resolved = roslib.packages.find_resource(top, args[1])
96             if len(resolved) == 1:
97                 resolved = resolved[0]
98             elif len(resolved) > 1:
99                 raise roslaunch.core.RLException("multiple files named [%s] in package [%s]:%s\nPlease specify full path instead" % (args[1], top, ''.join(['\n- %s' % r for r in resolved])))
100         except rospkg.ResourceNotFound as e:
101             raise roslaunch.core.RLException("[%s] is not a package or launch file name"%top)
102         if not resolved:
103             raise roslaunch.core.RLException("cannot locate [%s] in package [%s]"%(args[1], top))
104         else:
105             resolved_args = [resolved] + args[2:]
106     return resolved_args
107 
108 def _wait_for_master():
109     """
110     Block until ROS Master is online
111     
112     :raise: :exc:`RuntimeError` If unexpected error occurs
113     """
114     m = roslaunch.core.Master() # get a handle to the default master
115     is_running = m.is_running()
116     if not is_running:
117         roslaunch.core.printlog("roscore/master is not yet running, will wait for it to start")
118     while not is_running:
119         time.sleep(0.1)
120         is_running = m.is_running()
121     if is_running:
122         roslaunch.core.printlog("master has started, initiating launch")
123     else:
124         raise RuntimeError("unknown error waiting for master to start")
125 
126 _terminal_name = None
127 
128 def _set_terminal(s):
129     import platform
130     if platform.system() in ['FreeBSD', 'Linux', 'Darwin', 'Unix']:
131         try:
132             print('\033]2;%s\007'%(s))
133         except:
134             pass
135     
136 def update_terminal_name(ros_master_uri):
137     """
138     append master URI to the terminal name
139     """
140     if _terminal_name:
141         _set_terminal(_terminal_name + ' ' + ros_master_uri)
142 
143 def change_terminal_name(args, is_core):
144     """
145     use echo (where available) to change the name of the terminal window
146     """
147     global _terminal_name
148     _terminal_name = 'roscore' if is_core else ','.join(args)
149     _set_terminal(_terminal_name)
150 
151 def get_or_generate_uuid(options_runid, options_wait_for_master):
152     """
153     :param options_runid: run_id value from command-line or ``None``, ``str``
154     :param options_wait_for_master: the wait_for_master command
155       option. If this is True, it means that we must retrieve the
156       value from the parameter server and need to avoid any race
157       conditions with the roscore being initialized. ``bool``
158     """
159 
160     # Three possible sources of the run_id:
161     #
162     #  - if we're a child process, we get it from options_runid
163     #  - if there's already a roscore running, read from the param server
164     #  - generate one if we're running the roscore
165     if options_runid:
166         return options_runid
167 
168     # #773: Generate a run_id to use if we launch a master
169     # process.  If a master is already running, we'll get the
170     # run_id from it instead
171     param_server = rosgraph.Master('/roslaunch')
172     val = None
173     while val is None:
174         try:
175             val = param_server.getParam('/run_id')
176         except:
177             if not options_wait_for_master:
178                 val = roslaunch.core.generate_run_id()
179     return val
180     
181 def check_roslaunch(f):
182     """
183     Check roslaunch file for errors, returning error message if check fails. This routine
184     is mainly to support rostest's roslaunch_check.
185 
186     :param f: roslaunch file name, ``str``
187     :returns: error message or ``None``
188     """
189     try:
190         rl_config = roslaunch.config.load_config_default([f], DEFAULT_MASTER_PORT, verbose=False)
191     except roslaunch.core.RLException as e:
192         return str(e)
193     
194     errors = []
195     # check for missing deps
196     base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps([f])
197     for pkg, miss in missing.iteritems():
198         if miss:
199             errors.append("Missing manifest dependencies: %s/manifest.xml: %s"%(pkg, ', '.join(miss)))
200     
201     # load all node defs
202     nodes = []
203     for filename, rldeps in file_deps.iteritems():
204         nodes.extend(rldeps.nodes)
205 
206     # check for missing packages
207     rospack = rospkg.RosPack()
208     for pkg, node_type in nodes:
209         try:
210             rospack.get_path(pkg)
211         except:
212             errors.append("cannot find package [%s] for node [%s]"%(pkg, node_type))
213 
214     # check for missing nodes
215     for pkg, node_type in nodes:
216         try:
217             if not roslib.packages.find_node(pkg, node_type):
218                 errors.append("cannot find node [%s] in package [%s]"%(node_type, pkg))
219         except Exception as e:
220             errors.append("unable to find node [%s/%s]: %s"%(pkg, node_type, str(e)))
221                 
222     # Check for configuration errors, #2889
223     for err in rl_config.config_errors:
224         errors.append('ROSLaunch config error: %s' % err)
225 
226     if errors:
227         return '\n'.join(errors)
228                           
229 def print_file_list(roslaunch_files):
230     """
231     :param roslaunch_files: list of launch files to load, ``str``
232 
233     :returns: list of files involved in processing roslaunch_files, including the files themselves.
234     """
235     from roslaunch.config import load_config_default, get_roscore_filename
236     import roslaunch.xmlloader
237     try:
238         loader = roslaunch.xmlloader.XmlLoader(resolve_anon=True)
239         config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)
240         files = [os.path.abspath(x) for x in set(config.roslaunch_files) - set([get_roscore_filename()])]
241         print('\n'.join(files))
242     except roslaunch.core.RLException as e:
243         print(str(e), file=sys.stderr)
244         sys.exit(1)
245 
246
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/tools/roslaunch/src/roslaunch/rlutil.py b/tools/roslaunch/src/roslaunch/rlutil.py
--- a/tools/roslaunch/src/roslaunch/rlutil.py
+++ b/tools/roslaunch/src/roslaunch/rlutil.py
@@ -85,24 +85,26 @@
     if not args:
         return args
     resolved_args = None
-    top = args[0]
-    if os.path.isfile(top):
-        resolved_args = [top] + args[1:]
-    elif len(args) == 1:
-        raise roslaunch.core.RLException("[%s] does not exist. please specify a package and launch file"%(top))
-    else:
+
+    # try to resolve launch file in package first
+    if len(args) >= 2:
         try:
-            resolved = roslib.packages.find_resource(top, args[1])
+            resolved = roslib.packages.find_resource(args[0], args[1])
+            if len(resolved) > 1:
+                raise roslaunch.core.RLException("multiple files named [%s] in package [%s]:%s\nPlease specify full path instead" % (args[1], args[0], ''.join(['\n- %s' % r for r in resolved])))
             if len(resolved) == 1:
-                resolved = resolved[0]
-            elif len(resolved) > 1:
-                raise roslaunch.core.RLException("multiple files named [%s] in package [%s]:%s\nPlease specify full path instead" % (args[1], top, ''.join(['\n- %s' % r for r in resolved])))
-        except rospkg.ResourceNotFound as e:
-            raise roslaunch.core.RLException("[%s] is not a package or launch file name"%top)
-        if not resolved:
-            raise roslaunch.core.RLException("cannot locate [%s] in package [%s]"%(args[1], top))
+                resolved_args = [resolved[0]] + args[2:]
+        except rospkg.ResourceNotFound:
+            pass
+    # try to resolve launch file
+    if resolved_args is None and os.path.isfile(args[0]):
+        resolved_args = [args[0]] + args[1:]
+    # raise if unable to resolve
+    if resolved_args is None:
+        if len(args) >= 2:
+            raise roslaunch.core.RLException("[%s] is neither a launch file in package [%s] nor is [%s] a launch file name" % (args[1], args[0], args[0]))
         else:
-            resolved_args = [resolved] + args[2:]
+            raise roslaunch.core.RLException("[%s] is not a launch file name" % args[0])
     return resolved_args
 
 def _wait_for_master():

{"golden_diff": "diff --git a/tools/roslaunch/src/roslaunch/rlutil.py b/tools/roslaunch/src/roslaunch/rlutil.py\n--- a/tools/roslaunch/src/roslaunch/rlutil.py\n+++ b/tools/roslaunch/src/roslaunch/rlutil.py\n@@ -85,24 +85,26 @@\n     if not args:\n         return args\n     resolved_args = None\n-    top = args[0]\n-    if os.path.isfile(top):\n-        resolved_args = [top] + args[1:]\n-    elif len(args) == 1:\n-        raise roslaunch.core.RLException(\"[%s] does not exist. please specify a package and launch file\"%(top))\n-    else:\n+\n+    # try to resolve launch file in package first\n+    if len(args) >= 2:\n         try:\n-            resolved = roslib.packages.find_resource(top, args[1])\n+            resolved = roslib.packages.find_resource(args[0], args[1])\n+            if len(resolved) > 1:\n+                raise roslaunch.core.RLException(\"multiple files named [%s] in package [%s]:%s\\nPlease specify full path instead\" % (args[1], args[0], ''.join(['\\n- %s' % r for r in resolved])))\n             if len(resolved) == 1:\n-                resolved = resolved[0]\n-            elif len(resolved) > 1:\n-                raise roslaunch.core.RLException(\"multiple files named [%s] in package [%s]:%s\\nPlease specify full path instead\" % (args[1], top, ''.join(['\\n- %s' % r for r in resolved])))\n-        except rospkg.ResourceNotFound as e:\n-            raise roslaunch.core.RLException(\"[%s] is not a package or launch file name\"%top)\n-        if not resolved:\n-            raise roslaunch.core.RLException(\"cannot locate [%s] in package [%s]\"%(args[1], top))\n+                resolved_args = [resolved[0]] + args[2:]\n+        except rospkg.ResourceNotFound:\n+            pass\n+    # try to resolve launch file\n+    if resolved_args is None and os.path.isfile(args[0]):\n+        resolved_args = [args[0]] + args[1:]\n+    # raise if unable to resolve\n+    if resolved_args is None:\n+        if len(args) >= 2:\n+            raise roslaunch.core.RLException(\"[%s] is neither a launch file in package [%s] nor is [%s] a launch file name\" % (args[1], args[0], args[0]))\n         else:\n-            resolved_args = [resolved] + args[2:]\n+            raise roslaunch.core.RLException(\"[%s] is not a launch file name\" % args[0])\n     return resolved_args\n \n def _wait_for_master():\n", "issue": "roslaunch does not accept a package name if a file with the same name exists in the current directory\nReproduce with:\n\n```\nroscreate-pkg roslaunch_test\ncd roslaunch_test\nmkdir bin\nmkdir launch\ntouch bin/roslaunch_test\necho \"<launch/>\" > launch/example.launch\ncd bin\nroslaunch roslaunch_test example.launch\n```\n\nError output:\n\n```\nUsage: roslaunch [options] [package] <filename> [arg_name:=value...]\n\nroslaunch: error: The following input files do not exist: example.launch\n```\n\nWithout the file in `bin/` or with another working directory roslaunch executes without errors (and exits immediately as there are no nodes).\n\nI am using roslaunch 1.9.47 installed from the binary package repository in ROS hydro.\n\n", "before_files": [{"content": "# Software License Agreement (BSD License)\n#\n# Copyright (c) 2009, Willow Garage, Inc.\n# All rights reserved.\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions\n# are met:\n#\n#  * Redistributions of source code must retain the above copyright\n#    notice, this list of conditions and the following disclaimer.\n#  * Redistributions in binary form must reproduce the above\n#    copyright notice, this list of conditions and the following\n#    disclaimer in the documentation and/or other materials provided\n#    with the distribution.\n#  * Neither the name of Willow Garage, Inc. nor the names of its\n#    contributors may be used to endorse or promote products derived\n#    from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\n# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\n# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\n# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\n# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n# POSSIBILITY OF SUCH DAMAGE.\n\n\"\"\"\nUncategorized utility routines for roslaunch.\n\nThis API should not be considered stable.\n\"\"\"\n\nfrom __future__ import print_function\n\nimport os\nimport sys\nimport time\n\nimport roslib.packages\n\nimport rosclean\nimport rospkg\nimport rosgraph\n\nimport roslaunch.core\nimport roslaunch.config\nimport roslaunch.depends\nfrom rosmaster import DEFAULT_MASTER_PORT\n\ndef check_log_disk_usage():\n    \"\"\"\n    Check size of log directory. If high, print warning to user\n    \"\"\"\n    try:\n        d = rospkg.get_log_dir()\n        roslaunch.core.printlog(\"Checking log directory for disk usage. This may take awhile.\\nPress Ctrl-C to interrupt\") \n        disk_usage = rosclean.get_disk_usage(d)\n        # warn if over a gig\n        if disk_usage > 1073741824:\n            roslaunch.core.printerrlog(\"WARNING: disk usage in log directory [%s] is over 1GB.\\nIt's recommended that you use the 'rosclean' command.\"%d)\n        else:\n            roslaunch.core.printlog(\"Done checking log file disk usage. Usage is <1GB.\")            \n    except:\n        pass\n\ndef resolve_launch_arguments(args):\n    \"\"\"\n    Resolve command-line args to roslaunch filenames.\n\n    :returns: resolved filenames, ``[str]``\n    \"\"\"\n\n    # strip remapping args for processing\n    args = rosgraph.myargv(args)\n    \n    # user can either specify:\n    #  - filename + launch args\n    #  - package + relative-filename + launch args\n    if not args:\n        return args\n    resolved_args = None\n    top = args[0]\n    if os.path.isfile(top):\n        resolved_args = [top] + args[1:]\n    elif len(args) == 1:\n        raise roslaunch.core.RLException(\"[%s] does not exist. please specify a package and launch file\"%(top))\n    else:\n        try:\n            resolved = roslib.packages.find_resource(top, args[1])\n            if len(resolved) == 1:\n                resolved = resolved[0]\n            elif len(resolved) > 1:\n                raise roslaunch.core.RLException(\"multiple files named [%s] in package [%s]:%s\\nPlease specify full path instead\" % (args[1], top, ''.join(['\\n- %s' % r for r in resolved])))\n        except rospkg.ResourceNotFound as e:\n            raise roslaunch.core.RLException(\"[%s] is not a package or launch file name\"%top)\n        if not resolved:\n            raise roslaunch.core.RLException(\"cannot locate [%s] in package [%s]\"%(args[1], top))\n        else:\n            resolved_args = [resolved] + args[2:]\n    return resolved_args\n\ndef _wait_for_master():\n    \"\"\"\n    Block until ROS Master is online\n    \n    :raise: :exc:`RuntimeError` If unexpected error occurs\n    \"\"\"\n    m = roslaunch.core.Master() # get a handle to the default master\n    is_running = m.is_running()\n    if not is_running:\n        roslaunch.core.printlog(\"roscore/master is not yet running, will wait for it to start\")\n    while not is_running:\n        time.sleep(0.1)\n        is_running = m.is_running()\n    if is_running:\n        roslaunch.core.printlog(\"master has started, initiating launch\")\n    else:\n        raise RuntimeError(\"unknown error waiting for master to start\")\n\n_terminal_name = None\n\ndef _set_terminal(s):\n    import platform\n    if platform.system() in ['FreeBSD', 'Linux', 'Darwin', 'Unix']:\n        try:\n            print('\\033]2;%s\\007'%(s))\n        except:\n            pass\n    \ndef update_terminal_name(ros_master_uri):\n    \"\"\"\n    append master URI to the terminal name\n    \"\"\"\n    if _terminal_name:\n        _set_terminal(_terminal_name + ' ' + ros_master_uri)\n\ndef change_terminal_name(args, is_core):\n    \"\"\"\n    use echo (where available) to change the name of the terminal window\n    \"\"\"\n    global _terminal_name\n    _terminal_name = 'roscore' if is_core else ','.join(args)\n    _set_terminal(_terminal_name)\n\ndef get_or_generate_uuid(options_runid, options_wait_for_master):\n    \"\"\"\n    :param options_runid: run_id value from command-line or ``None``, ``str``\n    :param options_wait_for_master: the wait_for_master command\n      option. If this is True, it means that we must retrieve the\n      value from the parameter server and need to avoid any race\n      conditions with the roscore being initialized. ``bool``\n    \"\"\"\n\n    # Three possible sources of the run_id:\n    #\n    #  - if we're a child process, we get it from options_runid\n    #  - if there's already a roscore running, read from the param server\n    #  - generate one if we're running the roscore\n    if options_runid:\n        return options_runid\n\n    # #773: Generate a run_id to use if we launch a master\n    # process.  If a master is already running, we'll get the\n    # run_id from it instead\n    param_server = rosgraph.Master('/roslaunch')\n    val = None\n    while val is None:\n        try:\n            val = param_server.getParam('/run_id')\n        except:\n            if not options_wait_for_master:\n                val = roslaunch.core.generate_run_id()\n    return val\n    \ndef check_roslaunch(f):\n    \"\"\"\n    Check roslaunch file for errors, returning error message if check fails. This routine\n    is mainly to support rostest's roslaunch_check.\n\n    :param f: roslaunch file name, ``str``\n    :returns: error message or ``None``\n    \"\"\"\n    try:\n        rl_config = roslaunch.config.load_config_default([f], DEFAULT_MASTER_PORT, verbose=False)\n    except roslaunch.core.RLException as e:\n        return str(e)\n    \n    errors = []\n    # check for missing deps\n    base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps([f])\n    for pkg, miss in missing.iteritems():\n        if miss:\n            errors.append(\"Missing manifest dependencies: %s/manifest.xml: %s\"%(pkg, ', '.join(miss)))\n    \n    # load all node defs\n    nodes = []\n    for filename, rldeps in file_deps.iteritems():\n        nodes.extend(rldeps.nodes)\n\n    # check for missing packages\n    rospack = rospkg.RosPack()\n    for pkg, node_type in nodes:\n        try:\n            rospack.get_path(pkg)\n        except:\n            errors.append(\"cannot find package [%s] for node [%s]\"%(pkg, node_type))\n\n    # check for missing nodes\n    for pkg, node_type in nodes:\n        try:\n            if not roslib.packages.find_node(pkg, node_type):\n                errors.append(\"cannot find node [%s] in package [%s]\"%(node_type, pkg))\n        except Exception as e:\n            errors.append(\"unable to find node [%s/%s]: %s\"%(pkg, node_type, str(e)))\n                \n    # Check for configuration errors, #2889\n    for err in rl_config.config_errors:\n        errors.append('ROSLaunch config error: %s' % err)\n\n    if errors:\n        return '\\n'.join(errors)\n                          \ndef print_file_list(roslaunch_files):\n    \"\"\"\n    :param roslaunch_files: list of launch files to load, ``str``\n\n    :returns: list of files involved in processing roslaunch_files, including the files themselves.\n    \"\"\"\n    from roslaunch.config import load_config_default, get_roscore_filename\n    import roslaunch.xmlloader\n    try:\n        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=True)\n        config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)\n        files = [os.path.abspath(x) for x in set(config.roslaunch_files) - set([get_roscore_filename()])]\n        print('\\n'.join(files))\n    except roslaunch.core.RLException as e:\n        print(str(e), file=sys.stderr)\n        sys.exit(1)\n\n", "path": "tools/roslaunch/src/roslaunch/rlutil.py"}], "after_files": [{"content": "# Software License Agreement (BSD License)\n#\n# Copyright (c) 2009, Willow Garage, Inc.\n# All rights reserved.\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions\n# are met:\n#\n#  * Redistributions of source code must retain the above copyright\n#    notice, this list of conditions and the following disclaimer.\n#  * Redistributions in binary form must reproduce the above\n#    copyright notice, this list of conditions and the following\n#    disclaimer in the documentation and/or other materials provided\n#    with the distribution.\n#  * Neither the name of Willow Garage, Inc. nor the names of its\n#    contributors may be used to endorse or promote products derived\n#    from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\n# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\n# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\n# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\n# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n# POSSIBILITY OF SUCH DAMAGE.\n\n\"\"\"\nUncategorized utility routines for roslaunch.\n\nThis API should not be considered stable.\n\"\"\"\n\nfrom __future__ import print_function\n\nimport os\nimport sys\nimport time\n\nimport roslib.packages\n\nimport rosclean\nimport rospkg\nimport rosgraph\n\nimport roslaunch.core\nimport roslaunch.config\nimport roslaunch.depends\nfrom rosmaster import DEFAULT_MASTER_PORT\n\ndef check_log_disk_usage():\n    \"\"\"\n    Check size of log directory. If high, print warning to user\n    \"\"\"\n    try:\n        d = rospkg.get_log_dir()\n        roslaunch.core.printlog(\"Checking log directory for disk usage. This may take awhile.\\nPress Ctrl-C to interrupt\") \n        disk_usage = rosclean.get_disk_usage(d)\n        # warn if over a gig\n        if disk_usage > 1073741824:\n            roslaunch.core.printerrlog(\"WARNING: disk usage in log directory [%s] is over 1GB.\\nIt's recommended that you use the 'rosclean' command.\"%d)\n        else:\n            roslaunch.core.printlog(\"Done checking log file disk usage. Usage is <1GB.\")            \n    except:\n        pass\n\ndef resolve_launch_arguments(args):\n    \"\"\"\n    Resolve command-line args to roslaunch filenames.\n\n    :returns: resolved filenames, ``[str]``\n    \"\"\"\n\n    # strip remapping args for processing\n    args = rosgraph.myargv(args)\n    \n    # user can either specify:\n    #  - filename + launch args\n    #  - package + relative-filename + launch args\n    if not args:\n        return args\n    resolved_args = None\n\n    # try to resolve launch file in package first\n    if len(args) >= 2:\n        try:\n            resolved = roslib.packages.find_resource(args[0], args[1])\n            if len(resolved) > 1:\n                raise roslaunch.core.RLException(\"multiple files named [%s] in package [%s]:%s\\nPlease specify full path instead\" % (args[1], args[0], ''.join(['\\n- %s' % r for r in resolved])))\n            if len(resolved) == 1:\n                resolved_args = [resolved[0]] + args[2:]\n        except rospkg.ResourceNotFound:\n            pass\n    # try to resolve launch file\n    if resolved_args is None and os.path.isfile(args[0]):\n        resolved_args = [args[0]] + args[1:]\n    # raise if unable to resolve\n    if resolved_args is None:\n        if len(args) >= 2:\n            raise roslaunch.core.RLException(\"[%s] is neither a launch file in package [%s] nor is [%s] a launch file name\" % (args[1], args[0], args[0]))\n        else:\n            raise roslaunch.core.RLException(\"[%s] is not a launch file name\" % args[0])\n    return resolved_args\n\ndef _wait_for_master():\n    \"\"\"\n    Block until ROS Master is online\n    \n    :raise: :exc:`RuntimeError` If unexpected error occurs\n    \"\"\"\n    m = roslaunch.core.Master() # get a handle to the default master\n    is_running = m.is_running()\n    if not is_running:\n        roslaunch.core.printlog(\"roscore/master is not yet running, will wait for it to start\")\n    while not is_running:\n        time.sleep(0.1)\n        is_running = m.is_running()\n    if is_running:\n        roslaunch.core.printlog(\"master has started, initiating launch\")\n    else:\n        raise RuntimeError(\"unknown error waiting for master to start\")\n\n_terminal_name = None\n\ndef _set_terminal(s):\n    import platform\n    if platform.system() in ['FreeBSD', 'Linux', 'Darwin', 'Unix']:\n        try:\n            print('\\033]2;%s\\007'%(s))\n        except:\n            pass\n    \ndef update_terminal_name(ros_master_uri):\n    \"\"\"\n    append master URI to the terminal name\n    \"\"\"\n    if _terminal_name:\n        _set_terminal(_terminal_name + ' ' + ros_master_uri)\n\ndef change_terminal_name(args, is_core):\n    \"\"\"\n    use echo (where available) to change the name of the terminal window\n    \"\"\"\n    global _terminal_name\n    _terminal_name = 'roscore' if is_core else ','.join(args)\n    _set_terminal(_terminal_name)\n\ndef get_or_generate_uuid(options_runid, options_wait_for_master):\n    \"\"\"\n    :param options_runid: run_id value from command-line or ``None``, ``str``\n    :param options_wait_for_master: the wait_for_master command\n      option. If this is True, it means that we must retrieve the\n      value from the parameter server and need to avoid any race\n      conditions with the roscore being initialized. ``bool``\n    \"\"\"\n\n    # Three possible sources of the run_id:\n    #\n    #  - if we're a child process, we get it from options_runid\n    #  - if there's already a roscore running, read from the param server\n    #  - generate one if we're running the roscore\n    if options_runid:\n        return options_runid\n\n    # #773: Generate a run_id to use if we launch a master\n    # process.  If a master is already running, we'll get the\n    # run_id from it instead\n    param_server = rosgraph.Master('/roslaunch')\n    val = None\n    while val is None:\n        try:\n            val = param_server.getParam('/run_id')\n        except:\n            if not options_wait_for_master:\n                val = roslaunch.core.generate_run_id()\n    return val\n    \ndef check_roslaunch(f):\n    \"\"\"\n    Check roslaunch file for errors, returning error message if check fails. This routine\n    is mainly to support rostest's roslaunch_check.\n\n    :param f: roslaunch file name, ``str``\n    :returns: error message or ``None``\n    \"\"\"\n    try:\n        rl_config = roslaunch.config.load_config_default([f], DEFAULT_MASTER_PORT, verbose=False)\n    except roslaunch.core.RLException as e:\n        return str(e)\n    \n    errors = []\n    # check for missing deps\n    base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps([f])\n    for pkg, miss in missing.iteritems():\n        if miss:\n            errors.append(\"Missing manifest dependencies: %s/manifest.xml: %s\"%(pkg, ', '.join(miss)))\n    \n    # load all node defs\n    nodes = []\n    for filename, rldeps in file_deps.iteritems():\n        nodes.extend(rldeps.nodes)\n\n    # check for missing packages\n    rospack = rospkg.RosPack()\n    for pkg, node_type in nodes:\n        try:\n            rospack.get_path(pkg)\n        except:\n            errors.append(\"cannot find package [%s] for node [%s]\"%(pkg, node_type))\n\n    # check for missing nodes\n    for pkg, node_type in nodes:\n        try:\n            if not roslib.packages.find_node(pkg, node_type):\n                errors.append(\"cannot find node [%s] in package [%s]\"%(node_type, pkg))\n        except Exception as e:\n            errors.append(\"unable to find node [%s/%s]: %s\"%(pkg, node_type, str(e)))\n                \n    # Check for configuration errors, #2889\n    for err in rl_config.config_errors:\n        errors.append('ROSLaunch config error: %s' % err)\n\n    if errors:\n        return '\\n'.join(errors)\n                          \ndef print_file_list(roslaunch_files):\n    \"\"\"\n    :param roslaunch_files: list of launch files to load, ``str``\n\n    :returns: list of files involved in processing roslaunch_files, including the files themselves.\n    \"\"\"\n    from roslaunch.config import load_config_default, get_roscore_filename\n    import roslaunch.xmlloader\n    try:\n        loader = roslaunch.xmlloader.XmlLoader(resolve_anon=True)\n        config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False)\n        files = [os.path.abspath(x) for x in set(config.roslaunch_files) - set([get_roscore_filename()])]\n        print('\\n'.join(files))\n    except roslaunch.core.RLException as e:\n        print(str(e), file=sys.stderr)\n        sys.exit(1)\n\n", "path": "tools/roslaunch/src/roslaunch/rlutil.py"}]}