Python get parent dir
9 Python code examples are found related to "
get parent dir".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: builder.py From base16-builder-python with MIT License | 5 votes |
def get_parent_dir(base_dir, level=1): "Get the directory $level levels above $base_dir." while level > 0: base_dir = os.path.dirname(base_dir) level -= 1 return base_dir
Example 2
Source File: path_util.py From blenderseed with MIT License | 5 votes |
def get_appleseed_parent_dir_path(): appleseed_parent_dir = get_appleseed_bin_dir_path() while os.path.basename(appleseed_parent_dir) != 'bin': appleseed_parent_dir = os.path.dirname(appleseed_parent_dir) appleseed_parent_dir = os.path.dirname(appleseed_parent_dir) return appleseed_parent_dir
Example 3
Source File: file.py From QMusic with GNU Lesser General Public License v2.1 | 5 votes |
def get_parent_dir(filepath, level=1): ''' Get parent directory with given return level. @param filepath: Filepath. @param level: Return level, default is 1 @return: Return parent directory with given return level. ''' parent_dir = os.path.realpath(filepath) while (level > 0): parent_dir = os.path.dirname(parent_dir) level -= 1 return parent_dir
Example 4
Source File: setup_path.py From crossgap_il_rl with GNU General Public License v2.0 | 5 votes |
def getParentDir(): cur_path = SetupPath.getCurrentPath() if SetupPath.getDirLevels(cur_path) >= 1: return os.path.dirname(cur_path) return ''
Example 5
Source File: setup_path.py From crossgap_il_rl with GNU General Public License v2.0 | 5 votes |
def getGrandParentDir(): cur_path = SetupPath.getCurrentPath() if SetupPath.getDirLevels(cur_path) >= 2: return os.path.dirname(os.path.dirname(cur_path)) return ''
Example 6
Source File: utils.py From warriorframework with Apache License 2.0 | 5 votes |
def get_parent_dir(path, child="warhorn"): """ This function gets the parent directory of any a specified child folder from the given path """ if path.rsplit(os.sep)[-1] == child: path = os.path.dirname(path) else: path = os.path.dirname(path) path = get_parent_dir(path, child) return path
Example 7
Source File: package_utils.py From nni with MIT License | 5 votes |
def get_nni_installation_parent_dir(): ''' Find nni installation parent directory ''' def try_installation_path_sequentially(*sitepackages): '''Try different installation path sequentially util nni is found. Return None if nothing is found ''' def _generate_installation_path(sitepackages_path): python_dir = get_python_dir(sitepackages_path) entry_file = os.path.join(python_dir, 'nni', 'main.js') if os.path.isfile(entry_file): return python_dir return None for sitepackage in sitepackages: python_dir = _generate_installation_path(sitepackage) if python_dir: return python_dir return None if os.getenv('VIRTUAL_ENV'): # if 'virtualenv' package is used, `site` has not attr getsitepackages, so we will instead use VIRTUAL_ENV # Note that conda venv will not have VIRTUAL_ENV python_dir = os.getenv('VIRTUAL_ENV') else: python_sitepackage = site.getsitepackages()[0] # If system-wide python is used, we will give priority to using `local sitepackage`--"usersitepackages()" given # that nni exists there if python_sitepackage.startswith('/usr') or python_sitepackage.startswith('/Library'): python_dir = try_installation_path_sequentially(site.getusersitepackages(), site.getsitepackages()[0]) else: python_dir = try_installation_path_sequentially(site.getsitepackages()[0], site.getusersitepackages()) return python_dir
Example 8
Source File: utilities.py From ros2-migration-tools with Apache License 2.0 | 5 votes |
def get_parent_dir(directory): """ Gets the parent directory for give path :param directory: :return: str """ return os.path.abspath(os.path.join(directory, os.pardir))
Example 9
Source File: fileSystem.py From FACT_core with GNU General Public License v3.0 | 5 votes |
def get_parent_dir(dir_path): dir_path = dir_path.split('/') dir_path = dir_path[0:len(dir_path) - 1] dir_path = '/'.join(dir_path) return dir_path