Functions
srt_path_util Namespace Reference

Functions

def get_relative_path (the_path, base_path)
 
def find_file_in_PATH (filename)
 
def find_file_in_search_string (filename, search_dir_string)
 
def change_to_type (old_path, new_type)
 
def file_type (the_path)
 
def path_to_unix (the_path)
 

Function Documentation

def srt_path_util.change_to_type (   old_path,
  new_type 
)

Definition at line 93 of file srt_path_util.py.

Referenced by srt_make_ntide_files.split_targets().

93 def change_to_type (old_path, new_type):
94  (base_dir, fname) = os.path.split (old_path)
95  new_fname = regsub.gsub("\.[^\.]*$", "." + new_type, fname)
96  return os.path.join (base_dir, new_fname)
97 
98 #
99 # file_type
100 #
101 # Return the filetype of the handed path.
102 #
def change_to_type(old_path, new_type)
def srt_path_util.file_type (   the_path)

Definition at line 103 of file srt_path_util.py.

Referenced by srt_ntf77.main(), srt_nt_example_command.main(), and srt_ntcc.main().

103 def file_type (the_path):
104  (base_dir, fname) = os.path.split (the_path)
105  temp = regex.compile (".*\.\([^\.]*\)$")
106  if temp.match(the_path) != -1:
107  return temp.group(1)
108  return ""
109 
110 #
111 # path_to_unix
112 #
113 # Convert from NT to unix path -- just change the \ to /s
114 #
def file_type(the_path)
def srt_path_util.find_file_in_PATH (   filename)

Definition at line 71 of file srt_path_util.py.

71 def find_file_in_PATH (filename):
72  return find_file_in_search_string (filename, os.environ["PATH"])
73 
74 #
75 # find_file_in_search_string
76 #
77 # Find a file in a given search string. The seperator is the default for this platform (os.pathsep).
78 #
def find_file_in_PATH(filename)
def srt_path_util.find_file_in_search_string (   filename,
  search_dir_string 
)

Definition at line 79 of file srt_path_util.py.

79 def find_file_in_search_string (filename, search_dir_string):
80  search_list = string.split (search_dir_string, os.pathsep)
81  search_list.insert (0, "./")
82 
83  for search_path in search_list:
84  file_to_look_for = search_path + os.sep + filename
85  if os.path.exists (file_to_look_for):
86  return file_to_look_for
87 
88 #
89 # change_to_type
90 #
91 # Change the file extension of a given path
92 #
def find_file_in_search_string(filename, search_dir_string)
def srt_path_util.get_relative_path (   the_path,
  base_path 
)

Definition at line 22 of file srt_path_util.py.

22 def get_relative_path (the_path, base_path):
23 
24  #
25  # Dumb special case
26  #
27 
28  if the_path == base_path:
29  return "."
30 
31  #
32  # There is a bug in commonprefix... it doesn't do it by directory, but, rather
33  # by string... so it can cut off in the middle of a directory (!!!!!). Actually,
34  # the docs say that that is what it is meant to do, but geez!
35  #
36 
37  common_path = os.path.commonprefix ([the_path, base_path])
38  index = len(common_path)
39  index = string.rfind (the_path[:index+1], "\\")
40  if index == -1:
41  index = 0
42 
43  common_path = the_path[:index]
44  l_path = the_path[index+1:]
45  l_base = base_path[index+1:]
46 
47  #
48  # Make sure they had something in common, or this isn't going to work!
49  #
50 
51  if common_path == "":
52  raise "Path '" + the_path + "' and base path '" + base_path + "' have nothing in common, so cannot be made relative!"
53 
54  #
55  # Add a set of ".."s to the start of l_path for each directory there is in
56  # l_base. That should do it!
57  #
58 
59  while (l_base != "\\") and (l_base != ""):
60  (l_base, fragment) = os.path.split (l_base)
61  l_path = "..\\" + l_path
62 
63  return l_path
64 
65 #
66 # find_file_in_PATH
67 #
68 # Search the PATH environ var for a certian file. Report back the filename if we find it, a null
69 # string if we can't.
70 #
def get_relative_path(the_path, base_path)
def srt_path_util.path_to_unix (   the_path)

Definition at line 115 of file srt_path_util.py.

Referenced by srt_ntide_project_file.create_project_file().

115 def path_to_unix (the_path):
116  return regsub.gsub("\\\\", "/", the_path)
117 
def path_to_unix(the_path)