Pyautoupdate API

Launcher

class pyautoupdate.Launcher(filepath, url, newfiles='project.zip', log_level=30, *args, **kwargs)[source]

Creates a Launcher object. This class provides the main functionality of the Pyautoupdate module.

Parameters:
  • filepath (str) – Path to file to execute
  • url (str) – Base URL from which to download new versions

Note

This must be an HTTPS url. HTTP urls are silently changed into HTTPS. Use of HTTPS is strictly enforced.

Parameters, queries, and fragments will be stripped from the URL.

Parameters:
  • newfiles (str) – Name of .zip, tar.gz or .tar.bz2 archive with new versions to download from site
  • log_level (int) – Logging level for the built in logger
  • args (tuple) – args passed to the launched code
  • kwargs (dict) – kwargs passed to the launched code

When the code is launched, the following variables are already defined:

Variable Name Value Description
filepath Path to the file that was initially launched
url Base url to check and download new versions
newfiles Name of the archive to download from the server
check_new Method to check for updated code
pid PID of parent process that spawns the code
log Logger for Pyautoupdate and for the executed code
args args tuple for the spawned code
kwargs kwargs dict for the spawned code

Warning

The Launcher uses multiprocessing.Process to run the code.

Please ensure that all arguments passed in as args and kwargs can be pickled. Non-pickleable arguments cannot be passed to the child process on Windows, and an error will be raised when attempting to run user code.

_call_code(*args, **kwargs)[source]

Internal function to execute the user code.

This is used as target of a multiprocessing.Process instance.

Parameters:
  • args (tuple) – *args tuple from self.args
  • kwargs (dict) – **kwargs dict from self.kwargs

Warning

End users should never call this directly. Please use the run() method instead.

_get_new(allow_redirects=True, chunk_size=512)[source]

Retrieves the new archive and extracts it to self.updatedir.

_replace_files()[source]

Replaces the existing files with the downloaded files.

Returns:Whether update succeeded
Return type:bool
_reset_update_files()[source]

Resets the update files to its default state.

It empties the existing update directory or creates a new one if it doesn’t exist.

check_new()[source]

Retrieves the latest version number from the remote host.

Returns:Whether a newer version is available
Return type:bool

Note

This function internally uses setuptool’s parse_version to compare versions.

Any versioning scheme conforming to PEP 440 can be used.

When the server contains an invalid version specification, this returns false.

Changed in version 1.0.0: Previously, an invalid server version would cause an exception.

file_list = 'filelist.txt'
process_code_running

Property indicating whether the user code is running

To see if the process has started, please use Launcher.process_is_alive(). Note that the process needs to initialize itself before it can run user code.

process_exitcode

Property indicating the process exitcode, if it exists

process_is_alive

Property indicating whether the process is alive

To see if user code is running, please use Launcher.process_code_running(). Note that the process needs to initialize itself before it can run user code.

process_join(timeout=None)[source]

Joins the process

process_pid

Property indicating the process PID, if it exists

process_terminate()[source]

Terminates the process.

Warning

All the provisos of multiprocessing.Process.terminate() apply.

Attempts are made in the code to ensure that internal variables inside the Launcher class are properly cleaned up. However, there is little protection for user supplied code in case of termination.

Returns:Whether process was terminated
Return type:bool
queue_update = '.queue'
run(background=False)[source]

Runs the user code.

If background is False, returns the Process’s exitcode.

Parameters:background (bool) – Whether to run code in background
Returns:the exit code if background is False
Return type:int or None
update_code()[source]

Updates the code if necessary.

Returns:Whether update succeeded
Return type:bool
updatedir = '.pyautodownloads'
version_check_log = 'version_check.log'
version_doc = 'version.txt'
version_doc_validator()[source]

Validates the file containing the current version number.

Returns:Whether the version_doc is a proper version
Return type:bool
version_log_validator()[source]

Validates the file containing the version history.

Returns:Whether the version_log is formatted properly
Return type:bool

Exceptions

exception pyautoupdate.PyautoupdateBaseException[source]

Base exception for all pyautoupdate errors

exception pyautoupdate.PyautoupdateBaseWarning[source]

Base warning for all pyautoupdate errors

exception pyautoupdate.ProcessRunningException[source]

Exception when process is already running

exception pyautoupdate.CorruptedFileWarning[source]

Warning that critical files are corrupted