1
0
Fork 0
mirror of synced 2024-06-30 04:31:09 -04:00
dotbot/dotbot/util/common.py
m-richards 47f3e07b2d
Cleanup link logic, with a fix for windows links with \\?\ in them.
* reduce ci matrix

* python runscript without bash

(cherry picked from commit 9b148a6679722db5eb7ffabd3a27a8579f296319)

* change link dest function to handle '\?\' links

* add path normalization for windows support

* Revert "add path normalization for windows support"

This reverts commit 2ab0fc1b3c.

* link variable extraction without normpath

* type annotation

* blacken

* missing black files

* variable renames from '2775765a' outside link function

* from '2775765a' use method for default flags

* fix defaults from method

* variable renames from '2775765a' in link function and method renames

* refactor if clauses into blocks

* maybe fix if refactor

* remove unreachable code

* remove silly disambiguation semantics

* remove silly disambiguation semantics 2

* incremental else swap

* bring source existence check to front

* bring source existence check to front and remove old back check

* refactor almost final case

* check symlink broken cases up front

* add return missing

* flip block order to make things easier to understand
2021-02-16 19:32:13 +10:00

29 lines
1.3 KiB
Python

import os
import subprocess
import platform
def shell_command(command, cwd=None, enable_stdin=False, enable_stdout=False, enable_stderr=False):
with open(os.devnull, "w") as devnull_w, open(os.devnull, "r") as devnull_r:
stdin = None if enable_stdin else devnull_r
stdout = None if enable_stdout else devnull_w
stderr = None if enable_stderr else devnull_w
executable = os.environ.get("SHELL")
if platform.system() == "Windows":
# We avoid setting the executable kwarg on Windows because it does
# not have the desired effect when combined with shell=True. It
# will result in the correct program being run (e.g. bash), but it
# will be invoked with a '/c' argument instead of a '-c' argument,
# which it won't understand.
#
# See https://github.com/anishathalye/dotbot/issues/219 and
# https://bugs.python.org/issue40467.
#
# This means that complex commands that require Bash's parsing
# won't work; a workaround for this is to write the command as
# `bash -c "..."`.
executable = None
return subprocess.call(
command, shell=True, executable=executable, stdin=stdin, stdout=stdout, stderr=stderr, cwd=cwd
)