Misc. Tools (rever.tools)

Some special rever tools

rever.tools.check_gpg()

Checks that gpg is available and useable. Returns a boolean and message.

rever.tools.download(url, encoding=None, errors=None, **kwargs)

Gets a URL in a given encoding.

rever.tools.download_bytes(url, **kwargs)

Gets the bytes from a URL

rever.tools.eval_version(v)

Evalauates the argument either as a template string which contains $VERSION (or other environment variables) or a callable which takes a single argument (that is $VERSION) and returns a string.

rever.tools.get_format_field_names(s)

Returns the set of field names in a format string.

rever.tools.hash_url(url, hash='sha256', quiet=False)

Hashes a URL, with a progress bar, and returns the hex representation

rever.tools.indir(d)

Context manager for temporarily entering into a directory.

rever.tools.progress(count, total=None, prefix='', suffix='', width=60, file=None, fill='`·.,¸,.·*¯`·.,¸,.·*¯', color=None, empty=' ', quiet=False)

CLI progress bar

rever.tools.render_authors(authors)

Parse a list of of tuples of authors into valid bibtex

Parameters
authors: list of str

The authors eg [‘Your name in nicely formatted bibtex’]. Please see <http://nwalsh.com/tex/texhelp/bibtx-23.html> for information about how to format your name for bibtex

Returns
str:

Valid bibtex authors

rever.tools.replace_in_file(pattern, new, fname, leading_whitespace=True)

Replaces a given pattern in a file. If leading whitespace is True, whitespace at the begining of a line will be captured and preserved. Otherwise, the pattern itself must contain all leading whitespace.

rever.tools.stream_url_progress(url, verb='downloading', chunksize=1024, width=60, quiet=False)

Generator yielding successive bytes from a URL.

Parameters
urlstr

URL to open and stream

verbstr

Verb to prefix the url downloading with, default ‘downloading’

chunksizeint

Number of bytes to return, defaults to 1 kb.

quietbool, optional

If true don’t print out progress bar, defaults to False

Returns
yields the bytes which is at most chunksize in length.
rever.tools.user_group(filename, return_ids=False)

Returns the user and group name for a file, and optionally ids too. returns (user_name, group_name) if return_ids is False. If True, returns (user_name, group_name, user_id, group_id). On windows, the user id and group id will be None and the group name will be the same as the user name.