updater4pyi.util module

A collection of various utilities.

updater4pyi.util.applescript_quote(x)[source]
updater4pyi.util.bash_quote(x)[source]
updater4pyi.util.dirIsWritable(directory)[source]
updater4pyi.util.ensure_datetime(x)[source]
updater4pyi.util.ensure_timedelta(x)[source]
updater4pyi.util.fileIsWritable(fn)[source]
updater4pyi.util.getbool(x)[source]

Utility to parse a string representing a boolean value.

If x is already of integer or boolean type (actually, anything castable to an integer), then the corresponding boolean convertion is returned. If it is a string-like type, then it is matched against something that looks like ‘t(rue)?’, ‘1’, ‘y(es)?’ or ‘on’ (ignoring case), or against something that looks like ‘f(alse)?’, ‘0’, ‘n(o)?’ or ‘off’ (also ignoring case). Leading or trailing whitespace is ignored. If the string cannot be parsed, a ValueError is raised.

updater4pyi.util.ignore_exc(f, exc=(<type 'exceptions.Exception'>, ), value_if_exc=None)[source]
updater4pyi.util.is_linux()[source]
updater4pyi.util.is_macosx()[source]
updater4pyi.util.is_win()[source]
updater4pyi.util.locationIsWritable(path)[source]
updater4pyi.util.parse_version(s)[source]

Convert a version string to a chronologically-sortable key

This function is based on code from setuptools. (I didn’t find any license text to copy from that project, but on PyPI it states that the license is ‘PSF or ZPL‘.)

This is a rough cross between distutils’ StrictVersion and LooseVersion; if you give it versions that would work with StrictVersion, then it behaves the same; otherwise it acts like a slightly-smarter LooseVersion. It is possible to create pathological version coding schemes that will fool this parser, but they should be very rare in practice.

The returned value will be a tuple of strings. Numeric portions of the version are padded to 8 digits so they will compare numerically, but without relying on how numbers compare relative to strings. Dots are dropped, but dashes are retained. Trailing zeros between alpha segments or dashes are suppressed, so that e.g. “2.4.0” is considered the same as “2.4”. Alphanumeric parts are lower-cased.

The algorithm assumes that strings like “-” and any alpha string that alphabetically follows “final” represents a “patch level”. So, “2.4-1” is assumed to be a branch or patch of “2.4”, and therefore “2.4.1” is considered newer than “2.4-1”, which in turn is newer than “2.4”.

Strings like “a”, “b”, “c”, “alpha”, “beta”, “candidate” and so on (that come before “final” alphabetically) are assumed to be pre-release versions, so that the version “2.4” is considered newer than “2.4a1”.

Finally, to handle miscellaneous cases, the strings “pre”, “preview”, and “rc” are treated as if they were “c”, i.e. as though they were release candidates, and therefore are not as new as a version string that does not contain them, and “dev” is replaced with an ‘@’ so that it sorts lower than than any other pre-release tag.

updater4pyi.util.path2url(p)[source]
updater4pyi.util.resource_path(relative_path)[source]

Get absolute path to resource, works for dev and for PyInstaller

updater4pyi.util.run_as_admin(argv)[source]
updater4pyi.util.run_win(argv, needs_sudo=False, wait=True, cwd=None)[source]

Run a process on windows.

Returns: the exit code of the process if wait is True, or the PID of the running process if wait is False.

updater4pyi.util.simple_platform()[source]
updater4pyi.util.which(name, flags=1, usecache=True, firstresult=True)[source]

Search PATH for executable files with the given name.

This function is based on code from twisted (see copyright notice in source code of this function).

On newer versions of MS-Windows, the PATHEXT environment variable will be set to the list of file extensions for files considered executable. This will normally include things like ”.EXE”. This fuction will also find files with the given name ending with any of these extensions.

On MS-Windows the only flag that has any meaning is os.F_OK. Any other flags will be ignored.

@type name: C{str} @param name: The name for which to search.

@type flags: C{int} @param flags: Arguments to L{os.access}.

@rtype: C{list} @param: A list of the full paths to files found, in the order in which they were found.

updater4pyi.util.which_clear_cache()[source]
updater4pyi.util.winshell_quote(x)[source]