Python get root dir

20 Python code examples are found related to " get root 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: dota_utils.py    From AerialDetection with Apache License 2.0 8 votes vote down vote up
def GetFileFromThisRootDir(dir,ext = None):
  allfiles = []
  needExtFilter = (ext != None)
  for root,dirs,files in os.walk(dir):
    for filespath in files:
      filepath = os.path.join(root, filespath)
      extension = os.path.splitext(filepath)[1][1:]
      if needExtFilter and extension in ext:
        allfiles.append(filepath)
      elif not needExtFilter:
        allfiles.append(filepath)
  return allfiles 
Example 2
Source File: git.py    From synthtool with Apache License 2.0 7 votes vote down vote up
def get_repo_root_dir(repo_path: str) -> str:
    """Given a path to a file or dir in a repo, find the root directory of the repo.

    Arguments:
        repo_path {str} -- Any path into the repo.

    Returns:
        str -- The repo's root directory.
    """
    path = pathlib.Path(repo_path)
    if not path.is_dir():
        path = path.parent
    proc = executor.run(
        ["git", "rev-parse", "--show-toplevel"],
        stdout=subprocess.PIPE,
        universal_newlines=True,
        cwd=str(path),
    )
    proc.check_returncode()
    return proc.stdout.strip() 
Example 3
Source File: resource_loader.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def get_root_dir_with_all_resources():
  """Get a root directory containing all the data attributes in the build rule.

  Returns:
    The path to the specified file present in the data attribute of py_test
    or py_binary. Falls back to returning the same as get_data_files_path if it
    fails to detect a bazel runfiles directory.
  """
  script_dir = get_data_files_path()

  # Create a history of the paths, because the data files are located relative
  # to the repository root directory, which is directly under runfiles
  # directory.
  directories = [script_dir]
  data_files_dir = ''

  while True:
    candidate_dir = directories[-1]
    current_directory = _os.path.basename(candidate_dir)
    if '.runfiles' in current_directory:
      # Our file should never be directly under runfiles.
      # If the history has only one item, it means we are directly inside the
      # runfiles directory, something is wrong, fall back to the default return
      # value, script directory.
      if len(directories) > 1:
        data_files_dir = directories[-2]

      break
    else:
      new_candidate_dir = _os.path.dirname(candidate_dir)
      # If we are at the root directory these two will be the same.
      if new_candidate_dir == candidate_dir:
        break
      else:
        directories.append(new_candidate_dir)

  return data_files_dir or script_dir 
Example 4
Source File: utils.py    From DOTA_models with Apache License 2.0 5 votes vote down vote up
def GetFileFromThisRootDir(dir,ext = None):
  allfiles = []
  needExtFilter = (ext != None)
  for root,dirs,files in os.walk(dir):
    for filespath in files:
      filepath = os.path.join(root, filespath)
      extension = os.path.splitext(filepath)[1][1:]
      if needExtFilter and extension in ext:
        allfiles.append(filepath)
      elif not needExtFilter:
        allfiles.append(filepath)
  return allfiles 
Example 5
Source File: Application.py    From nionswift with GNU General Public License v3.0 5 votes vote down vote up
def get_root_dir():
    root_dir = os.path.dirname((os.path.dirname(os.path.abspath(__file__))))
    path_ascend_count = 2
    for i in range(path_ascend_count):
        root_dir = os.path.dirname(root_dir)
    return root_dir 
Example 6
Source File: download_files_utilities.py    From pyspedas with MIT License 5 votes vote down vote up
def get_root_data_dir():
    from .config import CONFIG
    # Get preferred data download location for pyspedas project
    if 'local_data_dir' in CONFIG:
        return CONFIG['local_data_dir']
    else:
        raise NameError('local_data_dir is not found in config.py') 
Example 7
Source File: platform.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def get_dir_root(shellvars, default_to_home=True):
    def check_sysvars(x):
        y = os.path.expandvars(x)
        if y != x and os.path.isdir(y):
            return y
        return None

    dir_root = None
    for d in shellvars:
        dir_root = check_sysvars(d)
        if dir_root is not None:
            break
    else:
        if default_to_home:
            dir_root = os.path.expanduser('~')
            if dir_root == '~' or not os.path.isdir(dir_root):
                dir_root = None

    if get_filesystem_encoding() == None:
        try:
            dir_root = dir_root.decode(sys.getfilesystemencoding())
        except:
            try:
                dir_root = dir_root.decode('utf8')
            except:
                pass


    return dir_root 
Example 8
Source File: Summarizer.py    From tierpsy-tracker with MIT License 5 votes vote down vote up
def getRootDir(self):
        root_dir = QtWidgets.QFileDialog.getExistingDirectory(
            self,
            "Selects the root directory where the features files are located.",
            self.mapper['root_dir'])
        if root_dir:
            self.updateRootDir(root_dir) 
Example 9
Source File: main.py    From ops-cli with Apache License 2.0 5 votes vote down vote up
def get_root_dir(args):
    """ Either the root_dir option or the current working dir """

    if args.root_dir:
        if not os.path.isdir(os.path.realpath(args.root_dir)):
            raise OpsException(
                "Specified root dir '%s' does not exists" %
                os.path.realpath(
                    args.root_dir))

        return os.path.realpath(args.root_dir)

    return os.path.realpath(os.getcwd()) 
Example 10
Source File: cmd.py    From git-machete with MIT License 5 votes vote down vote up
def get_root_dir():
    global root_dir
    if not root_dir:
        try:
            root_dir = popen_git("rev-parse", "--show-toplevel").strip()
        except MacheteException:
            raise MacheteException("Not a git repository")
    return root_dir 
Example 11
Source File: cli.py    From surround with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_project_root_from_current_dir():
    """
    Returns the project root directory for the current project we're in.

    :return: path to the root of the project
    :rtype: string
    """

    return get_project_root(os.getcwd()) 
Example 12
Source File: overlayfs.py    From mock with GNU General Public License v2.0 5 votes vote down vote up
def getRootDir(self):
        return self.rootDir


    # directory which contains all data asocied with this plugin 
Example 13
Source File: register.py    From gcr-catalogs with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_root_dir():
    """
    Returns current root_dir.
    """
    return _config_register.root_dir 
Example 14
Source File: log_manager000.py    From distributed_framework with Apache License 2.0 5 votes vote down vote up
def get_logs_dir_by_disk_root():
    """
    返回磁盘根路径下的pythonlogs文件夹,当使用文件日志时候自动创建这个文件夹。
    :return:
    """
    from pathlib import Path
    return str(Path(Path(__file__).absolute().root) / Path('pythonlogs'))


# noinspection PyMissingOrEmptyDocstring,PyPep8 
Example 15
Source File: __init__.py    From pfio with MIT License 5 votes vote down vote up
def get_root_dir() -> str:
    """get the current root path

    Returns:
        The current root path

    """
    global _DEFAULT_CONTEXT
    default_context = _DEFAULT_CONTEXT

    return default_context.get_root_dir() 
Example 16
Source File: dax_settings.py    From dax with MIT License 5 votes vote down vote up
def get_root_job_dir(self):
        """Get the root_job_dir value from the cluster section.

        :return: String of the root_job_dir value, None if empty
        """
        return self.get('cluster', 'root_job_dir') 
Example 17
Source File: ypkgcontext.py    From ypkg with GNU General Public License v3.0 4 votes vote down vote up
def get_package_root_dir(self):
        """ Return the root directory for the package """
        return os.path.abspath("{}/root/{}".format(
                               self.get_build_prefix(),
                               self.spec.pkg_name)) 
Example 18
Source File: data.py    From sagemaker-python-sdk with Apache License 2.0 4 votes vote down vote up
def get_root_dir(self):
        """Retrieve the absolute path to the root directory of this data source.

        Returns:
            str: absolute path to the root directory of this data source.
        """