Utility functions for MRJob that have no external dependencies.
For the given OptionParser and list of command line arguments args, yield values in args that correspond to option destinations in the set of strings dests. If dests is None, return args as parsed by OptionParser.
Escape single quotes in a shell command string and wrap it with bash -c '<string>'.
This low-tech replacement works because we control the surrounding string and single quotes are the only character in a single-quote string that needs escaping.
boto’s file iterator splits by buffer size instead of by newline. This wrapper puts them back into lines.
Warning
This may append a newline to your last chunk of data. In v0.5.0 it will not, for better compatibility with file objects.
Decompress gzipped data on the fly.
Parameters: |
|
---|
Warning
This yields lines for backwards compatibility only; in v0.5.0 it will yield arbitrary chunks of data as part of supporting non-line-based protocols (see Issue #715). If you want lines, wrap this in buffer_iterator_to_line_iterator().
build a command line that works in a shell.
Resolve ~ (home dir) and environment variables in path.
If path is None, return None.
Deprecated since version 0.4.0.
Get the name of the directory the tar at archive_path extracts into.
Parameters: |
---|
return the file extension, including the .
>>> file_ext('foo.tar.gz')
'.tar.gz'
Decompress gzipped data on the fly.
Parameters: |
|
---|
Warning
This yields decompressed chunks; it does not split on lines. To get lines, wrap this in buffer_iterator_to_line_iterator().
Generate a hash (currently md5) of the repr of the object
Deprecated since version 0.4.
Set up a null handler for the given stream, to suppress “no handlers could be found” warnings.
Set up logging.
Parameters: |
|
---|
DEPRECATED. To be removed in v0.5.
Duplicate behavior of OptionParser, but capture the strings required to reproduce the same values. Ref. optparse.py lines 1414-1548 (python 2.6.5)
Given a dictionary mapping OptionGroup and OptionParser objects to a list of strings represention option dests, populate the objects with options from indexed_options (generated by scrape_options_and_index_by_dest()) in alphabetical order by long option name. This function primarily exists to serve scrape_options_into_new_groups().
Parameters: |
|
---|
Yields lines from a file, possibly decompressing it based on file extension.
Currently we handle compressed files with the extensions .gz and .bz2.
Parameters: |
|
---|
Stream input the way Hadoop would.
You can redefine stdin for ease of testing. stdin can actually be any iterable that yields lines (e.g. a list).
Like eval, but with nearly everything in the environment blanked out, so that it’s difficult to cause mischief.
globals and locals are optional dictionaries mapping names to values for those names (just like in eval()).
Context manager that saves os.environ and loads it back again after execution
Context manager that saves the current working directory, and chdir’s back to it after execution.
Scrapes optparse options from OptionParser and OptionGroup objects and builds a dictionary of dest_var: [option1, option2, ...]. This function primarily exists to serve scrape_options_into_new_groups().
An example return value: {'verbose': [<verbose_on_option>, <verbose_off_option>], 'files': [<file_append_option>]}
Parameters: | parsers_and_groups (OptionParser or OptionGroup) – Parsers and groups to scrape option objects from |
---|---|
Returns: | dict of the form {dest_var: [option1, option2, ...], ...} |
Puts options from the OptionParser and OptionGroup objects in source_groups into the keys of assignments according to the values of assignments. An example:
Parameters: |
|
---|
Wrapper around shlex.split(), but convert to str if Python version < 2.7.3 when unicode support was added.
Return the given datetime.timedelta, without microseconds.
Useful for printing datetime.timedelta objects.
Tar and gzip the given dir to a tarball at out_path.
If we encounter symlinks, include the actual file, not the symlink.
Parameters: |
---|
Extract the contents of a tar or zip file at archive_path into the directory dest.
Parameters: |
---|
dest will be created if it doesn’t already exist.
tar files can be gzip compressed, bzip2 compressed, or uncompressed. Files within zip files can be deflated or stored.