def get_default_output_directory(): global __default_output_directory if __default_output_directory is not None: return __default_output_directory if not get_config().Exists(DEFAULT_OUTPUT_DIRECTORY): return os.path.abspath(os.path.expanduser('~')) # Fetch the default. Note that it might be None default_output_directory = config_read(DEFAULT_OUTPUT_DIRECTORY) or '' try: if os.path.isdir(default_output_directory): __default_output_directory = get_proper_case_filename( default_output_directory) return __default_output_directory except: logger.error( "Unknown failure when retrieving the default output directory", exc_info=True) logger.warning( "Warning: current path of %s is not a valid directory. Switching to home directory." % (default_output_directory.encode('ascii', 'replace'))) # If the user's home directory is not ascii, we're not going to go hunting for one that is. # Fail ungracefully. default_output_directory = os.path.abspath(os.path.expanduser('~')) set_default_output_directory(default_output_directory) return str(get_proper_case_filename(default_output_directory))
def get_absolute_path(path, abspath_mode = ABSPATH_IMAGE): """Convert a path into an absolute path using the path conventions If a path starts with http:, https: or ftp:, leave it unchanged. If a path starts with "./", then make the path relative to the Default Output Folder. If a path starts with "&/", then make the path relative to the Default Input Folder. If a "path" has no path component then make the path relative to the Default Output Folder. """ if abspath_mode == ABSPATH_OUTPUT: osep = '.' isep = '&' elif abspath_mode == ABSPATH_IMAGE: osep = '&' isep = '.' else: raise ValueError("Unknown abspath mode: %s"%abspath_mode) if is_url_path(path): return path if (path.startswith(osep+os.path.sep) or ("altsep" in os.path.__all__ and os.path.altsep and path.startswith(osep+os.path.altsep))): return os.path.join(get_default_output_directory(), path[2:]) elif (path.startswith(isep+os.path.sep) or ("altsep" in os.path.__all__ and os.path.altsep and path.startswith(isep+os.path.altsep))): return os.path.join(get_default_image_directory(), path[2:]) elif len(os.path.split(path)[0]) == 0: return os.path.join(get_default_output_directory(), path) else: return str(get_proper_case_filename(os.path.abspath(path)))
def get_default_output_directory(): global __default_output_directory if __default_output_directory is not None: return __default_output_directory if not get_config().Exists(DEFAULT_OUTPUT_DIRECTORY): return os.path.abspath(os.path.expanduser('~')) # Fetch the default. Note that it might be None default_output_directory = config_read(DEFAULT_OUTPUT_DIRECTORY) or '' try: if os.path.isdir(default_output_directory): __default_output_directory = get_proper_case_filename(default_output_directory) return __default_output_directory except: logger.error("Unknown failure when retrieving the default output directory", exc_info=True) logger.warning("Warning: current path of %s is not a valid directory. Switching to home directory."%(default_output_directory.encode('ascii', 'replace'))) # If the user's home directory is not ascii, we're not going to go hunting for one that is. # Fail ungracefully. default_output_directory = os.path.abspath(os.path.expanduser('~')) set_default_output_directory(default_output_directory) return str(get_proper_case_filename(default_output_directory))
def get_default_image_directory(): global __default_image_directory if __default_image_directory is not None: return __default_image_directory # I'm not sure what it means for the preference not to exist. No read-write preferences file? if not get_config().Exists(DEFAULT_IMAGE_DIRECTORY): return os.path.abspath(os.path.expanduser("~")) # Fetch the default. Note that it might be None default_image_directory = config_read(DEFAULT_IMAGE_DIRECTORY) or "" try: if os.path.isdir(default_image_directory): __default_image_directory = get_proper_case_filename(default_image_directory) return __default_image_directory except: logger.error("Unknown failure when retrieving the default image directory", exc_info=True) logger.warning( "Warning: current path of %s is not a valid directory. Switching to home directory." % (default_image_directory.encode("ascii", "replace")) ) # If the user's home directory is not ascii, we're not going to go hunting for one that is. # Fail ungracefully. default_image_directory = os.path.abspath(os.path.expanduser("~")) set_default_image_directory(default_image_directory) return str(get_proper_case_filename(default_image_directory))