common module

exception common.EWaptBadServerAuthentication[source]

Bases: waptpackage.EWaptException

exception common.EWaptCancelled[source]

Bases: exceptions.Exception

class common.LogInstallOutput(console, waptdb, rowid)[source]

Bases: waptutils.BaseObjectClass

file like to log print output to db installstatus


alias of package

class common.Wapt(config=None, config_filename=None, defaults=None, disable_update_server_status=True)[source]

Bases: waptutils.BaseObjectClass

Global WAPT engine


Add an automatic host repository, remove existing WaptHostRepo last one before


Add a pyscripter project file to package development directory.

Parameters:target_directory (str) – path to location where to create the wa^t.psproj file.

Add a local shitdown policy to upgrade system


return a list of autorized package certificate issuers for this host check_certificates_validity enable date checking.

build_package(directoryname, inc_package_release=False, excludes=['.svn', '.git', '.gitignore', 'setup.pyc'], target_directory=None)[source]

Build the WAPT package from a directory

Call update_control from if this function is defined. Then zip the content of directory. Add a manifest.sha256 file with sha256 hash of the content of each file.

  • directoryname (str) – source root directory of package to build
  • inc_package_release (boolean) – increment the version of package in control file.

Filename of built WAPT package

Return type:


build_upload(sources_directories, private_key_passwd=None, wapt_server_user=None, wapt_server_passwd=None, inc_package_release=False, target_directory=None)[source]

Build a list of packages and upload the resulting packages to the main repository. if section of package is group or host, user specific wapt-host or wapt-group

list: list of filenames of built WAPT package
call_setup_hook(wapt_package_dir, hook_name='update_package', *args, **kwargs)[source]

Install a single wapt package given its WAPT filename. return install status

check_cancelled(msg='Task cancelled')[source]
check_depends(apackages, forceupgrade=False, force=False, assume_removed=[])[source]

Given a list of packagename or requirement “name (=version)”, return a dictionnary of {‘additional’ ‘upgrade’ ‘install’ ‘skipped’ ‘unavailable’,’remove’} of [packagerequest,matching PackageEntry]

  • apackages (str or list) – list of packages for which to check missing dependencies.
  • forceupgrade (boolean) – if True, check if the current installed packages is the latest available
  • force (boolean) – if True, install the latest version even if the package is already there and match the requirement
  • assume_removed (list) – list of packagename which are assumed to be absent even if they are actually installed to check the consequences of removal of packages, implies force=True

{‘additional’ ‘upgrade’ ‘install’ ‘skipped’ ‘unavailable’, ‘remove’} with list of [packagerequest,matching PackageEntry]

Return type:


check_downloads(apackages=None, usecache=True)[source]

Return list of available package entries to match supplied packages requirements

  • apackages (list or str) – list of packages
  • usecache (bool) – returns only PackageEntry not yet in cache

list of PackageEntry to download

Return type:



Check and return the host package if available and not installed

check_install(apackages=None, force=True, forceupgrade=True)[source]

Return a list of actions required for install of apackages list of packages if apackages is None, check for all pending updates.

  • apackages (str or list) – list of packages or None to check pending install/upgrades
  • force (boolean) – if True, already installed package listed in apackages will be considered to be reinstalled
  • forceupgrade – if True, all dependencies are upgraded to latest version, even if current version comply with depends requirements

with keys [‘skipped’, ‘additional’, ‘remove’, ‘upgrade’, ‘install’, ‘unavailable’] and list of

(package requirements, PackageEntry)

Return type:



Check if an install is in progress, return list of pids of install in progress Kill old stucked wapt-get processes/children and update db status max_ttl is maximum age of wapt-get in minutes


Return a list of additional package to remove if apackages are removed

Parameters:apackages (str or list) – list of packages fr which parent dependencies will be checked.
Returns:list of package requirements with broken dependencies
Return type:list

Remove cached WAPT files from local disk

Parameters:obsolete_only (boolean) – If True, remove packages which are either no more available, or installed at a equal or newer version
Returns:list of filenames of removed packages
Return type:list
>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
>>> l = wapt.download_packages(wapt.check_downloads())
>>> res = wapt.cleanup(True)

Remove all current user session_setup informations for removed packages

Create a rsa key pair for the host and a x509 certiticate.
Location of key is <wapt_root>private Should be kept secret restricted access to system account and administrators only.
Parameters:force_recreate (bool) – recreate key pair even if already exists for this FQDN.
Returns:x509 certificate of this host.
Return type:str

Remove a key from local db

dependencies(packagename, expand=False)[source]

Return all dependecies of a given package >>> w = Wapt(config_filename=’c:/wapt/wapt-get.ini’) >>> dep = w.dependencies(‘tis-waptdev’) >>> isinstance(dep,list) and isinstance(dep[0],PackageEntry) True


Disable Wapt automatic update/upgrade scheduling through windows scheduler

download_packages(package_requests, usecache=True, printhook=None)[source]

Download a list of packages (requests are of the form packagename (>version) ) returns a dict of {“downloaded,”skipped”,”errors”}

  • package_requests (str or list) – list of packages to prefetch
  • usecache (boolean) – if True, don’t download package if already in cache
  • printhook (func) – callback with signature report(received,total,speed,url) to display progress

with keys {“downloaded,”skipped”,”errors”,”packages”} and list of PackageEntry.

Return type:


>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
>>> def nullhook(*args):
...     pass
>>> wapt.download_packages(['tis-firefox','tis-waptdev'],usecache=False,printhook=nullhook)
{'downloaded': [u'c:/wapt\\cache\\tis-firefox_37.0.2-9_all.wapt', u'c:/wapt\\cache\\tis-waptdev.wapt'], 'skipped': [], 'errors': []}

Download packages that can be upgraded

duplicate_package(packagename, newname=None, newversion=None, target_directory=None, append_depends=None, remove_depends=None, append_conflicts=None, remove_conflicts=None, auto_inc_version=True, usecache=True, printhook=None, cabundle=None)[source]

Duplicate an existing package. Duplicate an existing package from declared repostory or file into targetdirectory with

optional newname and version.
  • packagename (str) – packagename to duplicate, or filepath to a local package or package development directory.
  • newname (str) – name of target package
  • newversion (str) – version of target package. if None, use source package version
  • target_directory (str) – path where to put development files. If None, use temporary. If empty, use default development dir
  • append_depends (list) – comma str or list of depends to append.
  • remove_depends (list) – comma str or list of depends to remove.
  • auto_inc_version (bool) – if version is less than existing package in repo, set version to repo version+1
  • usecache (bool) – If True, allow to use cached package in local repo instead of downloading it.
  • printhook (func) – hook for download progress
  • cabundle (SSLCABundle) – list of authorized ca certificate (SSLPublicCertificate) to check authenticity of source packages. If None, no check is performed.

new packageEntry with sourcespath = target_directory

Return type:


>>> wapt = Wapt(config_filename='c:/tranquilit/wapt/tests/wapt-get.ini')
>>> wapt.dbpath = ':memory:'
>>> r= wapt.update()
>>> def nullhook(*args):
...     pass
>>> tmpdir = 'c:/tmp/testdup-wapt'
>>> if os.path.isdir(tmpdir):
...     import shutil
...     shutil.rmtree(tmpdir)
>>> p = wapt.duplicate_package('tis-wapttest',
...     newname='testdup',
...     newversion='20.0-0',
...     target_directory=tmpdir,
...     excludes=['.svn','.git','.gitignore','*.pyc','src'],
...     append_depends=None,
...     auto_inc_version=True,
...     usecache=False,
...     printhook=nullhook)
>>> print repr(p['package'])
>>> if os.path.isdir(tmpdir):
...     import shutil
...     shutil.rmtree(tmpdir)
>>> p = wapt.duplicate_package('tis-wapttest',
...    target_directory=tempfile.mkdtemp('wapt'),
...    auto_inc_version=True,
...    append_depends=['tis-firefox','tis-irfanview'],
...    remove_depends=['tis-wapttestsub'],
...    )
>>> print repr(p['package'])
edit_host(hostname, target_directory=None, append_depends=None, remove_depends=None, append_conflicts=None, remove_conflicts=None, printhook=None, description=None, cabundle=None)[source]

Download and extract a host package from host repositories into target_directory for modification

  • hostname (str) – fqdn of the host to edit
  • target_directory (str) – where to place the developments files. if empty, use default one from wapt-get.ini configuration
  • append_depends (str or list) – list or comma separated list of package requirements
  • remove_depends (str or list) – list or comma separated list of package requirements to remove
  • cabundle (SSLCA Bundle) – authorized ca certificates. If None, use default from current wapt.


>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
>>> tmpdir = 'c:/tmp/dummy'
>>> wapt.edit_host('dummy.tranquilit.local',target_directory=tmpdir,append_depends='tis-firefox')
>>> import shutil
>>> shutil.rmtree(tmpdir)
>>> host = wapt.edit_host('htlaptop.tranquilit.local',target_directory=tmpdir,append_depends='tis-firefox')
>>> 'package' in host
>>> shutil.rmtree(tmpdir)
edit_package(packagerequest, target_directory='', use_local_sources=True, append_depends=None, remove_depends=None, append_conflicts=None, remove_conflicts=None, auto_inc_version=True, cabundle=None)[source]

Download an existing package from repositories into target_directory for modification if use_local_sources is True and no newer package exists on repos, updates current local edited data else if target_directory exists and is not empty, raise an exception

  • packagerequest (str) – path to existing wapt file, or package request
  • use_local_sources (boolean) – don’t raise an exception if target exist and match package version
  • append_depends (list of str) – package requirements to add to depends
  • remove_depends (list or str) – package requirements to remove from depends
  • auto_inc_version (bool) –
  • cabundle (SSLCABundle) – list of authorized certificate filenames. If None, use default from current wapt.

edit local package with sourcespath attribute populated

Return type:


>>> wapt = Wapt(config_filename='c:/tranquilit/wapt/tests/wapt-get.ini')
>>> wapt.dbpath = ':memory:'
>>> r= wapt.update()
>>> tmpdir = tempfile.mkdtemp('wapt')
>>> res = wapt.edit_package('tis-wapttest',target_directory=tmpdir,append_depends='tis-firefox',remove_depends='tis-7zip')
>>> res['target'] == tmpdir and res['package'].package == 'tis-wapttest' and 'tis-firefox' in res['package'].depends
>>> import shutil
>>> shutil.rmtree(tmpdir)

Enable Wapt automatic update/upgrade scheduling through windows scheduler


return install tasks with error status


Remove install status for packages from local database without actually uninstalling the packages

Parameters:packages_list (list) – list of installed package names to forget
Returns:list of package names actually forgotten
Return type:list
>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
>>> res = wapt.install('tis-test')
>>> res = wapt.is_installed('tis-test')
>>> isinstance(res,PackageEntry)
>>> wapt.forget_packages('tis-test')
>>> wapt.is_installed('tis-test')
>>> print wapt.is_installed('tis-test')

Regenerate a random UUID for this host or force with supplied one.

Normally, the UUID is taken from BIOS through wmi.

In case bios returns some duplicates or garbage, it can be useful to force a random uuid. This is stored as uuid key in wapt-get.ini.

In case we want to link th host with a an existing record on server, we can force a old UUID.

forced_uuid (str): uuid to force for this host. If None, generate a random one
get_default_development_dir(packagecond, section='base')[source]

Returns the default development directory for package named <packagecond> based on default_sources_root ini parameter if provided

Parameters:packagecond (PackageEntry or str) – either PackageEntry or a “name(=version)” string
Returns:path to local proposed development directory
Return type:unicode

Return the current host certificate.

Returns:host public certificate.
Return type:SSLCertificate

Return private key used to sign uploaded data from host

Returns:Private key used to sign data posted by host.
Return type:SSLPrivateKey

Get update status of host as stored at the end of last operation.

Returns:‘date’: timestamp of last operation ‘runstatus’: last printed message of wapt core ‘running_tasks’: list of tasks ‘errors’: list of packages not installed properly ‘upgrades’: list of packages which need to be upgraded
Return type:dict

Return most up to date packages entries for packages_names packages_names is either a list or a string return a dictionnary with {‘packages’:[],’missing’:[]} >>> wapt = Wapt(config_filename=’c:/wapt/wapt-get.ini’) >>> res = wapt.get_package_entries([‘tis-firefox’,’tis-putty’]) >>> isinstance(res[‘missing’],list) and isinstance(res[‘packages’][0],PackageEntry) True


Download sources of package (if referenced in package as a https svn) in the current directory

global_attributes = ['wapt_base_dir', 'waptserver', 'config_filename', 'proxies', 'repositories', 'personal_certificate_path', 'public_certs_dir', 'package_cache_dir', 'dbpath']

get HiberbootEnabled.


Return package name for current computer

http_upload_package(packages, wapt_server_user=None, wapt_server_passwd=None)[source]

Upload a package or host package to the waptserver.

  • packages (str or list) – list of filepaths or PackageEntry to wapt packages to upload
  • wapt_server_user (str) – user for basic auth on waptserver
  • wapt_server_passwd (str) – password for basic auth on waptserver


>>> from common import *
>>> wapt = Wapt(config_filename = r'C:\tranquilit\wapt\tests\wapt-get.ini')
>>> r = wapt.update()
>>> d = wapt.duplicate_package('tis-wapttest','toto')
>>> print d
{'target': u'c:\\users\\htouvet\\appdata\\local\\temp\\toto.wapt', 'package': PackageEntry('toto','119')}
>>> wapt.http_upload_package(d['package'],wapt_server_user='admin',wapt_server_passwd='password')
install(apackages, force=False, params_dict={}, download_only=False, usecache=True, printhook=None, installed_by=None)[source]

Install a list of packages and its dependencies removes first packages which are in conflicts package attribute

Returns a dictionary of (package requirement,package) with ‘install’,’skipped’,’additional’

  • apackages (list or str) – list of packages requirements “packagename(=version)” or list of PackageEntry.
  • force (bool) – reinstalls the packages even if it is already installed
  • params_dict (dict) – parameters passed to the install() procedure in the packages of all packages as params variables and as “setup module” attributes
  • download_only (bool) – don’t install package, but only download them
  • usecache (bool) – use the already downloaded packages if available in cache directory
  • printhook (func) – hook for progress print

with keys [‘skipped’, ‘additional’, ‘remove’, ‘upgrade’, ‘install’, ‘unavailable’] and list of

(package requirements, PackageEntry)

Return type:


>>> wapt = Wapt(config_filename='c:/tranquilit/wapt/tests/wapt-get.ini')
>>> def nullhook(*args):
...     pass
>>> res = wapt.install(['tis-wapttest'],usecache=False,printhook=nullhook,params_dict=dict(company='toto'))
>>> isinstance(res['upgrade'],list) and isinstance(res['errors'],list) and isinstance(res['additional'],list) and isinstance(res['install'],list) and isinstance(res['unavailable'],list)
>>> res = wapt.remove('tis-wapttest')
>>> res == {'removed': ['tis-wapttest'], 'errors': []}
install_wapt(fname, params_dict={}, explicit_by=None)[source]

Install a single wapt package given its WAPT filename. return install status

  • fname (str) – Path to wapt Zip file or unzipped development directory
  • params (dict) – custom parmaters for the install function
  • explicit_by (str) – identify who has initiated the install


Return type:


  • EWaptMissingCertificate
  • EWaptNeedsNewerAgent
  • EWaptUnavailablePackage
  • EWaptConflictingPackage
  • EWaptBadTargetOS
  • EWaptException
  • various Exception depending on setup script

Returns all installed packages with their status

Parameters:include_errors (boolean) – include packages wnot installed successfully
Returns:list of PackageEntry merged with local install status.
Return type:list

Return full inventory of the computer as a dictionary.

Return type:dict

…changed: 1.4.1: renamed keys


Check if a package (with optional version condition) is available in repositories.

Parameters:packagename (str) – package name to lookup or package requirement ( packagename(=version) )
Returns:of PackageEntry sorted by package version ascending
Return type:list
>>> wapt = Wapt(config_filename='c:/tranquilit/wapt/tests/wapt-get.ini')
>>> l = wapt.is_available('tis-wapttest')
>>> l and isinstance(l[0],PackageEntry)
is_installed(packagename, include_errors=False)[source]

Checks if a package is installed. Return package entry and additional local status or None

Parameters:packagename (str) – name / package request to query
None en PackageEntry merged with local install_xxx fields
  • install_date
  • install_output
  • install_params
  • install_status
Return type:PackageEntry

Return PackageEntry if directory is a wapt developement directory (a WAPT/control file exists) or False


Return PackageEntry if filename is a wapt package or False


Get the printed output of the last install of package named packagename

Parameters:packagename (str) – name of package to query
Returns:{status,log} of the last install of a package
Return type:dict
>>> w = Wapt()
>>> w.last_install_log('tis-7zip')
{'status': u'OK', 'log': u'Installing 7-Zip 9.38.0-1\n7-Zip already installed, skipping msi install\n'}

Returns a list of installed packages which have the searchwords in their description

Parameters:searchwords (list) – list of words to llokup in package name and description only entries which have words in the proper order are returned.
Returns:list of PackageEntry matching the search words
Return type:list
>>> w = Wapt()
>>> w.list('zip')
[PackageEntry('tis-7zip','16.4-8') ]

Returns a list of packages requirement which can be upgraded

Returns:{‘additional’: [], ‘install’: [], ‘remove’: [], ‘upgrade’: []}
Return type:dict

Load configuration parameters from supplied inifilename

make_group_template(packagename='', depends=None, conflicts=None, directoryname=None, section='group', description=None)[source]

Creates or updates on disk a skeleton of a WAPT group package. If the a package skeleton already exists in directoryname, it is updated.

sourcespath attribute of returned PackageEntry is populated with the developement directory of group package.

  • packagename (str) – group name
  • depends
  • conflicts
  • directoryname
  • section
  • description


>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
>>> tmpdir = 'c:/tmp/dummy'
>>> if os.path.isdir(tmpdir):
...    import shutil
...    shutil.rmtree(tmpdir)
>>> p = wapt.make_group_template(packagename='testgroupe',directoryname=tmpdir,depends='tis-firefox',description=u'Test de groupe')
>>> print p
>>> print p['package'].depends
>>> import shutil
>>> shutil.rmtree(tmpdir)
make_host_template(packagename='', depends=None, conflicts=None, directoryname=None, description=None)[source]
make_package_template(installer_path='', packagename='', directoryname='', section='', description=None, depends='', version=None, silentflags=None, uninstallkey=None)[source]
Build a skeleton of WAPT package based on the properties of the supplied installer
Return the path of the skeleton
>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
>>> wapt.dbpath = ':memory:'
>>> files = 'c:/tmp/files'
>>> if not os.path.isdir(files):
...    os.makedirs(files)
>>> tmpdir = 'c:/tmp/dummy'
>>> devdir = wapt.make_package_template(files,packagename='mydummy',directoryname=tmpdir,depends='tis-firefox')
>>> os.path.isfile(os.path.join(devdir,'WAPT','control'))
>>> p = wapt.build_package(devdir)
>>> 'filename' in p and isinstance(p['files'],list) and isinstance(p['package'],PackageEntry)
>>> import shutil
>>> shutil.rmtree(tmpdir)

get / set the MaxGPOScriptWait.


Called whenever the network configuration has changed


get / set the pre shutdown timeout shutdown tasks.

private_key(passwd_callback=None, private_key_password=None)[source]

SSLPrivateKey matching the personal_certificate When key has been found, it is kept in memory for later use.

  • passwd_callback – func to call to get a password from user (must return str when called)
  • private_key_password – password to use to decrypt key. If None, passwd_callback is called.



EWaptMissingPrivateKey if ket can not be decrypted or found.


Return the local IP which is most probably reachable by wapt server

In case there are several network connections, returns the local IP
which Windows choose for sending packets to WaptServer.

This can be the most probable IP which would get packets from WaptServer.

Returns:Local IP
Return type:str
read_param(name, default=None)[source]

read a param value from local db >>> wapt = Wapt(config_filename=’c:/wapt/wapt-get.ini’) >>> wapt.read_param(‘db_version’) u‘20140410’

Send computer informations to WAPT Server
if description is provided, updates local registry with new description
Returns:response from server.
Return type:dict
>>> wapt = Wapt()
>>> s = wapt.register_computer()

Return list of uninstall ID from registry launched before and after an installation to capture uninstallkey


Check if config file has been updated, Return None if config has not changed or date of new config file if reloaded

>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
>>> wapt.reload_config_if_updated()
remove(packages_list, force=False)[source]

Removes a package giving its package name, unregister from local status DB

  • packages_list (str or list or path) – packages to remove (package name, list of package requirement, package entry or development directory)
  • force – if True, unregister package from local status database, even if uninstall has failed

{‘errors’: [], ‘removed’: []}

Return type:



Add a local shitdown policy to upgrade system


Reset host uuid to bios provided UUID.


Remove the local waptservice auth from ini file

run(*arg, **args)[source]
run_notfatal(*cmd, **args)[source]

Runs the command and wait for it termination returns output, don’t raise exception if exitcode is not null but return ‘’


return current install tasks


returns the current run status for tray display

search(searchwords=[], exclude_host_repo=True, section_filter=None, newest_only=False)[source]

Returns a list of packages which have the searchwords in their description

  • searchwords (str or list) – words to search in packages name or description
  • exclude_host_repo (boolean) – if True, don’t search in host repoisitories.
  • section_filter (str or list) – restrict search to the specified package sections/categories

list of PackageEntry

Return type:


session_setup(packagename, force=False)[source]

Setup the user session for a specific system wide installed package” Source from database or filename

set_local_password(user='admin', pwd='password')[source]

Set admin/password local auth for waptservice in ini file as a sha256 hex hash


Setup cron job on windows for update and download-upgrade

show_progress(show_box=False, msg='Loading...', progress=None, progress_max=None)[source]
sign_host_content(data, md='sha256')[source]

Sign data str with host private key with sha256 + RSA :param data: data to sign :type data: bytes

bytes: signature of sha256 hash of data.
sign_package(zip_or_directoryname, certificate=None, callback=None, private_key_password=None)[source]
Calc the signature of the WAPT/manifest.sha256 file and put/replace it in ZIP or directory.

if directory, creates WAPT/manifest.sha256 and add it to the content of package create a WAPT/signature file and it to directory or zip file.

known issue : if zip file already contains a manifest.sha256 file, it is not removed, so there will be
2 manifest files in zip / wapt package.
  • zip_or_directoryname – filename or path for the wapt package’s content
  • certificate – path to the certificate of signer.
  • callback – ref to the function to call if a password is required for opening the private key.

base64 encoded signature of manifest.sha256 file (content

Return type:



Stores in DB the current pending upgrades and running installs for query by waptservice

uninstall(packagename, params_dict={})[source]

Launch the uninstall script of an installed package” Source from database or filename


return the (quiet) command stored in registry to uninstall a software given its registry key

update(force=False, register=True, filter_on_host_cap=True)[source]

Update local database with packages definition from repositories

  • force (boolean) – update even if Packages index on repository has not been updated since last update (based on http headers)
  • register (boolean) – Send informations about status of local packages to waptserver
list of (host package entry,entry date on server)
Return type:dict
>>> wapt = Wapt(config_filename='c:/wapt/wapt-get.ini')
>>> updates = wapt.update()
>>> 'count' in updates and 'added' in updates and 'upgrades' in updates and 'date' in updates and 'removed' in updates
Send host_info, installed packages and installed softwares,
and last update status informations to WAPT Server, but don’t send register info like dmi or wmi.

Changed in version 1.4.3: if last status has been properly sent to server and data has not changed, don’t push data again to server. the hash is stored in memory, so is not pass across threads or processes.

>>> wapt = Wapt()
>>> s = wapt.update_server_status()

Install “well known” host package from main repository if not already installed then query localstatus database for packages with a version older than repository and install all newest packages

{‘upgrade’: [], ‘additional’: [], ‘downloads’:
{‘downloaded’: [], ‘skipped’: [], ‘errors’: []},

’remove’: [], ‘skipped’: [], ‘install’: [], ‘errors’: [], ‘unavailable’: []}

Return type:dict
upload_package(filenames, wapt_server_user=None, wapt_server_passwd=None)[source]

Method to upload a package using Shell command (like scp) instead of http upload You must define first a command in inifile with the form :

upload_cmd=”c:Program Files”puttypscp -v -l waptserver %(waptfile)s srvwapt:/var/www/%(waptdir)s/
upload_cmd=”C:Program FilesWinSCPWinSCP.exe” root@wapt.tranquilit.local /upload %(waptfile)s
You can define a “after_upload” shell command. Typical use is to update the Packages index
after_upload=”c:Program Files”puttyplink -v -l waptserver srvwapt.tranquilit.local “python /opt/wapt/ /var/www/%(waptdir)s/”

Wapt configuration and version informations

versions of main main files, waptservice config,
repos and waptserver config
Return type:dict
>>> w = Wapt()
>>> w.wapt_status()
        'setuphelpers-version': '1.1.1',
        'waptserver': {
                'dnsdomain': u'tranquilit.local',
                'proxies': {
                        'http': None,
                        'https': None
                'server_url': 'https: //wapt.tranquilit.local'
        'waptservice_protocol': 'http',
        'repositories': [{
                'dnsdomain': u'tranquilit.local',
                'proxies': {
                        'http': None,
                        'https': None
                'name': 'global',
                'repo_url': 'http: //wapt.tranquilit.local/wapt'
                'dnsdomain': u'tranquilit.local',
                'proxies': {
                        'http': None,
                        'https': None
                'name': 'wapt-host',
                'repo_url': 'http: //srvwapt.tranquilit.local/wapt-host'
        'common-version': '1.1.1',
        'wapt-exe-version': u'',
        'waptservice_port': 8088,
        'wapt-py-version': '1.1.1'

Wapt database


Test reachability of waptserver.

If waptserver is defined and available, return True, else False

Returns:True if server is defined and actually reachable
Return type:boolean

Wapt user session database


Update configuration parameters to supplied inifilename

write_param(name, value)[source]

Store in local db a key/value pair for later use

class common.WaptBaseDB(dbpath)[source]

Bases: waptutils.BaseObjectClass

curr_db_version = None
db = None
get_param(name, default=None)[source]

Retrieve the value associated with name from database

query(query, args=(), one=False, as_dict=True)[source]

execute la requete query sur la db et renvoie un tableau de dictionnaires

set_param(name, value)[source]

Store permanently a (name/value) pair in database, replace existing one


Update local database structure to current version if rules are described in db_upgrades

Parameters:force (bool) – force upgrade even if structure version is greater than requested.
Return type:tuple
class common.WaptDB(dbpath)[source]

Bases: common.WaptBaseDB

Class to manage SQLite database with local installation status

add_package(package='', version='', section='', priority='', architecture='', maintainer='', description='', filename='', size='', md5sum='', depends='', conflicts='', sources='', repo_url='', repo='', signer='', signer_fingerprint='', maturity='', locale='', signature='', signature_date='', signed_attributes='', min_wapt_version='', installed_size=None, max_os_version='', min_os_version='')[source]
add_start_install(package, version, architecture, params_dict={}, explicit_by=None, maturity='', locale='', depends='', conflicts='')[source]

Register the start of installation in local db

  • params_dict (dict) – dictionary of parameters provided on command line with –param or by the server
  • explicit_by (str) – username of initiator of the install. if not None, install is not a dependencie but an explicit manual install
  • setuppy (str) – python source code used for install, uninstall or session_setup code used for uninstall or session_setup must use only wapt self library as package content is no longer available at this step.

Given a list of packages conditions (packagename (optionalcondition)) return a list of dependencies (packages conditions) to install

TODO : choose available dependencies in order to reduce the number of new packages to install

>>> waptdb = WaptDB(':memory:')
>>> office = PackageEntry('office','0')
>>> firefox22 = PackageEntry('firefox','22')
>>> firefox22.depends = 'mymissing,flash'
>>> firefox24 = PackageEntry('firefox','24')
>>> thunderbird = PackageEntry('thunderbird','23')
>>> flash10 = PackageEntry('flash','10')
>>> flash12 = PackageEntry('flash','12')
>>> office.depends='firefox(<24),thunderbird,mymissing'
>>> firefox22.depends='flash(>=10)'
>>> firefox24.depends='flash(>=12)'
>>> waptdb.add_package_entry(office)
>>> waptdb.add_package_entry(firefox22)
>>> waptdb.add_package_entry(firefox24)
>>> waptdb.add_package_entry(flash10)
>>> waptdb.add_package_entry(flash12)
>>> waptdb.add_package_entry(thunderbird)
>>> waptdb.build_depends('office')
([u'flash(>=10)', u'firefox(<24)', u'thunderbird'], [u'mymissing'])
curr_db_version = '20180104'

Initialize current sqlite db with empty table and return structure version


Return a PackageEntry of the local install status for id

Parameters:id – sql rowid

Return a dict of installed packages on this host

Parameters:include_errors (bool) – if False, only packages with status ‘OK’ and ‘UNKNOWN’ are returned if True, all packages are installed.
Returns:installed packages keys=package, values = PackageEntry
Return type:dict
installed_matching(package_cond, include_errors=False)[source]

Return True if one properly installed (if include_errors=False) package match the package condition ‘tis-package (>=version)’

Return a list of installed package entries based on search keywords


return a list of all (package,version)

package_entry_from_db(package, version_min='', version_max='')[source]

Return the most recent package entry given its packagename and minimum and maximum version

>>> waptdb = WaptDB(':memory:')
>>> waptdb.add_package_entry(PackageEntry('dummy','1'))
>>> waptdb.add_package_entry(PackageEntry('dummy','2'))
>>> waptdb.add_package_entry(PackageEntry('dummy','3'))
>>> waptdb.package_entry_from_db('dummy')
>>> waptdb.package_entry_from_db('dummy',version_min=2)
>>> waptdb.package_entry_from_db('dummy',version_max=1)

Return an ordered list of available packages entries which match the condition “packagename[([=<>]version)]?” version ascending

Return a list of package entries matching the search words


Return install parameters associated with a package


remove references to repo repo_name

>>> waptdb = WaptDB('c:/wapt/db/waptdb.sqlite')
>>> waptdb.purge_repo('main')
query_package_entry(query, args=(), one=False)[source]

Execute la requete query sur la db et renvoie un tableau de PackageEntry

Le matching est fait sur le nom de champs. Les champs qui ne matchent pas un attribut de PackageEntry sont également mis en attributs !

>>> waptdb = WaptDB(':memory:')
>>> waptdb.add_package_entry(PackageEntry('toto','0',repo='main'))
>>> waptdb.add_package_entry(PackageEntry('dummy','2',repo='main'))
>>> waptdb.add_package_entry(PackageEntry('dummy','1',repo='main'))
>>> waptdb.query_package_entry("select * from wapt_package where package=?",["dummy"])
[PackageEntry('dummy','2'), PackageEntry('dummy','1')]
>>> waptdb.query_package_entry("select * from wapt_package where package=?",["dummy"],one=True)

Remove status of package installation from localdb

store_setuppy(rowid, setuppy=None, install_params={})[source]

Update status of package installation on localdb

switch_to_explicit_mode(package, user_id)[source]

Set package install mode to manual so that package is not removed when meta packages don’t require it anymore

update_install_status(rowid, install_status, install_output, uninstall_key=None, uninstall_string=None)[source]

Update status of package installation on localdb

update_install_status_pid(pid, install_status='ERROR')[source]

Update status of package installation on localdb

update_repos_list(repos_list, force=False, filter_on_host_cap=True)[source]
update the packages database with Packages files from the url repos_list

removes obsolete records for repositories which are no more referenced repos_list : list of all the repositories objects referenced by the system

as returned by Wapt.repositories
force : update repository even if date of packages index is same as
last retrieved date
return a dictionary of update_db results for each repository name
which has been accessed.
>>> wapt = Wapt(config_filename = 'c:/tranquilit/wapt/tests/wapt-get.ini' )
>>> res = wapt.waptdb.update_repos_list(wapt.repositories)

Return a dictionary of upgradable Package entries

class common.WaptHostRepo(url=None, name='wapt-host', verify_cert=None, http_proxy=None, timeout=None, dnsdomain=None, host_id=None, cabundle=None, config=None, host_key=None)[source]

Bases: common.WaptRepo

Dummy http repository for host packages

>>> host_repo = WaptHostRepo(name='wapt-host',host_id=['0D2972AC-0993-0C61-9633-529FB1A177E3','4C4C4544-004E-3510-8051-C7C04F325131'])
>>> host_repo.load_config_from_file(r'C:\Users\htouvet\AppData\Local\waptconsole\waptconsole.ini')
>>> host_repo.packages
[PackageEntry('0D2972AC-0993-0C61-9633-529FB1A177E3','10') ,
 PackageEntry('4C4C4544-004E-3510-8051-C7C04F325131','30') ]
download_packages(package_requests, target_dir=None, usecache=True, printhook=None)[source]

Download a list of packages from repo

  • package_request (list,PackateEntry) – a list of PackageEntry to download
  • target_dir (str) – where to store downloaded Wapt Package files
  • usecache (bool) – wether to try to use cached Wapt files if checksum is ok
  • printhook (callable) – to show progress of download

{“downloaded”:[local filenames],”skipped”:[filenames in cache],”errors”:[],”packages”:self.packages}

Return type:


load_config(config, section=None)[source]

Load waptrepo configuration from inifile section.

Use name of repo as section name if section is not provided. Use ‘global’ if no section named section in ini file

class common.WaptLogger(wapt=None, package=None)[source]

Bases: object

Context handler to log all print messages to a wapt package install log

class common.WaptRepo(url=None, name='wapt', verify_cert=None, http_proxy=None, timeout=2, dnsdomain=None, cabundle=None, config=None)[source]

Bases: waptpackage.WaptRemoteRepo

Gives access to a remote http repository, with a zipped Packages packages index

>>> repo = WaptRepo(name='main',url='http://wapt/wapt',timeout=4)
>>> packages = repo.packages()
>>> len(packages)

Search the nearest working main WAPT repository given the following priority - URL defined in ini file - first SRV record in the same network as one of the connected network interface - first SRV record with the highest weight - wapt CNAME in the local dns domain (https first then http)

Preference for SRV records is :
same subnet -> priority asc -> weight desc
Returns:URL to the server.
Return type:str
>>> repo = WaptRepo(name='wapt',dnsdomain='',timeout=4,url=None)
>>> repo.repo_url
>>> repo = WaptRepo(name='wapt',url='http://wapt/wapt',timeout=4)
>>> repo.repo_url
load_config(config, section=None)[source]

Load waptrepo configuration from inifile section.

Use name of repo as section name if section is not provided. Use ‘global’ if no section named section in ini file


Repository URL

Fixed url if any, else request DNS with a SRV _wapt._tcp.domain query or a CNAME by the find_wapt_repo_url method.

The URL is queried once and then cached into a local property.

Returns:url to the repository
Return type:str
>>> repo = WaptRepo(name='wapt',timeout=4)
>>> print repo.dnsdomain
>>> repo = WaptRepo(name='wapt',timeout=4)
>>> print repo.dnsdomain
>>> print repo.repo_url

called by wapt when network configuration has changed

update_db(force=False, waptdb=None, filter_on_host_cap=True)[source]

Get Packages from http repo and update local package database return last-update header

The local status DB is updated. Date of index is stored in params table for further checks.

  • force (bool) – get index from remote repo even if creation date is not newer than the datetime stored in local status database
  • waptdb (WaptDB) – instance of Wapt status database.

date of Packages index

Return type:


>>> import common
>>> repo = common.WaptRepo('wapt','http://wapt/wapt')
>>> localdb = common.WaptDB('c:/wapt/db/waptdb.sqlite')
>>> last_update = repo.is_available()
>>> repo.update_db(waptdb=localdb) == last_update
class common.WaptServer(url=None, proxies={'http': None, 'https': None}, timeout=2, dnsdomain=None)[source]

Bases: waptutils.BaseObjectClass

Manage connection to waptserver


Ask for basic auth if server requires it


Search the WAPT server with dns SRV query

preference for SRV is :
same priority asc -> weight desc
>>> WaptServer(dnsdomain='tranquilit.local',timeout=4,url=None).server_url
>>> WaptServer(url='http://srvwapt:8080',timeout=4).server_url
get(action, auth=None, timeout=None)[source]
load_config(config, section='global')[source]

Load waptserver configuration from inifile

load_config_from_file(config_filename, section='global')[source]

Load waptserver configuration from an inifile located at config_filename

  • config_filename (str) – path to wapt inifile
  • section (str) – ini section from which to get parameters. default to ‘global’


Return type:


post(action, data=None, files=None, auth=None, timeout=None, signature=None, signer=None, content_length=None)[source]

Post data to waptserver using http POST method

Add a signature to the posted data using host certificate.

Posted Body is gzipped

  • action (str) – doc part of the url
  • data (str) – posted data body
  • files (list or dict) – list of filenames

called by wapt when network configuration has changed

save_server_certificate(server_ssl_dir=None, overwrite=False)[source]

Retrieve certificate of https server for further checks

Parameters:server_ssl_dir (str) – Directory where to save x509 certificate file
Returns:full path to x509 certificate file.
Return type:str

Return fixed url if any, else request DNS

>>> server = WaptServer(timeout=4)
>>> print server.dnsdomain
>>> server = WaptServer(timeout=4)
>>> print server.dnsdomain
>>> print server.server_url
upload_packages(packages, auth=None, timeout=None, progress_hook=None)[source]

Upload a list of PackageEntry with local wapt build/signed files :returns: {‘ok’,’errors’} list of http post upload results :rtype: dict

class common.WaptSessionDB(username='')[source]

Bases: common.WaptBaseDB

add_start_install(package, version, architecture)[source]

Register the start of installation in local db

curr_db_version = '20161103'

Initialize current sqlite db with empty table and return structure version

is_installed(package, version)[source]

Remove status of package installation from localdb

>>> wapt = Wapt()
>>> wapt.forget_packages('tis-7zip')

Remove local user status of packages no more installed

update_install_status(rowid, install_status, install_output)[source]

Update status of package installation on localdb

update_install_status_pid(pid, install_status='ERROR')[source]

Update status of package installation on localdb

common.check_is_member_of(huser, group_name)[source]

check if a user is a member of a group huser : handle pywin32 group_name : group as a string >>> from win32security import LogonUser >>> hUser = win32security.LogonUser (‘technique’,’tranquilit’,’xxxxxxx’,win32security.LOGON32_LOGON_NETWORK,win32security.LOGON32_PROVIDER_DEFAULT) >>> check_is_member_of(hUser,’domain admins’) False

common.check_user_membership(user_name, password, domain_name, group_name)[source]

check if a user is a member of a group user_name: user as a string password: as a string domain_name : as a string. If empty, check local then domain group_name : group as a string >>> from win32security import LogonUser >>> hUser = win32security.LogonUser (‘technique’,’tranquilit’,’xxxxxxx’,win32security.LOGON32_LOGON_NETWORK,win32security.LOGON32_PROVIDER_DEFAULT) >>> check_is_member_of(hUser,’domain admins’) False

return localized version of domain admin group (ie “domain admins” or
“administrateurs du domaine” with RID -512)
>>> get_domain_admins_group_name()
u'Domain Admins'

return a list of (iface,mac,{addr,broadcast,netmask})

common.lookup_name_from_rid(domain_controller, rid)[source]
return username or group name from RID (with localization if applicable)
from domain_controller : should be a DC rid : integer number (512 for domain admins, 513 for domain users, etc.)
>>> lookup_name_from_rid('srvads', DOMAIN_GROUP_RID_ADMINS)
u'Domain Admins'
common.same_net(ip1, ip2, netmask)[source]

Given 2 ipv4 address and mask, return True if in same subnet

common.sid_from_rid(domain_controller, rid)[source]

Return SID structure based on supplied domain controller’s domain and supplied rid rid can be for example DOMAIN_GROUP_RID_ADMINS, DOMAIN_GROUP_RID_USERS

common.start_interactive_process(app_filename, cmdline=None, session_id=None)[source]

Starts a process in the context of opened interactive session if any

common.tryurl(url, proxies=None, timeout=2, auth=None, verify_cert=False, cert=None)[source]
Utility to open Pyscripter with package source if it is installed
else open the development directory in Shell Explorer.
wapt_sources_dir (str): directory path of teh wapt package sources
Returns:sources path
Return type:str