File: os.py

package info (click to toggle)
py-postgresql 1.2.1%2Bgit20180803.ef7b9a9-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,620 kB
  • sloc: python: 18,317; ansic: 2,024; sql: 282; sh: 26; makefile: 22
file content (34 lines) | stat: -rw-r--r-- 773 bytes parent folder | download | duplicates (4)
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
##
# .python.os
##
"""
General OS abstractions and information.
"""
import sys
import os

#: By default, close the FDs on subprocess.Popen().
close_fds = True

#: By default, there is no modification for executable references.
platform_exe = str

def find_file(basename, paths,
	join = os.path.join, exists = os.path.exists,
):
	"""
	Find the file in the given paths. Return the first path
	that exists.
	"""
	for x in paths:
		path = join(x, basename)
		if exists(path):
			return path

if sys.platform in ('win32','win64'):
	# replace variants for windows
	from .msw import close_fds, platform_exe

def find_executable(basename, pathsep = os.pathsep, platexe = platform_exe):
	paths = os.environ.get('PATH', '').split(pathsep)
	return find_file(platexe(basename), paths)