Command


Attributes

a default_interactive

0

a default_verbosity

0

a description

None

a group_name

''

a hidden

False

a max_args

None

a max_args_error

'You must provide no more than %(max_args)s arguments'

a min_args

None

a min_args_error

'You must provide at least %(min_args)s arguments'

a required_args

()

a return_code

0

a takes_config_file

None

a usage

''

Methods

f __init__(self, name) ...

f run(self, args) ...

f parse_args(self, args) ...

f here(cls) ...

f ask(self, prompt, safe=False, default=True) ...

Prompt the user. Default can be true, false, 'careful' or 'none'. If 'none' then the user must enter y/n. If 'careful' then the user must enter yes/no (long form).

If the interactive option is over two (-ii) then safe will be used as a default. This option should be the do-nothing option.

f challenge(self, prompt, default=<class 'paste.script.command.NoDefault'>, should_echo=True) ...

Prompt the user for a variable.

f pad(self, s, length, dir='left') ...

f standard_parser(cls, verbose=True, interactive=False, no_interactive=False, simulate=False, quiet=False, overwrite=False) ...

Create a standard OptionParser instance.

Typically used like:

class MyCommand(Command):
    parser = Command.standard_parser()

Subclasses may redefine standard_parser, so use the nearest superclass's class method.

f shorten(self, fn, *paths) ...

Return a shorted form of the filename (relative to the current directory), typically for displaying in messages. If *paths are present, then use os.path.join to create the full filename before shortening.

f ensure_dir(self, dir, svn_add=True) ...

Ensure that the directory exists, creating it if necessary. Respects verbosity and simulation.

Adds directory to subversion if .svn/ directory exists in parent, and directory was created.

f ensure_file(self, filename, content, svn_add=True) ...

Ensure a file named filename exists with the given content. If --interactive has been enabled, this will ask the user what to do if a file exists with different content.

f insert_into_file(self, filename, marker_name, text, indent=False) ...

Inserts text into the file, right after the given marker. Markers look like: -*- <marker_name>[:]? -*-, and the text will go on the immediately following line.

Raises ValueError if the marker is not found.

If indent is true, then the text will be indented at the same level as the marker.

f run_command(self, cmd, *args, **kw) ...

Runs the command, respecting verbosity and simulation. Returns stdout, or None if simulating.

Keyword arguments:

cwd:
the current working directory to run the command in
capture_stderr:
if true, then both stdout and stderr will be returned
expect_returncode:
if true, then don't fail if the return code is not 0
force_no_simulate:
if true, run the command even if --simulate

f quote_first_command_arg(self, arg) ...

There's a bug in Windows when running an executable that's located inside a path with a space in it. This method handles that case, or on non-Windows systems or an executable with no spaces, it just leaves well enough alone.

f svn_command(self, *args, **kw) ...

Run an svn command, but don't raise an exception if it fails.

f write_file(self, filename, content, source=None, binary=True, svn_add=True) ...

Like ensure_file, but without the interactivity. Mostly deprecated. (I think I forgot it existed)

f parse_vars(self, args) ...

Given variables like ['a=b', 'c=d'] turns it into {'a': 'b', 'c': 'd'}

f read_vars(self, config, section='pastescript') ...

Given a configuration filename, this will return a map of values.

f write_vars(self, config, vars, section='pastescript') ...

Given a configuration filename, this will add items in the vars mapping to the configuration file. Will create the configuration file if it doesn't exist.

f indent_block(self, text, indent=2, initial=None) ...

Indent the block of text (each line is indented). If you give initial, then that is used in lieue of indent for the first line.

f logging_file_config(self, config_file) ...

Setup logging via the logging module's fileConfig function with the specified config_file, if applicable.

See the source for more information.