Revision 56bcd3f4 lib/backend.py
b/lib/backend.py | ||
---|---|---|
881 | 881 |
detail = str(err) |
882 | 882 |
return detail |
883 | 883 |
|
884 |
def _OSSearch(name, search_path=None): |
|
885 |
"""Search for OSes with the given name in the search_path. |
|
886 |
|
|
887 |
Args: |
|
888 |
name: The name of the OS to look for |
|
889 |
search_path: List of dirs to search (defaults to constants.OS_SEARCH_PATH) |
|
890 |
|
|
891 |
Returns: |
|
892 |
The base_dir the OS resides in |
|
893 |
|
|
894 |
""" |
|
895 |
|
|
896 |
if search_path is None: |
|
897 |
search_path = constants.OS_SEARCH_PATH |
|
898 |
|
|
899 |
for dir in search_path: |
|
900 |
t_os_dir = os.path.sep.join([dir, name]) |
|
901 |
if os.path.isdir(t_os_dir): |
|
902 |
return dir |
|
903 |
|
|
904 |
return None |
|
884 | 905 |
|
885 | 906 |
def _OSOndiskVersion(name, os_dir): |
886 | 907 |
"""Compute and return the api version of a given OS. |
... | ... | |
950 | 971 |
break |
951 | 972 |
for name in f_names: |
952 | 973 |
try: |
953 |
os_inst = OSFromDisk(name, os_dir=os.path.sep.join([dir, name]))
|
|
974 |
os_inst = OSFromDisk(name, base_dir=dir)
|
|
954 | 975 |
result.append(os_inst) |
955 | 976 |
except errors.InvalidOS, err: |
956 | 977 |
result.append(err) |
... | ... | |
958 | 979 |
return result |
959 | 980 |
|
960 | 981 |
|
961 |
def OSFromDisk(name, os_dir=None):
|
|
982 |
def OSFromDisk(name, base_dir=None):
|
|
962 | 983 |
"""Create an OS instance from disk. |
963 | 984 |
|
964 | 985 |
This function will return an OS instance if the given name is a |
... | ... | |
972 | 993 |
|
973 | 994 |
""" |
974 | 995 |
|
975 |
if os_dir is None: |
|
976 |
for base_dir in constants.OS_SEARCH_PATH: |
|
977 |
t_os_dir = os.path.sep.join([base_dir, name]) |
|
978 |
if os.path.isdir(t_os_dir): |
|
979 |
os_dir = t_os_dir |
|
980 |
break |
|
996 |
if base_dir is None: |
|
997 |
base_dir = _OSSearch(name) |
|
998 |
else: |
|
999 |
if not os.path.isdir(os.path.sep.join([base_dir, name])): |
|
1000 |
raise errors.InvalidOS(name, "OS not found in base dir %s" % base_dir) |
|
981 | 1001 |
|
982 |
if os_dir is None:
|
|
1002 |
if base_dir is None:
|
|
983 | 1003 |
raise errors.InvalidOS(name, "OS dir not found in search path") |
984 | 1004 |
|
1005 |
os_dir = os.path.sep.join([base_dir, name]) |
|
985 | 1006 |
api_version = _OSOndiskVersion(name, os_dir) |
986 | 1007 |
|
987 | 1008 |
if api_version != constants.OS_API_VERSION: |
Also available in: Unified diff