本文整理汇总了Python中sarge.Capture方法的典型用法代码示例。如果您正苦于以下问题:Python sarge.Capture方法的具体用法?Python sarge.Capture怎么用?Python sarge.Capture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sarge
的用法示例。
在下文中一共展示了sarge.Capture方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startHotspot
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def startHotspot(self):
with self._startHotspotCondition:
isHotspotActive = self.isHotspotActive()
if isHotspotActive is None: # this means is not possible in this system
return "Hotspot is not possible on this system"
if isHotspotActive is True:
return True
try:
p = sarge.run("service wifi_access_point start", stderr=sarge.Capture())
if p.returncode != 0:
returncode = p.returncode
stderr_text = p.stderr.text
logger.warn("Start hotspot failed with return code %i: %s" % (returncode, stderr_text))
return "Start hotspot failed with return code %i: %s" % (returncode, stderr_text)
else:
return True
except Exception, e:
logger.warn("Start hotspot failed with return code: %s" % e)
return "Start hotspot failed with return code: %s" % e
示例2: _mountPartition
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def _mountPartition(self, partition, directory):
if directory:
try:
if not os.path.exists(directory):
os.makedirs(directory)
p = sarge.run("mount -o iocharset=utf8 %s '%s'" % (partition, directory), stderr=sarge.Capture())
if p.returncode != 0:
returncode = p.returncode
stderr_text = p.stderr.text
self._logger.warn("Partition mount failed with return code %i: %s" % (returncode, stderr_text))
return False
else:
self._logger.info("Partition %s mounted on %s" % (partition, directory))
return True
except Exception, e:
self._logger.warn("Mount failed: %s" % e)
return False
示例3: setup
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def setup():
global server, driver
if not have_selenium:
raise SkipTest("Tests require Selenium")
default_setup()
for step in setup_steps:
if callable(step):
step()
else:
print(step[0]) # description
run_test(*step[1:])
server = sarge.Command("smtweb -p 8765 --no-browser", cwd=utils.working_dir,
stdout=sarge.Capture(), stderr=sarge.Capture())
server.run(async=True)
driver = webdriver.Firefox()
示例4: performSystemAction
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def performSystemAction(self,action,sendResponse):
available_actions = settings().get(["system", "actions"])
logger = logging.getLogger(__name__)
for availableAction in available_actions:
if availableAction["action"] == action:
command = availableAction["command"]
if command:
logger.info("Performing command: %s" % command)
def executeCommand(command, logger):
time.sleep(0.5) #add a small delay to make sure the response is sent
try:
p = sarge.run(command, stderr=sarge.Capture())
if p.returncode != 0:
returncode = p.returncode
stderr_text = p.stderr.text
logger.warn("Command failed with return code %i: %s" % (returncode, stderr_text))
sendResponse({'success': False})
else:
logger.info("Command executed sucessfully")
sendResponse({'success': True})
except Exception, e:
logger.warn("Command failed: %s" % e)
executeThread = threading.Thread(target=executeCommand, args=(command, logger))
executeThread.start()
else:
logger.warn("Action %s is misconfigured" % action)
sendResponse('action_not_configured', True)
return
示例5: stopHotspot
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def stopHotspot(self):
try:
p = sarge.run("service wifi_access_point stop", stderr=sarge.Capture())
if p.returncode != 0:
returncode = p.returncode
stderr_text = p.stderr.text
logger.warn("Stop hotspot failed with return code %i: %s" % (returncode, stderr_text))
return "Stop hotspot failed with return code %i: %s" % (returncode, stderr_text)
else:
return True
except Exception, e:
logger.warn("Stop hotspot failed with return code: %s" % e)
return "Stop hotspot failed with return code: %s" % e
示例6: _run_command
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def _run_command(
self, env, command=None, output_handler=None, return_code_handler=None
):
if not command:
command = self.options["command"]
interactive_mode = process_bool_arg(self.options["interactive"])
self.logger.info("Running command: %s", command)
p = sarge.Command(
command,
stdout=sys.stdout if interactive_mode else sarge.Capture(buffer_size=-1),
stderr=sys.stderr if interactive_mode else sarge.Capture(buffer_size=-1),
shell=True,
env=env,
cwd=self.options.get("dir"),
)
if interactive_mode:
p.run(input=sys.stdin)
else:
p.run(async_=True)
# Handle output lines
if not output_handler:
output_handler = self._process_output
while True:
line = p.stdout.readline(timeout=1.0)
if line:
output_handler(line)
elif p.poll() is not None:
break
p.wait()
# Handle return code
if not return_code_handler:
return_code_handler = self._handle_returncode
return_code_handler(p.returncode, None if interactive_mode else p.stderr)
示例7: test_run_task
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def test_run_task(self, sarge):
p = mock.Mock()
p.returncode = 0
p.stdout = Capture()
p.stdout.add_stream(BytesIO(b"testing testing 123"))
p.stderr = Capture()
p.stderr.add_stream(BytesIO(b"e"))
sarge.Command.return_value = p
self.task_config.config["options"] = {"command": "ls -la"}
task = Command(self.project_config, self.task_config)
task()
assert any("testing testing" in s for s in self.task_log["info"])
示例8: get_git_config
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def get_git_config(config_key):
p = sarge.Command(
sarge.shell_format('git config --get "{0!s}"', config_key),
stderr=sarge.Capture(buffer_size=-1),
stdout=sarge.Capture(buffer_size=-1),
shell=True,
)
p.run()
config_value = (
io.TextIOWrapper(p.stdout, encoding=sys.stdout.encoding).read().strip()
)
return config_value if config_value and not p.returncode else None
示例9: _process_snapshot
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def _process_snapshot(self, snapshot_path, pixfmt="yuv420p"):
hflip = self._settings.global_get_boolean(["webcam", "flipH"])
vflip = self._settings.global_get_boolean(["webcam", "flipV"])
rotate = self._settings.global_get_boolean(["webcam", "rotate90"])
ffmpeg = self._settings.global_get(["webcam", "ffmpeg"])
if not ffmpeg or not os.access(ffmpeg, os.X_OK) or (not vflip and not hflip and not rotate):
return
ffmpeg_command = [ffmpeg, "-y", "-i", snapshot_path]
rotate_params = ["format={}".format(pixfmt)] # workaround for foosel/OctoPrint#1317
if rotate:
rotate_params.append("transpose=2") # 90 degrees counter clockwise
if hflip:
rotate_params.append("hflip") # horizontal flip
if vflip:
rotate_params.append("vflip") # vertical flip
ffmpeg_command += ["-vf", sarge.shell_quote(",".join(rotate_params)), snapshot_path]
self._logger.info("Running: {}".format(" ".join(ffmpeg_command)))
p = sarge.run(ffmpeg_command, stdout=sarge.Capture(), stderr=sarge.Capture())
if p.returncode == 0:
self._logger.info("Rotated/flipped image with ffmpeg")
else:
self._logger.warn("Failed to rotate/flip image with ffmpeg, "
"got return code {}: {}, {}".format(p.returncode,
p.stdout.text,
p.stderr.text))
示例10: check_soc_temp
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def check_soc_temp(self):
if self.debugMode:
import random
return str(round(random.uniform(5, 60), 2))
if self.is_supported:
from sarge import run, Capture
p = run(self.temp_cmd, stdout=Capture())
if p.returncode == 1:
self.is_supported = False
self._logger.debug("SoC temperature not found.")
else:
p = p.stdout.text
self._logger.debug("response from sarge: %s" % p)
self._logger.debug("used pattern: %r" % self.parse_pattern)
match = re.search(self.parse_pattern, p)
temp = 0
if not match:
self._logger.debug("match: not found")
self.is_supported = False
else:
temp = self.parse_temperature(match)
self._logger.debug("match: %s" % str(temp))
return temp
return 0
示例11: run
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def run(command):
"""Run a command in the Sumatra project directory and capture the output."""
return sarge.run(command, cwd=working_dir, stdout=sarge.Capture(timeout=10, buffer_size=1))
示例12: performSystemAction
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def performSystemAction():
if "action" in request.values.keys():
action = request.values["action"]
available_actions = s().get(["system", "actions"])
logger = logging.getLogger(__name__)
for availableAction in available_actions:
if availableAction["action"] == action:
command = availableAction["command"]
if command:
logger.info("Performing command: %s" % command)
def executeCommand(command, logger):
timeSleeping = 0.5
#if shutdown send message to plugin
if action == "reboot" or action == "shutdown":
eventManager().fire(Events.SHUTTING_DOWN, {'status': action})
timeSleeping = 1
time.sleep(timeSleeping) #add a small delay to make sure the response is sent
try:
p = sarge.run(command, stderr=sarge.Capture())
if p.returncode != 0:
returncode = p.returncode
stderr_text = p.stderr.text
logger.warn("Command failed with return code %i: %s" % (returncode, stderr_text))
if action == "reboot" or action == "shutdown":
eventManager().fire(Events.SHUTTING_DOWN, {'status': None})
else:
logger.info("Command executed sucessfully")
except Exception, e:
logger.warn("Command failed: %s" % e)
if command == "reboot" or command == "shutdown":
eventManager().fire(Events.SHUTTING_DOWN, {'status': None})
executeThread = threading.Thread(target=executeCommand, args=(command, logger))
executeThread.start()
return OK
else:
logger.warn("Action %s is misconfigured" % action)
return ("Misconfigured action", 500)
logger.warn("No suitable action in config for: %s" % action)
return ("Command not found", 404)
示例13: sfdx
# 需要导入模块: import sarge [as 别名]
# 或者: from sarge import Capture [as 别名]
def sfdx(
command,
username=None,
log_note=None,
access_token=None,
args=None,
env=None,
capture_output=True,
check_return=False,
):
"""Call an sfdx command and capture its output.
Be sure to quote user input that is part of the command using `shell_quote`.
Returns a `sarge` Command instance with returncode, stdout, stderr
"""
command = "sfdx {}".format(command)
if args is not None:
for arg in args:
command += " " + shell_quote(arg)
if username:
command += f" -u {shell_quote(username)}"
if log_note:
logger.info("{} with command: {}".format(log_note, command))
# Avoid logging access token
if access_token:
command += f" -u {shell_quote(access_token)}"
p = sarge.Command(
command,
stdout=sarge.Capture(buffer_size=-1) if capture_output else None,
stderr=sarge.Capture(buffer_size=-1) if capture_output else None,
shell=True,
env=env,
)
p.run()
if capture_output or (check_return and p.returncode):
p.stdout_text = io.TextIOWrapper(p.stdout, encoding=sys.stdout.encoding)
p.stderr_text = io.TextIOWrapper(p.stderr, encoding=sys.stdout.encoding)
if check_return and p.returncode:
raise Exception(
f"Command exited with return code {p.returncode}:\n{p.stderr_text.read()}"
)
return p