/usr/lib/python3/dist-packages/click/osextras.py is in python3-click 0.4.21.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | # Copyright (C) 2013 Canonical Ltd.
# Author: Colin Watson <cjwatson@ubuntu.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Extra OS-level utility functions.
Usually we can instead use the functions exported from
lib/click/osextras.vala via GObject Introspection. These pure-Python
versions are preserved so that they can be used from code that needs to be
maximally portable: for example, click.build is intended to be usable even
on systems that lack GObject, as long as they have a reasonably recent
version of Python.
"""
__all__ = [
'ensuredir',
'find_on_path',
'unlink_force',
]
import errno
import os
try:
# Python 3.3
from shutil import which
def find_on_path(command):
# http://bugs.python.org/issue17012
path = os.environ.get('PATH', os.pathsep)
return which(command, path=os.environ.get('PATH', path)) is not None
except ImportError:
# Python 2
def find_on_path(command):
"""Is command on the executable search path?"""
if 'PATH' not in os.environ:
return False
path = os.environ['PATH']
for element in path.split(os.pathsep):
if not element:
continue
filename = os.path.join(element, command)
if os.path.isfile(filename) and os.access(filename, os.X_OK):
return True
return False
def ensuredir(directory):
if not os.path.isdir(directory):
os.makedirs(directory)
def listdir_force(directory):
try:
return os.listdir(directory)
except OSError as e:
if e.errno == errno.ENOENT:
return []
raise
def unlink_force(path):
"""Unlink path, without worrying about whether it exists."""
try:
os.unlink(path)
except OSError as e:
if e.errno != errno.ENOENT:
raise
def symlink_force(source, link_name):
"""Create symlink link_name -> source, even if link_name exists."""
unlink_force(link_name)
os.symlink(source, link_name)
def get_umask():
mask = os.umask(0)
os.umask(mask)
return mask
|