1 # Copyright (c) 2010, 2011 Nicira Networks
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 PROGRAM_NAME = os.path.basename(sys.argv[0])
22 def abs_file_name(dir_, file_name):
23 """If 'file_name' starts with '/', returns a copy of 'file_name'.
24 Otherwise, returns an absolute path to 'file_name' considering it relative
25 to 'dir_', which itself must be absolute. 'dir_' may be None or the empty
26 string, in which case the current working directory is used.
28 Returns None if 'dir_' is None and getcwd() fails.
30 This differs from os.path.abspath() in that it will never change the
31 meaning of a file name."""
32 if file_name.startswith('/'):
35 if dir_ is None or dir_ == "":
41 if dir_.endswith('/'):
42 return dir_ + file_name
44 return "%s/%s" % (dir_, file_name)