File: paths.py

package info (click to toggle)
subuser 0.6.2-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,216 kB
  • sloc: python: 5,204; sh: 380; makefile: 73; javascript: 43
file content (48 lines) | stat: -rwxr-xr-x 1,286 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-

"""
Module used for determining non-user-configurable paths.
"""

#external imports
import os
import inspect
try:
    import importlib.resources as importlib_resources
except ImportError:
    # For compatibility with older Python versions (< 3.7)
    import importlib_resources
#internal imports
import subuserlib.executablePath as executablePath

home = os.path.expanduser("~")

def upNDirsInPath(path,n):
  if n > 0:
    return os.path.dirname(upNDirsInPath(path,n-1))
  else:
    return path

def getSubuserDir():
  """
  Get the toplevel directory for subuser.
  """
  pathToThisSourceFile = os.path.abspath(inspect.getfile(inspect.currentframe()))
  return upNDirsInPath(pathToThisSourceFile,3)

def getSubuserExecutable():
  executable = os.path.join(getSubuserDir(),"logic","subuser")
  if not os.path.exists(executable):
    executable = executablePath.which("subuser")
  return executable

def getSubuserDataFile(filename):
  dataFile = os.path.join(getSubuserDir(),"logic","subuserlib","data",filename)
  if os.path.exists(dataFile):
    return dataFile
  else:
    ref = importlib_resources.files("subuserlib").joinpath("data", filename)
    if not ref.is_file():
      exit("Data file does not exist:"+str(dataFile))
    else:
      return str(ref)