features/unicode_import / Lib /

The branch 'legacy-trunk' does not exist.
# Module 'commands'
# Various tools for executing commands and looking at their output and status.
# NB This only works (and is only relevant) for UNIX.

# Get 'ls -l' status for an object into a string
def getstatus(file):
	return getoutput('ls -ld' + mkarg(file))

# Get the output from a shell command into a string.
# The exit status is ignored; a trailing newline is stripped.
# Assume the command will work with '{ ... ; } 2>&1' around it..
def getoutput(cmd):
	return getstatusoutput(cmd)[1]

# Ditto but preserving the exit status.
# Returns a pair (sts, output)
def getstatusoutput(cmd):
	import os
	pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
	text =
	sts = pipe.close()
	if sts == None: sts = 0
	if text[-1:] == '\n': text = text[:-1]
	return sts, text

# Make command argument from directory and pathname (prefix space, add quotes).
def mk2arg(head, x):
	import os
	return mkarg(os.path.join(head, x))

# Make a shell command argument from a string.
# Two strategies: enclose in single quotes if it contains none;
# otherwise, enclose in double quotes and prefix quotable characters
# with backslash.
def mkarg(x):
	if '\'' not in x:
		return ' \'' + x + '\''
	s = ' "'
	for c in x:
		if c in '\\$"`':
			s = s + '\\'
		s = s + c
	s = s + '"'
	return s
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.