本文整理汇总了PHP中csprintf函数的典型用法代码示例。如果您正苦于以下问题:PHP csprintf函数的具体用法?PHP csprintf怎么用?PHP csprintf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了csprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPasswords
public function testPasswords()
{
// Normal "%s" doesn't do anything special.
$command = csprintf('echo %s', 'hunter2trustno1');
$this->assertTrue(strpos($command, 'hunter2trustno1') !== false);
// "%P" takes a PhutilOpaqueEnvelope.
$caught = null;
try {
csprintf('echo %P', 'hunter2trustno1');
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertTrue($caught instanceof Exception);
// "%P" masks the provided value.
$command = csprintf('echo %P', new PhutilOpaqueEnvelope('hunter2trustno1'));
$this->assertFalse(strpos($command, 'hunter2trustno1'));
// Executing the command works as expected.
list($out) = execx('%C', $command);
$this->assertTrue(strpos($out, 'hunter2trustno1') !== false);
// Escaping should be robust even when used to escape commands which take
// other commands.
if (!phutil_is_windows()) {
list($out) = execx('sh -c %s', csprintf('sh -c %s', csprintf('sh -c %s', csprintf('echo %P', new PhutilOpaqueEnvelope('!@#$%^&*()')))));
$this->assertTrue(strpos($out, '!@#$%^&*()') !== false);
}
}
示例2: buildTestFuture
public function buildTestFuture($test_output, $cover_output) {
$paths = $this->getPaths();
$cmd_line = csprintf('source bin/activate; coverage run --source nylas -m py.test --junitxml tests/output tests; coverage xml -i -o tests/coverage');
return new ExecFuture('%C', $cmd_line);
}
示例3: phutil_console_prompt
/**
* @group console
*/
function phutil_console_prompt($prompt, $history = '')
{
echo "\n\n";
$prompt = phutil_console_wrap($prompt . ' ', 4);
try {
phutil_console_require_tty();
} catch (PhutilConsoleStdinNotInteractiveException $ex) {
// Throw after echoing the prompt so the user has some idea what happened.
echo $prompt;
throw $ex;
}
$use_history = true;
if ($history == '') {
$use_history = false;
} else {
// Test if bash is available by seeing if it can run `true`.
list($err) = exec_manual('bash -c %s', 'true');
if ($err) {
$use_history = false;
}
}
if (!$use_history) {
echo $prompt;
$response = fgets(STDIN);
} else {
// There's around 0% chance that readline() is available directly in PHP,
// so we're using bash/read/history instead.
$command = csprintf('bash -c %s', csprintf('history -r %s 2>/dev/null; ' . 'read -e -p %s; ' . 'echo "$REPLY"; ' . 'history -s "$REPLY" 2>/dev/null; ' . 'history -w %s 2>/dev/null', $history, $prompt, $history));
// execx() doesn't work with input, phutil_passthru() doesn't return output.
$response = shell_exec($command);
}
return rtrim($response, "\r\n");
}
示例4: sudoCommandAsDaemonUser
/**
* Format a command so it executes as the daemon user, if a daemon user is
* defined. This wraps the provided command in `sudo -u ...`, roughly.
*
* @param PhutilCommandString Command to execute.
* @return PhutilCommandString `sudo` version of the command.
*/
public static function sudoCommandAsDaemonUser($command)
{
$user = PhabricatorEnv::getEnvConfig('phd.user');
if (!$user) {
// No daemon user is set, so just run this as ourselves.
return $command;
}
// We may reach this method while already running as the daemon user: for
// example, active and passive synchronization of clustered repositories
// run the same commands through the same code, but as different users.
// By default, `sudo` won't let you sudo to yourself, so we can get into
// trouble if we're already running as the daemon user unless the host has
// been configured to let the daemon user run commands as itself.
// Since this is silly and more complicated than doing this check, don't
// use `sudo` if we're already running as the correct user.
if (function_exists('posix_getuid')) {
$uid = posix_getuid();
$info = posix_getpwuid($uid);
if ($info && $info['name'] == $user) {
return $command;
}
}
// Get the absolute path so we're safe against the caller wiping out
// PATH.
$sudo = Filesystem::resolveBinary('sudo');
if (!$sudo) {
throw new Exception(pht("Unable to find 'sudo'!"));
}
// Flags here are:
//
// -E: Preserve the environment.
// -n: Non-interactive. Exit with an error instead of prompting.
// -u: Which user to sudo to.
return csprintf('%s -E -n -u %s -- %C', $sudo, $user, $command);
}
示例5: renderPropertyViewValue
public function renderPropertyViewValue(array $handles)
{
$revision = $this->getObject();
$diff = $revision->getActiveDiff();
$status = $revision->getStatus();
if ($status != ArcanistDifferentialRevisionStatus::ACCEPTED) {
return null;
}
$local_vcs = $diff->getSourceControlSystem();
switch ($local_vcs) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$bookmark = $diff->getBookmark();
if (strlen($bookmark)) {
$next_step = csprintf('arc land %R', $bookmark);
} else {
$next_step = csprintf('arc land');
}
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$branch = $diff->getBranch();
if (strlen($branch)) {
$next_step = csprintf('arc land %R', $branch);
} else {
$next_step = csprintf('arc land');
}
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$next_step = csprintf('arc commit');
break;
default:
return null;
}
$next_step = phutil_tag('tt', array(), (string) $next_step);
return $next_step;
}
示例6: getProxyCommand
protected function getProxyCommand()
{
$uri = new PhutilURI($this->proxyURI);
$username = PhabricatorEnv::getEnvConfig('cluster.instance');
if (!strlen($username)) {
$username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user');
if (!strlen($username)) {
throw new Exception(pht('Unable to determine the username to connect with when trying ' . 'to proxy an SSH request within the Phabricator cluster.'));
}
}
$port = $uri->getPort();
$host = $uri->getDomain();
$key_path = AlmanacKeys::getKeyPath('device.key');
if (!Filesystem::pathExists($key_path)) {
throw new Exception(pht('Unable to proxy this SSH request within the cluster: this device ' . 'is not registered and has a missing device key (expected to ' . 'find key at "%s").', $key_path));
}
$options = array();
$options[] = '-o';
$options[] = 'StrictHostKeyChecking=no';
$options[] = '-o';
$options[] = 'UserKnownHostsFile=/dev/null';
// This is suppressing "added <address> to the list of known hosts"
// messages, which are confusing and irrelevant when they arise from
// proxied requests. It might also be suppressing lots of useful errors,
// of course. Ideally, we would enforce host keys eventually.
$options[] = '-o';
$options[] = 'LogLevel=quiet';
// NOTE: We prefix the command with "@username", which the far end of the
// connection will parse in order to act as the specified user. This
// behavior is only available to cluster requests signed by a trusted
// device key.
return csprintf('ssh %Ls -l %s -i %s -p %s %s -- %s %Ls', $options, $username, $key_path, $port, $host, '@' . $this->getUser()->getUsername(), $this->getOriginalArguments());
}
示例7: getPEP8Path
public function getPEP8Path()
{
$working_copy = $this->getEngine()->getWorkingCopy();
$prefix = $working_copy->getConfig('lint.pep8.prefix');
$bin = $working_copy->getConfig('lint.pep8.bin');
if ($bin === null && $prefix === null) {
$bin = csprintf('/usr/bin/env python2.6 %s', phutil_get_library_root('arcanist') . '/../externals/pep8/pep8.py');
} else {
if ($bin === null) {
$bin = 'pep8';
}
if ($prefix !== null) {
if (!Filesystem::pathExists($prefix . '/' . $bin)) {
throw new ArcanistUsageException("Unable to find PEP8 binary in a specified directory. Make sure " . "that 'lint.pep8.prefix' and 'lint.pep8.bin' keys are set " . "correctly. If you'd rather use a copy of PEP8 installed " . "globally, you can just remove these keys from your .arcconfig");
}
$bin = csprintf("%s/%s", $prefix, $bin);
return $bin;
}
// Look for globally installed PEP8
list($err) = exec_manual('which %s', $bin);
if ($err) {
throw new ArcanistUsageException("PEP8 does not appear to be installed on this system. Install it " . "(e.g., with 'easy_install pep8') or configure " . "'lint.pep8.prefix' in your .arcconfig to point to the directory " . "where it resides.");
}
}
return $bin;
}
示例8: executeAcquireLease
public function executeAcquireLease(DrydockResource $resource, DrydockLease $lease)
{
$key = Filesystem::readRandomCharacters(12);
$ports = $resource->getAttribute('ports', array());
for ($ii = 2000;; $ii++) {
if (empty($ports[$ii])) {
$ports[$ii] = $lease->getID();
$port = $ii;
break;
}
}
$resource->setAttribute('ports', $ports);
$resource->save();
$host = $resource->getAttribute('host');
$lease->setAttribute('port', $port);
$lease->setAttribute('key', $key);
$lease->save();
$config = <<<EOCONFIG
Listen *:{$port}
<VirtualHost *:{$port}>
DocumentRoot /opt/drydock/webroot/{$key}/
ServerName {$host}
</VirtualHost>
EOCONFIG;
$cmd = $this->getInterface($resource, $lease, 'command');
$cmd->execx(<<<EOSETUP
sudo mkdir -p %s &&
sudo sh -c %s &&
sudo /etc/init.d/httpd restart
EOSETUP
, "/opt/drydock/webroot/{$key}/", csprintf('echo %s > %s', $config, "/etc/httpd/conf.d/drydock-{$key}.conf"));
$lease->setAttribute('uri', "http://{$host}:{$port}/");
$lease->save();
}
示例9: getExecFuture
public function getExecFuture($command)
{
$this->openCredentialsIfNotOpen();
$argv = func_get_args();
if ($this->getConfig('platform') === 'windows') {
// Handle Windows by executing the command under PowerShell.
$command = id(new PhutilCommandString($argv))->setEscapingMode(PhutilCommandString::MODE_POWERSHELL);
$change_directory = '';
if ($this->getWorkingDirectory() !== null) {
$change_directory .= 'cd ' . $this->getWorkingDirectory();
}
$script = <<<EOF
{$change_directory}
{$command}
if (\$LastExitCode -ne 0) {
exit \$LastExitCode
}
EOF;
// When Microsoft says "Unicode" they don't mean UTF-8.
$script = mb_convert_encoding($script, 'UTF-16LE');
$script = base64_encode($script);
$powershell = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe';
$powershell .= ' -ExecutionPolicy Bypass' . ' -NonInteractive' . ' -InputFormat Text' . ' -OutputFormat Text' . ' -EncodedCommand ' . $script;
$full_command = $powershell;
} else {
// Handle UNIX by executing under the native shell.
$argv = $this->applyWorkingDirectoryToArgv($argv);
$full_command = call_user_func_array('csprintf', $argv);
}
$command_timeout = '';
if ($this->connectTimeout !== null) {
$command_timeout = csprintf('-o %s', 'ConnectTimeout=' . $this->connectTimeout);
}
return new ExecFuture('ssh ' . '-o LogLevel=quiet ' . '-o StrictHostKeyChecking=no ' . '-o UserKnownHostsFile=/dev/null ' . '-o BatchMode=yes ' . '%C -p %s -i %P %P@%s -- %s', $command_timeout, $this->getConfig('port'), $this->passphraseSSHKey->getKeyfileEnvelope(), $this->passphraseSSHKey->getUsernameEnvelope(), $this->getConfig('host'), $full_command);
}
示例10: executeRepositoryOperations
protected function executeRepositoryOperations()
{
$repository = $this->getRepository();
$args = $this->getArgs();
if (!$args->getArg('stdio')) {
throw new Exception(pht('Expected `%s`!', 'hg ... --stdio'));
}
if ($args->getArg('command') !== array('serve')) {
throw new Exception(pht('Expected `%s`!', 'hg ... serve'));
}
if ($this->shouldProxy()) {
$command = $this->getProxyCommand();
} else {
$command = csprintf('hg -R %s serve --stdio', $repository->getLocalPath());
}
$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command);
$future = id(new ExecFuture('%C', $command))->setEnv($this->getEnvironment());
$io_channel = $this->getIOChannel();
$protocol_channel = new DiffusionMercurialWireClientSSHProtocolChannel($io_channel);
$err = id($this->newPassthruCommand())->setIOChannel($protocol_channel)->setCommandChannelFromExecFuture($future)->setWillWriteCallback(array($this, 'willWriteMessageCallback'))->execute();
// TODO: It's apparently technically possible to communicate errors to
// Mercurial over SSH by writing a special "\n<error>\n-\n" string. However,
// my attempt to implement that resulted in Mercurial closing the socket and
// then hanging, without showing the error. This might be an issue on our
// side (we need to close our half of the socket?), or maybe the code
// for this in Mercurial doesn't actually work, or maybe something else
// is afoot. At some point, we should look into doing this more cleanly.
// For now, when we, e.g., reject writes for policy reasons, the user will
// see "abort: unexpected response: empty string" after the diagnostically
// useful, e.g., "remote: This repository is read-only over SSH." message.
if (!$err && $this->didSeeWrite) {
$repository->writeStatusMessage(PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, PhabricatorRepositoryStatusMessage::CODE_OKAY);
}
return $err;
}
示例11: executeRepositoryOperations
protected function executeRepositoryOperations()
{
$repository = $this->getRepository();
$viewer = $this->getUser();
$device = AlmanacKeys::getLiveDevice();
$skip_sync = $this->shouldSkipReadSynchronization();
if ($this->shouldProxy()) {
$command = $this->getProxyCommand();
if ($device) {
$this->writeClusterEngineLogMessage(pht("# Fetch received by \"%s\", forwarding to cluster host.\n", $device->getName()));
}
} else {
$command = csprintf('git-upload-pack -- %s', $repository->getLocalPath());
if (!$skip_sync) {
$cluster_engine = id(new DiffusionRepositoryClusterEngine())->setViewer($viewer)->setRepository($repository)->setLog($this)->synchronizeWorkingCopyBeforeRead();
if ($device) {
$this->writeClusterEngineLogMessage(pht("# Cleared to fetch on cluster host \"%s\".\n", $device->getName()));
}
}
}
$command = PhabricatorDaemon::sudoCommandAsDaemonUser($command);
$future = id(new ExecFuture('%C', $command))->setEnv($this->getEnvironment());
$err = $this->newPassthruCommand()->setIOChannel($this->getIOChannel())->setCommandChannelFromExecFuture($future)->execute();
if (!$err) {
$this->waitForGitClient();
}
return $err;
}
示例12: writeFile
public function writeFile($path, $data)
{
$source = new TempFile();
Filesystem::writeFile($source, $data);
$future = $this->getExecFuture($path);
$future->write(csprintf('put %s %s', $source, $path));
$future->resolvex();
}
示例13: getVersion
protected function getVersion()
{
$cmd = csprintf('%s version', $this->getBinary());
list($stdout) = execx('%C', $cmd);
$matches = array();
preg_match('/^go version go(?P<version>[0-9\\.]+).*/', $stdout, $matches);
return $matches['version'];
}
示例14: buildTestFuture
public function buildTestFuture($junit_tmp, $cover_tmp)
{
$paths = $this->getPaths();
$config_manager = $this->getConfigurationManager();
$coverage_command = $config_manager->getConfigFromAnySource('unit.pytest.command');
$cmd_line = csprintf($coverage_command, $junit_tmp);
return new ExecFuture('%C', $cmd_line);
}
示例15: buildTestFuture
public function buildTestFuture($path, $xunit_tmp, $cover_tmp)
{
$cmd_line = csprintf('nosetests --with-xunit --xunit-file=%s', $xunit_tmp);
if ($this->getEnableCoverage() !== false) {
$cmd_line .= csprintf(' --with-coverage --cover-xml --cover-xml-file=%s', $cover_tmp);
}
return new ExecFuture('%C %s', $cmd_line, $path);
}