Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2# -*- coding: utf-8; mode: python; -*- 

3# Copyright © 2020-2021 Pradyumna Paranjape 

4# 

5# This file is part of xdgpspconf. 

6# 

7# xdgpspconf is free software: you can redistribute it and/or modify 

8# it under the terms of the GNU Lesser General Public License as published by 

9# the Free Software Foundation, either version 3 of the License, or 

10# (at your option) any later version. 

11# 

12# xdgpspconf is distributed in the hope that it will be useful, 

13# but WITHOUT ANY WARRANTY; without even the implied warranty of 

14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

15# GNU Lesser General Public License for more details. 

16# 

17# You should have received a copy of the GNU Lesser General Public License 

18# along with xdgpspconf. If not, see <https://www.gnu.org/licenses/>. # 

19""" 

20Locate standard data. 

21 

22Read: 

23 - standard xdg-base locations 

24 - current directory and ancestors 

25 - custom location 

26 

27""" 

28 

29import os 

30from pathlib import Path 

31from typing import List 

32 

33from xdgpspconf.common import locate_base, walk_ancestors, xdg_base 

34 

35 

36def ancestral_data(child_dir: Path) -> List[Path]: 

37 """ 

38 Walk up to nearest mountpoint or project root. 

39 

40 - collect all directories containing __init__.py 

41 (assumed to be source directories) 

42 - project root is directory that contains ``setup.cfg`` or ``setup.py`` 

43 - mountpoint is a unix mountpoint or windows drive root 

44 - I am **NOT** my ancestor 

45 

46 Args: 

47 child_dir: walk ancestry of `this` directory 

48 

49 Returns: 

50 List of Paths to ancestral source directories: 

51 First directory is most dominant 

52 """ 

53 return walk_ancestors(child_dir) 

54 

55 

56def xdg_data() -> List[Path]: 

57 """ 

58 Get XDG_DATA_HOME locations. 

59 

60 `specifications 

61 <https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html>`__ 

62 

63 Returns: 

64 List of xdg-data Paths 

65 First directory is most dominant 

66 """ 

67 return xdg_base('DATA') 

68 

69 

70def locate_data(project: str, 

71 custom: os.PathLike = None, 

72 ancestors: bool = False, 

73 py_bin: os.PathLike = None) -> List[Path]: 

74 """ 

75 Locate data at standard locations. 

76 

77 Args: 

78 project: name of project whose data is being fetched 

79 custom: custom location for data 

80 ancestors: inherit ancestor directories that contain __init__.py 

81 py_bin: namespace.__file__ that imports this function 

82 

83 Returns: 

84 List of all possible data paths: 

85 Existing and non-existing 

86 First directory is most dominant 

87 

88 """ 

89 return locate_base(project, custom, ancestors, 'DATA', py_bin)