mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Initial commit of win_pkg.py
Stub out all the required functions for pkg Implement pkg.list_pkgs Verify pkg.version works
This commit is contained in:
parent
e0692c2b3d
commit
777a7ec6e8
166
salt/modules/win_pkg.py
Normal file
166
salt/modules/win_pkg.py
Normal file
@ -0,0 +1,166 @@
|
||||
'''
|
||||
A module to manage software on Windows
|
||||
'''
|
||||
try:
|
||||
import win32com.client
|
||||
import pythoncom
|
||||
except:
|
||||
pass
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Set the virtual pkg module if the os is Windows
|
||||
'''
|
||||
return 'pkg' if __grains__['os'] == 'Windows' else False
|
||||
|
||||
|
||||
def _list_removed(old, new):
|
||||
'''
|
||||
List the packages which have been removed between the two package objects
|
||||
'''
|
||||
pkgs = []
|
||||
for pkg in old:
|
||||
if pkg not in new:
|
||||
pkgs.append(pkg)
|
||||
return pkgs
|
||||
|
||||
|
||||
def available_version(name):
|
||||
'''
|
||||
The available version of the package in the repository
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.available_version <package name>
|
||||
'''
|
||||
return 'Not implemented on Windows yet'
|
||||
|
||||
|
||||
def upgrade_available(name):
|
||||
'''
|
||||
Check whether or not an upgrade is available for a given package
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.upgrade_available <package name>
|
||||
'''
|
||||
return 'Not implemented on Windows yet'
|
||||
|
||||
|
||||
def list_upgrades():
|
||||
'''
|
||||
List all available package upgrades on this system
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.list_upgrades
|
||||
'''
|
||||
return 'Not implemented on Windows yet'
|
||||
|
||||
|
||||
def version(name):
|
||||
'''
|
||||
Returns a version if the package is installed, else returns an empty string
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.version <package name>
|
||||
'''
|
||||
pkgs = list_pkgs()
|
||||
if name in pkgs:
|
||||
return pkgs[name]
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def list_pkgs():
|
||||
'''
|
||||
List the packages currently installed as a dict::
|
||||
|
||||
{'<package_name>': '<version>'}
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.list_pkgs
|
||||
'''
|
||||
pythoncom.CoInitialize()
|
||||
ret = {}
|
||||
strComputer = "."
|
||||
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
|
||||
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
|
||||
colItems = objSWbemServices.ExecQuery("Select * from Win32_Product")
|
||||
for objItem in colItems:
|
||||
ret[objItem.Name] = objItem.Version
|
||||
return ret
|
||||
|
||||
|
||||
def refresh_db():
|
||||
'''
|
||||
Just recheck the repository and return a dict::
|
||||
|
||||
{'<database name>': Bool}
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.refresh_db
|
||||
'''
|
||||
return 'Not implemented on Windows yet'
|
||||
|
||||
|
||||
def install(name, refresh=False, **kwargs):
|
||||
'''
|
||||
Install the passed package
|
||||
|
||||
Return a dict containing the new package names and versions::
|
||||
|
||||
{'<package>': {'old': '<old-version>',
|
||||
'new': '<new-version>']}
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.install <package name>
|
||||
'''
|
||||
return 'Not implemented on Windows yet'
|
||||
|
||||
|
||||
def upgrade():
|
||||
'''
|
||||
Run a full system upgrade
|
||||
|
||||
Return a dict containing the new package names and versions::
|
||||
|
||||
{'<package>': {'old': '<old-version>',
|
||||
'new': '<new-version>']}
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.upgrade
|
||||
'''
|
||||
return 'Not implemented on Windows yet'
|
||||
|
||||
|
||||
def remove(name):
|
||||
'''
|
||||
Remove a single package
|
||||
|
||||
Return a list containing the removed packages.
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.remove <package name>
|
||||
'''
|
||||
return 'Not implemented on Windows yet'
|
||||
|
||||
|
||||
def purge(name):
|
||||
'''
|
||||
Recursively remove a package and all dependencies which were installed
|
||||
with it
|
||||
|
||||
Return a list containing the removed packages.
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' pkg.purge <package name>
|
||||
'''
|
||||
return 'Not implemented on Windows yet'
|
Loading…
Reference in New Issue
Block a user