本文整理汇总了Python中plumbum.local方法的典型用法代码示例。如果您正苦于以下问题:Python plumbum.local方法的具体用法?Python plumbum.local怎么用?Python plumbum.local使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plumbum
的用法示例。
在下文中一共展示了plumbum.local方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_coverage
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def upload_coverage() -> None:
try:
print('>>>> Upload coverage')
# pylint: disable=import-outside-toplevel
from shared import fetch_tools
fetch_tools.store('https://codecov.io/bash', 'codecov.sh')
python3 = local['python3']
python3['-m', 'coverage', 'xml', '-i']
bash = local['bash']
bash['codecov.sh'] & FG
# Sometimes the coverage uploader has issues. Just fail silently, it's not that important
except ProcessExecutionError as e:
print(e)
except fetch_tools.FetchException as e:
print(e)
# pylint: disable=import-outside-toplevel
示例2: call_ansible
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def call_ansible(inventory, playbook, *args):
"""
Wraps a call out to the ansible-playbook executable, passing it the cinch
site.yml file that kicks off this playbook.
:param inventory: The Ansible inventory file to pass through
:param args: An array of other command-line arguments to ansible-playbook
to pass
:return: The exit code returned from ansible-playbook, or 255 if errors
come from elsewhere
"""
# Construct the arguments to pass to Ansible by munging the arguments
# provided to this method
ansible_args = [
os.path.join(BASE, playbook),
'-i', inventory,
'-v',
'--ssh-common-args=-o StrictHostKeyChecking=no ' +
'-o UserKnownHostsFile=/dev/null'
]
ansible_args.extend(args)
ansible = local['ansible-playbook']
exit_code = command_handler(ansible, ansible_args)
return exit_code
示例3: __call__
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def __call__(self):
assert self.__alive, '%s is dead' % self
# We can't use an iteration that's already started - maybe it's already at a too advanced stage?
if self._iterating.is_set():
self._not_iterating.wait()
self._iteration_trigger.set() # Signal that we want an iteration
while not self._iterating.wait(1): # Wait until an iteration starts
# It is possible that we missed the loop and _iterating was already
# cleared. If this is the case, _not_iterating will not be set -
# and we can use it as a signal to stop waiting for iteration.
if self._not_iterating.is_set():
break
else:
self._not_iterating.wait() # Wait until it finishes
# To avoid races, copy last exception and result to local variables
last_exception, last_result = self._last_exception, self._last_result
if last_exception:
raise last_exception
else:
return last_result
示例4: run
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def run():
netrc_path = os.path.join(local.env.get('HOME', ''), '.netrc')
github_actor = local.env.get('GITHUB_ACTOR')
github_token = local.env.get('INPUT_GITHUB-TOKEN')
commit_message = local.env.get('INPUT_COMMIT-MESSAGE')
force_add = local.env.get('INPUT_FORCE-ADD')
branch = local.env.get('INPUT_PUSH-BRANCH') or local.env.get('GITHUB_REF').split('/')[2]
rebase = local.env.get('INPUT_REBASE', 'false')
files = local.env.get('INPUT_FILES', '')
email = local.env.get('INPUT_EMAIL', f'{github_actor}@users.noreply.github.com')
name = local.env.get('INPUT_NAME', github_actor)
with open(netrc_path, 'w') as f:
f.write(
f'machine github.com\n'
f'login {github_actor}\n'
f'password {github_token}\n'
f'machine api.github.com\n'
f'login {github_actor}\n'
f'password {github_token}\n'
)
chmod = local['chmod']
git = local['git']
debug(chmod(['600', netrc_path]))
debug(git(['config', '--global', 'user.email', email]))
debug(git(['config', '--global', 'user.name', name]))
debug(f'username:{github_actor}, branch:{branch}, commit message:{commit_message}')
with open(netrc_path) as f:
debug(f.read())
add_args = ['add']
if force_add == 'true':
add_args.append('-f')
add_args.append('-A')
if files:
debug(f"Files: {files}")
add_args.extend(files.strip("'").split())
if rebase == 'true':
debug(git(['pull', '--rebase', '--autostash', 'origin', branch]))
debug(git(['checkout', '-B', branch]))
debug(git(add_args))
debug(git(['commit', '-m', commit_message], retcode=None))
debug(git(['push', '--follow-tags', '--set-upstream', 'origin', branch]))
示例5: is_running
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def is_running(process):
ps = local['ps']
result = ps['asw']()
return re.search(process, result)
示例6: watch
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def watch() -> None:
print('>>>> Watching')
subprocess.check_call(['npm', 'run', 'watch'], shell=ON_WINDOWS)
# Make a branch based off of current (remote) master with all your local changes preserved (but not added).
示例7: stash_if_any
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def stash_if_any() -> str:
print('>>>> Stashing local changes')
label = 'dev-py-stash-at-' + str(time.time())
subprocess.check_call(['git', 'stash', 'save', '--include-untracked', label])
return label
示例8: test_pylint
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def test_pylint(src_dir):
"""Run Pylint."""
pylint = plumbum.local["pylint"]
with plumbum.local.cwd(PROJECT_ROOT_DIR):
result = pylint(src_dir)
if result:
print("\nPylint:", result)
示例9: test_black
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def test_black(src_dir):
"""Run Black."""
black = plumbum.local["black"]
with plumbum.local.cwd(PROJECT_ROOT_DIR):
result = black("--check", src_dir)
if result:
print("\nBlack:", result)
示例10: test_isort
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def test_isort(src_dir):
"""Run Isort."""
isort = plumbum.local["isort"]
with plumbum.local.cwd(PROJECT_ROOT_DIR):
result = isort("--check-only", "-rc", src_dir)
if result:
print("\nIsort:", result)
示例11: test_mypy
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def test_mypy(src_dir):
"""Run MyPy."""
mypy = plumbum.local["mypy"]
with plumbum.local.cwd(PROJECT_ROOT_DIR):
result = mypy(src_dir)
if result:
print("\nMyPy:", result)
示例12: test_pydocstyle
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def test_pydocstyle(src_dir):
"""Run Pydocstyle."""
pydocstyle = plumbum.local["pydocstyle"]
with plumbum.local.cwd(PROJECT_ROOT_DIR):
result = pydocstyle(src_dir)
if result:
print("\nPydocstyle:", result)
示例13: async_raise_in_main_thread
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def async_raise_in_main_thread(exc, use_concurrent_loop=True):
"""
Uses a unix signal to raise an exception to be raised in the main thread.
"""
from plumbum import local
pid = os.getpid()
if not REGISTERED_SIGNAL:
raise NotInitialized()
# sometimes the signal isn't caught by the main-thread, so we should try a few times (WEKAPP-14543)
def do_signal(raised_exc):
global LAST_ERROR
if LAST_ERROR is not raised_exc:
_logger.debug("MainThread took the exception - we're done here")
if use_concurrent_loop:
raiser.stop()
return
_logger.info("Raising %s in main thread", type(LAST_ERROR))
local.cmd.kill("-%d" % REGISTERED_SIGNAL, pid)
if use_concurrent_loop:
from .concurrency import concurrent
raiser = concurrent(do_signal, raised_exc=exc, loop=True, sleep=30, daemon=True, throw=False)
raiser.start()
else:
do_signal(exc)
示例14: kill_subprocesses
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def kill_subprocesses():
from plumbum import local
pid = os.getpid()
return local.cmd.pkill['-HUP', '-P', pid].run(retcode=None)
示例15: kill_this_process
# 需要导入模块: import plumbum [as 别名]
# 或者: from plumbum import local [as 别名]
def kill_this_process(graceful=False):
from plumbum import local
pid = os.getpid()
if graceful:
flag = '-HUP'
else:
flag = '-9'
local.cmd.kill(flag, pid)