當前位置: 首頁>>代碼示例>>Python>>正文


Python sarge.Capture方法代碼示例

本文整理匯總了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 
開發者ID:AstroPrint,項目名稱:AstroBox,代碼行數:25,代碼來源:debian.py

示例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 
開發者ID:AstroPrint,項目名稱:AstroBox,代碼行數:22,代碼來源:linux.py

示例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() 
開發者ID:open-research,項目名稱:sumatra,代碼行數:18,代碼來源:test_webui.py

示例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 
開發者ID:AstroPrint,項目名稱:AstroBox,代碼行數:36,代碼來源:system.py

示例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 
開發者ID:AstroPrint,項目名稱:AstroBox,代碼行數:16,代碼來源:debian.py

示例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) 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:39,代碼來源:command.py

示例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"]) 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:16,代碼來源:test_command.py

示例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 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:15,代碼來源:__init__.py

示例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)) 
開發者ID:OctoPrint,項目名稱:OctoPrint-Pushbullet,代碼行數:32,代碼來源:__init__.py

示例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 
開發者ID:imrahil,項目名稱:OctoPrint-NavbarTemp,代碼行數:31,代碼來源:sbc.py

示例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)) 
開發者ID:open-research,項目名稱:sumatra,代碼行數:5,代碼來源:utils.py

示例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) 
開發者ID:AstroPrint,項目名稱:AstroBox,代碼行數:49,代碼來源:__init__.py

示例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 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:45,代碼來源:sfdx.py


注:本文中的sarge.Capture方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。