Current File : /home/mmdealscpanel/yummmdeals.com/actions.tar
__init__.py000075500000000037150515722430006664 0ustar00#!/usr/libexec/platform-python
up2date_config.py000075500000003673150515722430010027 0ustar00#!/usr/libexec/platform-python

# Copyright (c) 1999--2018 Red Hat, Inc.  Distributed under GPLv2.
#
# Author: Adrian Likins <alikins@redhat.com>
#

import os
import re

from up2date_client import config

cfg = config.initUp2dateConfig()

__rhnexport__ = ["update", "get"]

argVerbose = 0


def update(configdict, cache_only=None):
    """Invoke this to change the ondisk configuration of up2date"""
    if cache_only:
        return (0, "no-ops for caching", {})
    if argVerbose > 1:
        print("called update_up2date_config")

    if type(configdict) != type({}):
        return (13, "Invalid arguments passed to function", {})

    unknownparams = []
    if cfg["disallowConfChanges"]:
        skipParams = cfg["disallowConfChanges"]
    else:
        skipParams = []
    for param in configdict.keys():
        # dont touch params in the skip params list
        if param in skipParams:
            continue
        # write out all params, even ones we dont know about
        # could be useful
        cfg.set(param, configdict[param])

    if len(unknownparams):
        return unknownparams

    cfg.save()

    return (0, "config updated", {})


def get(cache_only=None):
    """Reterieve the current configuration of up2date"""
    if cache_only:
        return (0, "no-ops for caching", {})
    if argVerbose > 1:
        print("called get_up2date_config")

    ret = {}
    for k in cfg.keys():
        ret[k] = cfg[k]
    return (0, "configuration retrived", {"data": ret})


def main():
    configdatatup = get()
    configdata = configdatatup[2]["data"]

    import time

    timestamp = time.time()

    configdata["timeStampTest"] = timestamp
    print(configdata)
    import pprint

    pprint.pprint(update(configdata))

    configdata["serverURL"] = "https://xmlrpc.cln.cloudlinux.com/XMLRPC/"
    configdata["serverURLipv6"] = "https://ipv6.xmlrpc.cln.cloudlinux.com/XMLRPC/"
    pprint.pprint(update(configdata))


if __name__ == "__main__":
    main()
__pycache__/hardware.cpython-36.pyc000064400000001653150515722430013210 0ustar003

ge8hI�@sRddlmZddlmZddlmZdZdgZd
dd�Zdd�Zed	krNe�dS)�)�hardware)�up2dateAuth)�	rpcServer�refresh_listNc	Csh|rddifStj�}tj�}tdkr.td�y|jjtj	�|�Wntd�ddifSddifS)	Nrzno-ops for caching�zCalled refresh_hardwarez3ERROR: sending hardware database for System Profile�z Error refreshing system hardwarezhardware list refreshed)
rZHardwarerZ	getServer�
argVerbose�printZregistrationZrefresh_hw_profilerZgetSystemId)Z
cache_onlyZhardwareList�s�r�/usr/lib/python3.6/hardware.pyrs


cCstt��dS)N)r	rrrrr�main(sr
�__main__)N)	Zup2date_clientrrrrZ
__rhnexport__rr
�__name__rrrr�<module>
s
__pycache__/up2date_config.cpython-36.pyc000064400000003211150515722430014274 0ustar003

ge8h��@s^ddlZddlZddlmZej�ZddgZdZd
dd�Zddd�Z	dd�Z
ed	krZe
�dS)�N)�config�update�getcCs�|rddifStdkrtd�t|�ti�kr8ddifSg}tdrNtd}ng}x*|j�D]}||krjq\tj|||�q\Wt|�r�|Stj�ddifS)	z9Invoke this to change the ondisk configuration of up2daterzno-ops for caching�zcalled update_up2date_config�
z$Invalid arguments passed to functionZdisallowConfChangeszconfig updated)�
argVerbose�print�type�cfg�keys�set�lenZsave)Z
configdict�
cache_onlyZ
unknownparamsZ
skipParamsZparam�r�$/usr/lib/python3.6/up2date_config.pyrs$


cCsN|rddifStdkrtd�i}xtj�D]}t|||<q,Wddd|ifS)z.Reterieve the current configuration of up2daterzno-ops for cachingrzcalled get_up2date_configzconfiguration retrived�data)rrr
r)r�ret�krrrr3s
cCsjt�}|dd}ddl}|j�}||d<t|�ddl}|jt|��d|d<d|d<|jt|��dS)	N�rrZ
timeStampTestz)https://xmlrpc.cln.cloudlinux.com/XMLRPC/Z	serverURLz.https://ipv6.xmlrpc.cln.cloudlinux.com/XMLRPC/Z
serverURLipv6)r�timer�pprintr)Z
configdatatupZ
configdatarZ	timestamprrrr�main@sr�__main__)N)N)�os�reZup2date_clientrZinitUp2dateConfigr
Z
__rhnexport__rrrr�__name__rrrr�<module>s


__pycache__/packages.cpython-36.opt-1.pyc000064400000020274150515722430014130 0ustar003

.޾g.�@s�ddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ej
�ZdZddd	d
ddd
gZ
d!dd�Zd"dd�Zd#dd�Zd$dd
�Zd%dd�Zd&dd	�Zdd�Zd'dd
�Zd(dd�Zggdddfdd�Zdd�Zdd �ZdS))�N)�
up2dateLog)�config)�rpmUtils)�rhnPackageInfoz/var/lib/up2date/dbtimestamp�update�remove�refresh_list�
fullUpdate�checkNeedUpdate�runTransaction�verifycsj|rddifSt|t�s"ddifStjd|�tddd�}|jj�j���fd	d
�|D�}t||d|d�S)z0We have been told that we should remove packagesrzno-ops for caching�
z$Invalid arguments passed to functionzCalled remove_packagesTF)�load_system_repo�load_available_reposcsg|]}t�|��qS�)�_package_tup2obj)�.0�tup)�	installedr�/usr/lib/python3.6/packages.py�
<listcomp>:szremove.<locals>.<listcomp>)r�
allow_erasing�
cache_only)	�
isinstance�list�log�	log_debug�	_dnf_base�sack�queryr�_dnf_transaction)�package_listr�base�	to_remover)rrr-s


cCs�t|t�sddifStjd|�tddd�}|jj�j�}|jj�j�}d}g}g}�x"|D�]}t	|�dkrx|j
d�|\}	}
}}}
|
dkr�|dkr�|dkr�|
dkr�|j|	d	�r�tjd
|	�q\|dkr�d}|j|	|
d�j�}t
||�}|�sd
t|�}tjd|�|j
|�q\x`|D]N}|j|�}|dk�rHtjdt|��Pn|dk�rtjdt|��P�qW|j
|�q\W|�s�|�r�dddj|�ddd�f}n
ddif}|jj�|j�|St|||d�S)z:We have been told that we should retrieve/install packagesr
z$Invalid arguments passed to functionz
Called updateT)rrN��)�namezPackage %s is already installedr)r&�archz,Package %s is not available for installationzE: zPackage %s already installedz6More recent version of package %s is already installed� z-Failed: Packages failed to install properly:
�
�1�package_install_failure)�versionr&z$Requested packages already installed)�installr)rrrrrrrr�	available�len�append�filterZlatestr�_package_tup2strZlog_meZevr_cmp�join�_plugins�_unload�closer )r!rr"rr.�errZerrmsgs�
to_install�packager&r,�release�epochr'�pkgsZ
requested_pkg�pkgZpkg_cmp�retrrrr?s`











cCs�|rddifStddd�}|jj�j�}|jj�j�}g}g}xd|ddd�D]P}|\}}	t||�}
|	dkr~|
r~|j|
�qP|	dkrP|
rPt||�}|j|�qPW|r�|r�dd	ifSt|||d|d
�S)z� Run a transaction on a group of packages.
        This was historicaly meant as generic call, but
        is only called for rollback.
    rzno-ops for cachingT)rr�packagesN�e�iz6Requested package actions have already been performed.)r-rrr)rrrrr.rr0r )Ztransaction_datarr"rr.r8r#Zpackage_objectr9�actionr=�newrrrr�s&



cCstddd�}t|d|d�S)z$ Update all packages on the system. T)rr)�full_updater)rr )�forcerr"rrrr	�sc	Cs�|rddifSi}d}tj�}|dr.|d}d|}ytj|�d}Wndd|fSytjt�d}Wnd}YnX||dkr�dd	|fS|dkr�yttd
�}|j�Wndd|fStdd
�S)z� Check if the locally installed package list changed, if
        needed the list is updated on the server
        In case of error avoid pushing data to stay safe
    rzno-ops for cachingz/var/lib/rpm�dbpathz%s/Packages�zunable to stat the rpm database�
zNrpm database not modified since last update (or package list recently updated)zw+z!unable to open the timestamp file�)�rhnsd)rZinitUp2dateConfig�os�stat�LAST_UPDATE_FILE�openr6r)	rJr�datarFZcfgZRPM_PACKAGE_FILEZdbtimeZlast�filerrrr
�s4




c	CsR|rddifStjd�d}ytj�Wntd�ddifSt�ddifS)	z3 push again the list of rpm packages to the server rzno-ops for cachingzCalled refresh_rpmlistNz8ERROR: refreshing remote package list for System Profile�zError refreshing package listzrpmlist refreshed)rrrZupdatePackageProfile�print�touch_time_stamp)rJrr>rrrr�s


cCs^yttd�}|j�WnddifStj�}ytjt||f�WnddtifSdS)Nzw+rz!unable to open the timestamp filez6unable to set the time stamp on the time stamp file %s)rNrMr6�timerK�utime)Zfile_d�trrrrS�s

rScCsvtjd�|rddifSi}d|d<d|d<tj|�\}}||d<t|�rld|d<d|d<||d	<d
d|fSdd|fS)
NzCalled packages.verifyrzno-ops for cachingzpackages.verifyr&r,Zverify_infoz packages.verify.missing_packages�missing_packages�+z-packages requested to be verified are missingzpackages verified)rrrZverifyPackagesr/)r?rrOr>rWrrrr�s


TcCs6tj�}|jjs|j�|r$|j�|jddd�|S)NT)rr)�dnfZBaser4ZpluginsZinit_pluginsZread_all_reposZ	fill_sack)rrr"rrrrsrFcCs�z�y�|r|j�n8x|D]}|r|j|�qWx|D]}|r6|j|�q6W|j|�tjd�t|j�svtj	j
d��|jjr�tjddd�|jjD��|j|jj�|jj
r�tjddd�|jj
D��|s�|j�W�ntj	jk
�r }z&i}d|d	<d
|d<dd
t|�|fSd}~Xn�tj	jk
�rf}z&i}d|d	<d|d<ddt|�|fSd}~Xn�tj	jk
�r�}z&i}d|d	<d|d<ddt|�|fSd}~Xn@tj	j
k
�r�}zd}	dt|�}
i}|	|
|fSd}~XnXWd|jj�|j�XddifS)zE
    command is an function excpecting dnf.Base() as an argument
    zDependencies Resolvedzempty transactionzDownloading and installing: cSsg|]}t|��qSr)�str)r�prrrr-sz$_dnf_transaction.<locals>.<listcomp>z
Removing: cSsg|]}t|��qSr)rZ)rr[rrrr1sr*r,r+r&r(z/Failed: Packages failed to install properly: %sNrZrpmremoveerrors�z%sZfailed_deps�z9Failed: packages requested raised dependency problems: %s�z)Error while executing packages action: %szUpdate Succeeded)r^)Zupgrade_allZpackage_installZpackage_removeZresolverrr/ZtransactionrY�
exceptions�ErrorZinstall_setZdownload_packagesZ
remove_setZdo_transactionZMarkingErrorrZZ
DepsolveErrorr4r5r6)r"r-rrDrrr=r@rOZstatus�messagerrrr s^







r c	Cs�|dd�\}}}}t|�dkr(|dnd}d|i}|dk	rPt|�dkrP||d<|dk	rlt|�dkrl||d<|dk	r�t|�dkr�t|�|d<|dk	r�t|�dkr�||d<|jf|�j�}|r�|dSdS)N�r&rr,r:r;r')r/�intr1Zrun)	�qrr&r,r:r;r'rr<rrrrUsrcCsD|dd�\}}}}}|sd}d||||f}|r>|d|7}|fS)z6 Create a package name from an rhn package tuple.
    N�0z%s-%s:%s-%sz.%sr)Zpackage_tup�n�v�rr@�aZpkginforrrr2gsr2)N)N)N)rN)NN)NN)N)TT)rKrTZdnf.exceptionsrYZdnf.cliZup2date_clientrrrrZinitLogrrMZ
__rhnexport__rrrr	r
rrSrrr rr2rrrr�<module>s:

E
 

)


=__pycache__/systemid.cpython-36.opt-1.pyc000064400000001153150515722430014206 0ustar003

ge8h��@sddlZdgZddd�ZdS)�N�disablecCsJ|rddifSd}t|d�}|jdtjtj��|f�|j�ddifS)z5We have been told that we should disable the systemidrzno-ops for cachingz/etc/sysconfig/rhn/disable�wz4Disable lock created on %s. RHN Server Message:

%s
z*systemId disable lock file has been writen)�open�write�timeZctime�close)ZmessageTextZ
cache_onlyZdisableFilePath�fd�r	�/usr/lib/python3.6/systemid.pyrs

)N)rZ
__rhnexport__rr	r	r	r
�<module>s__pycache__/packages.cpython-36.pyc000064400000020274150515722430013171 0ustar003

.޾g.�@s�ddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ej
�ZdZddd	d
ddd
gZ
d!dd�Zd"dd�Zd#dd�Zd$dd
�Zd%dd�Zd&dd	�Zdd�Zd'dd
�Zd(dd�Zggdddfdd�Zdd�Zdd �ZdS))�N)�
up2dateLog)�config)�rpmUtils)�rhnPackageInfoz/var/lib/up2date/dbtimestamp�update�remove�refresh_list�
fullUpdate�checkNeedUpdate�runTransaction�verifycsj|rddifSt|t�s"ddifStjd|�tddd�}|jj�j���fd	d
�|D�}t||d|d�S)z0We have been told that we should remove packagesrzno-ops for caching�
z$Invalid arguments passed to functionzCalled remove_packagesTF)�load_system_repo�load_available_reposcsg|]}t�|��qS�)�_package_tup2obj)�.0�tup)�	installedr�/usr/lib/python3.6/packages.py�
<listcomp>:szremove.<locals>.<listcomp>)r�
allow_erasing�
cache_only)	�
isinstance�list�log�	log_debug�	_dnf_base�sack�queryr�_dnf_transaction)�package_listr�base�	to_remover)rrr-s


cCs�t|t�sddifStjd|�tddd�}|jj�j�}|jj�j�}d}g}g}�x"|D�]}t	|�dkrx|j
d�|\}	}
}}}
|
dkr�|dkr�|dkr�|
dkr�|j|	d	�r�tjd
|	�q\|dkr�d}|j|	|
d�j�}t
||�}|�sd
t|�}tjd|�|j
|�q\x`|D]N}|j|�}|dk�rHtjdt|��Pn|dk�rtjdt|��P�qW|j
|�q\W|�s�|�r�dddj|�ddd�f}n
ddif}|jj�|j�|St|||d�S)z:We have been told that we should retrieve/install packagesr
z$Invalid arguments passed to functionz
Called updateT)rrN��)�namezPackage %s is already installedr)r&�archz,Package %s is not available for installationzE: zPackage %s already installedz6More recent version of package %s is already installed� z-Failed: Packages failed to install properly:
�
�1�package_install_failure)�versionr&z$Requested packages already installed)�installr)rrrrrrrr�	available�len�append�filterZlatestr�_package_tup2strZlog_meZevr_cmp�join�_plugins�_unload�closer )r!rr"rr.�errZerrmsgs�
to_install�packager&r,�release�epochr'�pkgsZ
requested_pkg�pkgZpkg_cmp�retrrrr?s`











cCs�|rddifStddd�}|jj�j�}|jj�j�}g}g}xd|ddd�D]P}|\}}	t||�}
|	dkr~|
r~|j|
�qP|	dkrP|
rPt||�}|j|�qPW|r�|r�dd	ifSt|||d|d
�S)z� Run a transaction on a group of packages.
        This was historicaly meant as generic call, but
        is only called for rollback.
    rzno-ops for cachingT)rr�packagesN�e�iz6Requested package actions have already been performed.)r-rrr)rrrrr.rr0r )Ztransaction_datarr"rr.r8r#Zpackage_objectr9�actionr=�newrrrr�s&



cCstddd�}t|d|d�S)z$ Update all packages on the system. T)rr)�full_updater)rr )�forcerr"rrrr	�sc	Cs�|rddifSi}d}tj�}|dr.|d}d|}ytj|�d}Wndd|fSytjt�d}Wnd}YnX||dkr�dd	|fS|dkr�yttd
�}|j�Wndd|fStdd
�S)z� Check if the locally installed package list changed, if
        needed the list is updated on the server
        In case of error avoid pushing data to stay safe
    rzno-ops for cachingz/var/lib/rpm�dbpathz%s/Packages�zunable to stat the rpm database�
zNrpm database not modified since last update (or package list recently updated)zw+z!unable to open the timestamp file�)�rhnsd)rZinitUp2dateConfig�os�stat�LAST_UPDATE_FILE�openr6r)	rJr�datarFZcfgZRPM_PACKAGE_FILEZdbtimeZlast�filerrrr
�s4




c	CsR|rddifStjd�d}ytj�Wntd�ddifSt�ddifS)	z3 push again the list of rpm packages to the server rzno-ops for cachingzCalled refresh_rpmlistNz8ERROR: refreshing remote package list for System Profile�zError refreshing package listzrpmlist refreshed)rrrZupdatePackageProfile�print�touch_time_stamp)rJrr>rrrr�s


cCs^yttd�}|j�WnddifStj�}ytjt||f�WnddtifSdS)Nzw+rz!unable to open the timestamp filez6unable to set the time stamp on the time stamp file %s)rNrMr6�timerK�utime)Zfile_d�trrrrS�s

rScCsvtjd�|rddifSi}d|d<d|d<tj|�\}}||d<t|�rld|d<d|d<||d	<d
d|fSdd|fS)
NzCalled packages.verifyrzno-ops for cachingzpackages.verifyr&r,Zverify_infoz packages.verify.missing_packages�missing_packages�+z-packages requested to be verified are missingzpackages verified)rrrZverifyPackagesr/)r?rrOr>rWrrrr�s


TcCs6tj�}|jjs|j�|r$|j�|jddd�|S)NT)rr)�dnfZBaser4ZpluginsZinit_pluginsZread_all_reposZ	fill_sack)rrr"rrrrsrFcCs�z�y�|r|j�n8x|D]}|r|j|�qWx|D]}|r6|j|�q6W|j|�tjd�t|j�svtj	j
d��|jjr�tjddd�|jjD��|j|jj�|jj
r�tjddd�|jj
D��|s�|j�W�ntj	jk
�r }z&i}d|d	<d
|d<dd
t|�|fSd}~Xn�tj	jk
�rf}z&i}d|d	<d|d<ddt|�|fSd}~Xn�tj	jk
�r�}z&i}d|d	<d|d<ddt|�|fSd}~Xn@tj	j
k
�r�}zd}	dt|�}
i}|	|
|fSd}~XnXWd|jj�|j�XddifS)zE
    command is an function excpecting dnf.Base() as an argument
    zDependencies Resolvedzempty transactionzDownloading and installing: cSsg|]}t|��qSr)�str)r�prrrr-sz$_dnf_transaction.<locals>.<listcomp>z
Removing: cSsg|]}t|��qSr)rZ)rr[rrrr1sr*r,r+r&r(z/Failed: Packages failed to install properly: %sNrZrpmremoveerrors�z%sZfailed_deps�z9Failed: packages requested raised dependency problems: %s�z)Error while executing packages action: %szUpdate Succeeded)r^)Zupgrade_allZpackage_installZpackage_removeZresolverrr/ZtransactionrY�
exceptions�ErrorZinstall_setZdownload_packagesZ
remove_setZdo_transactionZMarkingErrorrZZ
DepsolveErrorr4r5r6)r"r-rrDrrr=r@rOZstatus�messagerrrr s^







r c	Cs�|dd�\}}}}t|�dkr(|dnd}d|i}|dk	rPt|�dkrP||d<|dk	rlt|�dkrl||d<|dk	r�t|�dkr�t|�|d<|dk	r�t|�dkr�||d<|jf|�j�}|r�|dSdS)N�r&rr,r:r;r')r/�intr1Zrun)	�qrr&r,r:r;r'rr<rrrrUsrcCsD|dd�\}}}}}|sd}d||||f}|r>|d|7}|fS)z6 Create a package name from an rhn package tuple.
    N�0z%s-%s:%s-%sz.%sr)Zpackage_tup�n�v�rr@�aZpkginforrrr2gsr2)N)N)N)rN)NN)NN)N)TT)rKrTZdnf.exceptionsrYZdnf.cliZup2date_clientrrrrZinitLogrrMZ
__rhnexport__rrrr	r
rrSrrr rr2rrrr�<module>s:

E
 

)


=__pycache__/up2date_config.cpython-36.opt-1.pyc000064400000003211150515722430015233 0ustar003

ge8h��@s^ddlZddlZddlmZej�ZddgZdZd
dd�Zddd�Z	dd�Z
ed	krZe
�dS)�N)�config�update�getcCs�|rddifStdkrtd�t|�ti�kr8ddifSg}tdrNtd}ng}x*|j�D]}||krjq\tj|||�q\Wt|�r�|Stj�ddifS)	z9Invoke this to change the ondisk configuration of up2daterzno-ops for caching�zcalled update_up2date_config�
z$Invalid arguments passed to functionZdisallowConfChangeszconfig updated)�
argVerbose�print�type�cfg�keys�set�lenZsave)Z
configdict�
cache_onlyZ
unknownparamsZ
skipParamsZparam�r�$/usr/lib/python3.6/up2date_config.pyrs$


cCsN|rddifStdkrtd�i}xtj�D]}t|||<q,Wddd|ifS)z.Reterieve the current configuration of up2daterzno-ops for cachingrzcalled get_up2date_configzconfiguration retrived�data)rrr
r)r�ret�krrrr3s
cCsjt�}|dd}ddl}|j�}||d<t|�ddl}|jt|��d|d<d|d<|jt|��dS)	N�rrZ
timeStampTestz)https://xmlrpc.cln.cloudlinux.com/XMLRPC/Z	serverURLz.https://ipv6.xmlrpc.cln.cloudlinux.com/XMLRPC/Z
serverURLipv6)r�timer�pprintr)Z
configdatatupZ
configdatarZ	timestamprrrr�main@sr�__main__)N)N)�os�reZup2date_clientrZinitUp2dateConfigr
Z
__rhnexport__rrrr�__name__rrrr�<module>s


__pycache__/errata.cpython-36.opt-1.pyc000064400000003045150515722430013625 0ustar003

.޾g�	�@sfddlmZddlmZddlmZddlmZdgZdZdd�Zdd
d�Z	dd�Z
ed
krbe
�d	S)�)�	rhnserver)�up2dateAuth)�pkgUtils)�packages�update�cCstj�}|jjtj�|�S)N)rZ	RhnServerZerrataZ
getErrataInforZgetSystemId)Z	errata_id�s�r	�/usr/lib/python3.6/errata.py�__getErrataInfosrNc
Cs�g}t|�tg�tf�gkr"|g}x|D]}t|�}||}q(Wi}i}x4tjdd�D]$}|||d|d<|||d<qVWi}t|d�dk�rx�|D]|}d|d|df|kr�|||d|d<q�d|d|kr�|||d|d<q�|dd	kr�|d|kr�|||d<q�Wn*x(|D] }|d|k�r"|||d<�q"Wt|j��}|gk�r�i}	d
|	d<d|	d<||	d
<dd|	fStj||�S)N�)ZgetArch�nameZarchr�z%s%sz%snoarchZnoarch�0�versionzerrata.update.no_packagesZerratas�'z*No packages from that errata are available)	�typerrZgetInstalledPackageList�len�list�valuesrr)
ZerrataidlistZ
cache_onlyZpackagelistZerrataidZtmpListZcurrent_packages_with_archZcurrent_packages�p�u�datar	r	r
rsB



cCsttdg��dS)Ni�ie)�printrr	r	r	r
�mainPsr�__main__)N)Zup2date_clientrrrZrhn.actionsrZ
__rhnexport__ZACTION_VERSIONrrr�__name__r	r	r	r
�<module>
s
7__pycache__/hardware.cpython-36.opt-1.pyc000064400000001653150515722430014147 0ustar003

ge8hI�@sRddlmZddlmZddlmZdZdgZd
dd�Zdd�Zed	krNe�dS)�)�hardware)�up2dateAuth)�	rpcServer�refresh_listNc	Csh|rddifStj�}tj�}tdkr.td�y|jjtj	�|�Wntd�ddifSddifS)	Nrzno-ops for caching�zCalled refresh_hardwarez3ERROR: sending hardware database for System Profile�z Error refreshing system hardwarezhardware list refreshed)
rZHardwarerZ	getServer�
argVerbose�printZregistrationZrefresh_hw_profilerZgetSystemId)Z
cache_onlyZhardwareList�s�r�/usr/lib/python3.6/hardware.pyrs


cCstt��dS)N)r	rrrrr�main(sr
�__main__)N)	Zup2date_clientrrrrZ
__rhnexport__rr
�__name__rrrr�<module>
s
__pycache__/rhnsd.cpython-36.pyc000064400000002367150515722430012534 0ustar003

ge8hS�@srddlZdgZd
dd�Zddd�Zedkrneed��eedd	��eed
d	d��eed	d��eed��dS)�N�	configurecCs�d}t|d�}|j�}d}d}g}xB|D]:}|j�}	|j|	�|	jdd�}
|
ddkrZ|}|d}q(W|dkrzd|||<|j�t|d�}d	j|�}|j|�|j�dS)
Nz/etc/sysconfig/rhn/rhnsd�rr�=�ZINTERVALzINTERVAL=%s�w�
)�open�	readlines�strip�append�split�close�join�write)�interval�
cache_onlyZrhnsdconfig�fd�lines�count�indexZtmplines�lineZtmp�comps�contents�r�/usr/lib/python3.6/rhnsd.py�
__configRhnsds(





rcCsb|rddifSd}|rByt|�d}Wntk
r@ddifSX|rXtjd�}|d}d|ifS)	Nrzno-ops for caching�zrhnsd interval config updated. �%z)Could not modify /etc/sysconfig/rhn/rhnsdz'/sbin/service rhnsd restart > /dev/nullzrhnsd restarted)r�IOError�os�system)r�restartr�msgZrcrrrr(s

�__main__Z240Z361rZ127)r!Z192)N)NNN)rZ
__rhnexport__rr�__name__�printrrrr�<module>s

__pycache__/systemid.cpython-36.pyc000064400000001153150515722440013250 0ustar003

ge8h��@sddlZdgZddd�ZdS)�N�disablecCsJ|rddifSd}t|d�}|jdtjtj��|f�|j�ddifS)z5We have been told that we should disable the systemidrzno-ops for cachingz/etc/sysconfig/rhn/disable�wz4Disable lock created on %s. RHN Server Message:

%s
z*systemId disable lock file has been writen)�open�write�timeZctime�close)ZmessageTextZ
cache_onlyZdisableFilePath�fd�r	�/usr/lib/python3.6/systemid.pyrs

)N)rZ
__rhnexport__rr	r	r	r
�<module>s__pycache__/reboot.cpython-36.pyc000064400000002262150515722440012703 0ustar003

ge8hN�@s^ddlZdgZddlmZddlmZej�Zej�ZdZ	d
dd�Z
dd�Zed	krZe�dS)�N�reboot)�
up2dateLog)�config�c
Cs�|rddifStdr ddifStj�}ddi}dtj�d	d
}|s�y4|rftjdddd
d|g�ntjdddd|g�Wn"tk
r�d|d<dd|fSXtjd�dd|fS)Nrzno-ops for cachingZnoReboot�&z*Up2date is configured not to allow reboots�version�0zReboot of system "�z'" initiated by Spacewalk reboot action.z/sbin/shutdownz-rz-kz+3zreboot.reboot.shutdown_failed�name�"z Could not execute /sbin/shutdownzRebooting the system nowzReboot sucessfully started)�cfg�os�fork�uname�execvp�OSError�logZlog_me)�testZ
cache_only�pid�dataZreboot_message�r�/usr/lib/python3.6/reboot.pyrs"


cCsttdd��dS)Nr	)r)�printrrrrr�main1sr�__main__)NN)
r
Z
__rhnexport__Zup2date_clientrrZinitUp2dateConfigrZinitLogrZACTION_VERSIONrr�__name__rrrr�<module>	s
__pycache__/reboot.cpython-36.opt-1.pyc000064400000002262150515722440013642 0ustar003

ge8hN�@s^ddlZdgZddlmZddlmZej�Zej�ZdZ	d
dd�Z
dd�Zed	krZe�dS)�N�reboot)�
up2dateLog)�config�c
Cs�|rddifStdr ddifStj�}ddi}dtj�d	d
}|s�y4|rftjdddd
d|g�ntjdddd|g�Wn"tk
r�d|d<dd|fSXtjd�dd|fS)Nrzno-ops for cachingZnoReboot�&z*Up2date is configured not to allow reboots�version�0zReboot of system "�z'" initiated by Spacewalk reboot action.z/sbin/shutdownz-rz-kz+3zreboot.reboot.shutdown_failed�name�"z Could not execute /sbin/shutdownzRebooting the system nowzReboot sucessfully started)�cfg�os�fork�uname�execvp�OSError�logZlog_me)�testZ
cache_only�pid�dataZreboot_message�r�/usr/lib/python3.6/reboot.pyrs"


cCsttdd��dS)Nr	)r)�printrrrrr�main1sr�__main__)NN)
r
Z
__rhnexport__Zup2date_clientrrZinitUp2dateConfigrZinitLogrZACTION_VERSIONrr�__name__rrrr�<module>	s
__pycache__/rhnsd.cpython-36.opt-1.pyc000064400000002367150515722440013474 0ustar003

ge8hS�@srddlZdgZd
dd�Zddd�Zedkrneed��eedd	��eed
d	d��eed	d��eed��dS)�N�	configurecCs�d}t|d�}|j�}d}d}g}xB|D]:}|j�}	|j|	�|	jdd�}
|
ddkrZ|}|d}q(W|dkrzd|||<|j�t|d�}d	j|�}|j|�|j�dS)
Nz/etc/sysconfig/rhn/rhnsd�rr�=�ZINTERVALzINTERVAL=%s�w�
)�open�	readlines�strip�append�split�close�join�write)�interval�
cache_onlyZrhnsdconfig�fd�lines�count�indexZtmplines�lineZtmp�comps�contents�r�/usr/lib/python3.6/rhnsd.py�
__configRhnsds(





rcCsb|rddifSd}|rByt|�d}Wntk
r@ddifSX|rXtjd�}|d}d|ifS)	Nrzno-ops for caching�zrhnsd interval config updated. �%z)Could not modify /etc/sysconfig/rhn/rhnsdz'/sbin/service rhnsd restart > /dev/nullzrhnsd restarted)r�IOError�os�system)r�restartr�msgZrcrrrr(s

�__main__Z240Z361rZ127)r!Z192)N)NNN)rZ
__rhnexport__rr�__name__�printrrrr�<module>s

__pycache__/__init__.cpython-36.pyc000064400000000161150515722440013144 0ustar003

ge8h�@sdS)N�rrr�/usr/lib/python3.6/__init__.py�<module>s__pycache__/__init__.cpython-36.opt-1.pyc000064400000000161150515722440014103 0ustar003

ge8h�@sdS)N�rrr�/usr/lib/python3.6/__init__.py�<module>s__pycache__/errata.cpython-36.pyc000064400000003045150515722440012667 0ustar003

.޾g�	�@sfddlmZddlmZddlmZddlmZdgZdZdd�Zdd
d�Z	dd�Z
ed
krbe
�d	S)�)�	rhnserver)�up2dateAuth)�pkgUtils)�packages�update�cCstj�}|jjtj�|�S)N)rZ	RhnServerZerrataZ
getErrataInforZgetSystemId)Z	errata_id�s�r	�/usr/lib/python3.6/errata.py�__getErrataInfosrNc
Cs�g}t|�tg�tf�gkr"|g}x|D]}t|�}||}q(Wi}i}x4tjdd�D]$}|||d|d<|||d<qVWi}t|d�dk�rx�|D]|}d|d|df|kr�|||d|d<q�d|d|kr�|||d|d<q�|dd	kr�|d|kr�|||d<q�Wn*x(|D] }|d|k�r"|||d<�q"Wt|j��}|gk�r�i}	d
|	d<d|	d<||	d
<dd|	fStj||�S)N�)ZgetArch�nameZarchr�z%s%sz%snoarchZnoarch�0�versionzerrata.update.no_packagesZerratas�'z*No packages from that errata are available)	�typerrZgetInstalledPackageList�len�list�valuesrr)
ZerrataidlistZ
cache_onlyZpackagelistZerrataidZtmpListZcurrent_packages_with_archZcurrent_packages�p�u�datar	r	r
rsB



cCsttdg��dS)Ni�ie)�printrr	r	r	r
�mainPsr�__main__)N)Zup2date_clientrrrZrhn.actionsrZ
__rhnexport__ZACTION_VERSIONrrr�__name__r	r	r	r
�<module>
s
7reboot.py000075500000002532150515722440006422 0ustar00#!/usr/libexec/platform-python

# Client code for Update Agent
# Copyright (c) 1999--2018 Red Hat, Inc.  Distributed under GPLv2.
#
# Author: Adrian Likins <alikins@redhat.com
#

import os

__rhnexport__ = [
    'reboot']

from up2date_client import up2dateLog
from up2date_client import config

cfg = config.initUp2dateConfig()
log = up2dateLog.initLog()

# action version we understand
ACTION_VERSION = 2

def reboot(test=None, cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})

    if cfg['noReboot']:
        return (38, "Up2date is configured not to allow reboots", {})

    pid = os.fork()
    data = {'version': '0'}
    reboot_message = 'Reboot of system "' + os.uname()[1] + '" initiated by Spacewalk reboot action.'
    if not pid:
        try:
            if test:
                os.execvp("/sbin/shutdown", ['/sbin/shutdown','-r','-k', '+3', reboot_message])
            else:
                os.execvp("/sbin/shutdown", ['/sbin/shutdown','-r', '+3', reboot_message])
        except OSError:
            data['name'] = "reboot.reboot.shutdown_failed"
            return (34, "Could not execute /sbin/shutdown", data)

    log.log_me("Rebooting the system now")
    # no point in waiting around

    return (0, "Reboot sucessfully started", data)


def main():
    print(reboot(test=1))

if __name__ == "__main__":
    main()
rhnsd.py000075500000003137150515722440006250 0ustar00#!/usr/libexec/platform-python

# Copyright (c) 1999--2018 Red Hat, Inc.  Distributed under GPLv2.
#
# Author: Adrian Likins <alikins@redhat.com>
#

import os

# mark this module as acceptable
__rhnexport__ = [
    'configure',
]

def __configRhnsd(interval, cache_only=None):
    rhnsdconfig = "/etc/sysconfig/rhn/rhnsd"
    fd = open(rhnsdconfig, "r")
    lines = fd.readlines()
    count = 0
    index = None
    tmplines = []
    for line in lines:
        tmp = line.strip()
        tmplines.append(tmp)
        comps = tmp.split("=", 1)
        if comps[0] == "INTERVAL":
            index = count
        count = count + 1

    if index != None:
        tmplines[index] = "INTERVAL=%s" % interval

    fd.close()
    fd = open(rhnsdconfig, "w")
    contents = "\n".join(tmplines)
    fd.write(contents)
    fd.close()


def configure(interval=None, restart=None, cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})
    msg = ""
    if interval:
        try:
            __configRhnsd(interval)
            msg = "rhnsd interval config updated. "
        except IOError:
            # i'm runing as root, must of been chattr'ed.
            # i'll resist the erge to unchattr this file
            return (37,"Could not modify /etc/sysconfig/rhn/rhnsd", {})

    if restart:
        rc = os.system("/sbin/service rhnsd restart > /dev/null")
        msg = msg + "rhnsd restarted"

    return(0,  msg, {})


if __name__ == "__main__":
    print(configure("240"))

    print(configure("361", 1))

    print(configure("127", restart=1))

    print(configure(restart=1))

    print(configure("192"))
systemid.py000075500000001361150515722440006770 0ustar00#!/usr/libexec/platform-python
#
# Copyright (c) 1999--2018 Red Hat, Inc.  Distributed under GPLv2.
#
# Author: Adrian Likins <alikins@redhat.com>

import time


# mark this module as acceptable
__rhnexport__ = [
    'disable',
]

def disable(messageText, cache_only=None):
    """We have been told that we should disable the systemid"""
    if cache_only:
        return (0, "no-ops for caching", {})

    disableFilePath = "/etc/sysconfig/rhn/disable"
    # open and shut off
    fd = open(disableFilePath, "w")
    fd.write("Disable lock created on %s. RHN Server Message:\n\n%s\n" % (
        time.ctime(time.time()), messageText))
    fd.close()

    # done if we survived this long
    return(0, "systemId disable lock file has been writen", {})

packages.py000064400000027030150515722440006703 0ustar00#
# Copyright (c) 2015--2017 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

import os
import time

import dnf.exceptions
import dnf.cli

from up2date_client import up2dateLog
from up2date_client import config
from up2date_client import rpmUtils
from up2date_client import rhnPackageInfo

log = up2dateLog.initLog()

# file used to keep track of the next time rhn_check
# is allowed to update the package list on the server
LAST_UPDATE_FILE = "/var/lib/up2date/dbtimestamp"

# mark this module as acceptable
__rhnexport__ = [
    'update',
    'remove',
    'refresh_list',
    'fullUpdate',
    'checkNeedUpdate',
    'runTransaction',
    'verify'
]


def remove(package_list, cache_only=None):
    """We have been told that we should remove packages"""
    if cache_only:
        return (0, "no-ops for caching", {})

    if not isinstance(package_list, list):
        return (13, "Invalid arguments passed to function", {})

    log.log_debug("Called remove_packages", package_list)

    # initialize dnf
    base = _dnf_base(load_system_repo=True, load_available_repos=False)
    installed = base.sack.query().installed()
    to_remove = [_package_tup2obj(installed, tup) for tup in package_list]
    return _dnf_transaction(base, remove=to_remove, allow_erasing=True,
                            cache_only=cache_only)


def update(package_list, cache_only=None):
    """We have been told that we should retrieve/install packages"""
    if not isinstance(package_list, list):
        return (13, "Invalid arguments passed to function", {})

    log.log_debug("Called update", package_list)

    # initialize dnf
    base = _dnf_base(load_system_repo=True, load_available_repos=True)
    installed = base.sack.query().installed()
    available = base.sack.query().available()

    # skip already installed packages
    err = None
    errmsgs = []
    to_install = []
    for package in package_list:
        if len(package) < 5:
            package.append('')

        (name, version, release, epoch, arch) = package
        if version == '' and release == '' \
           and epoch == '' and arch == '' \
           and installed.filter(name=name):
            log.log_debug('Package %s is already installed' % name)
            continue

        if epoch == '':
            epoch = 0

        pkgs = installed.filter(name=name, arch=arch).latest()
        requested_pkg = _package_tup2obj(available, package)

        if not requested_pkg:
                err = 'Package %s is not available for installation' \
                      % _package_tup2str(package)
                log.log_me('E: ', err)
                errmsgs.append(err)
                continue

        for pkg in pkgs:
            pkg_cmp = pkg.evr_cmp(requested_pkg)
            if pkg_cmp == 0:
                log.log_debug('Package %s already installed'
                              % _package_tup2str(package))
                break
            elif pkg_cmp > 0:
                log.log_debug('More recent version of package %s is already installed'
                              % _package_tup2str(package))
                break
        else:
            to_install.append(requested_pkg)

    # Don't proceed further with empty list,
    # since this would result into an empty yum transaction
    if not to_install:
        if err:
            ret = (32, "Failed: Packages failed to install properly:\n" + '\n'.join(errmsgs),
                   {'version': '1', 'name': "package_install_failure"})
        else:
            ret = (0, "Requested packages already installed", {})
        # workaround for RhBug:1218071
        base._plugins._unload()
        base.close()
        return ret

    return _dnf_transaction(base, install=to_install, cache_only=cache_only)


def runTransaction(transaction_data, cache_only=None):
    """ Run a transaction on a group of packages.
        This was historicaly meant as generic call, but
        is only called for rollback.
    """
    if cache_only:
        return (0, "no-ops for caching", {})

    # initialize dnf
    base = _dnf_base(load_system_repo=True, load_available_repos=True)
    installed = base.sack.query().installed()
    available = base.sack.query().available()
    to_install = []
    to_remove = []
    for package_object in transaction_data['packages'][:]:
        [package, action] = package_object
        pkg = _package_tup2obj(installed, package)

        if action == 'e' and pkg:
            to_remove.append(pkg)
        elif action == 'i' and not pkg:
            new = _package_tup2obj(available, package)
            to_install.append(new)

    # Don't proceed further with empty package lists
    if not to_install and not to_remove:
        return (0, "Requested package actions have already been performed.", {})

    return _dnf_transaction(base, install=to_install, remove=to_remove,
                            allow_erasing=True, cache_only=cache_only)


def fullUpdate(force=0, cache_only=None):
    """ Update all packages on the system. """
    base = _dnf_base(load_system_repo=True, load_available_repos=True)
    return _dnf_transaction(base, full_update=True, cache_only=cache_only)


# The following functions are the same as the old up2date ones.
def checkNeedUpdate(rhnsd=None, cache_only=None):
    """ Check if the locally installed package list changed, if
        needed the list is updated on the server
        In case of error avoid pushing data to stay safe
    """
    if cache_only:
        return (0, "no-ops for caching", {})

    data = {}
    dbpath = "/var/lib/rpm"
    cfg = config.initUp2dateConfig()
    if cfg['dbpath']:
        dbpath = cfg['dbpath']
    RPM_PACKAGE_FILE = "%s/Packages" % dbpath

    try:
        dbtime = os.stat(RPM_PACKAGE_FILE)[8]  # 8 is st_mtime
    except:
        return (0, "unable to stat the rpm database", data)
    try:
        last = os.stat(LAST_UPDATE_FILE)[8]
    except:
        last = 0

    # Never update the package list more than once every 1/2 hour
    if last >= (dbtime - 10):
        return (0, "rpm database not modified since last update (or package "
                "list recently updated)", data)

    if last == 0:
        try:
            file = open(LAST_UPDATE_FILE, "w+")
            file.close()
        except:
            return (0, "unable to open the timestamp file", data)

    # call the refresh_list action with a argument so we know it's
    # from rhnsd
    return refresh_list(rhnsd=1)


def refresh_list(rhnsd=None, cache_only=None):
    """ push again the list of rpm packages to the server """
    if cache_only:
        return (0, "no-ops for caching", {})
    log.log_debug("Called refresh_rpmlist")

    ret = None

    try:
        rhnPackageInfo.updatePackageProfile()
    except:
        print("ERROR: refreshing remote package list for System Profile")
        return (20, "Error refreshing package list", {})

    touch_time_stamp()
    return (0, "rpmlist refreshed", {})


def touch_time_stamp():
    try:
        file_d = open(LAST_UPDATE_FILE, "w+")
        file_d.close()
    except:
        return (0, "unable to open the timestamp file", {})
    # Never update the package list more than once every hour.
    t = time.time()
    try:
        os.utime(LAST_UPDATE_FILE, (t, t))

    except:
        return (0, "unable to set the time stamp on the time stamp file %s"
                % LAST_UPDATE_FILE, {})


def verify(packages, cache_only=None):
    log.log_debug("Called packages.verify")
    if cache_only:
        return (0, "no-ops for caching", {})

    data = {}
    data['name'] = "packages.verify"
    data['version'] = 0
    ret, missing_packages = rpmUtils.verifyPackages(packages)

    data['verify_info'] = ret

    if len(missing_packages):
        data['name'] = "packages.verify.missing_packages"
        data['version'] = 0
        data['missing_packages'] = missing_packages
        return(43, "packages requested to be verified are missing", data)

    return (0, "packages verified", data)


def _dnf_base(load_system_repo=True, load_available_repos=True):
    # initialize dnf
    base = dnf.Base()

    if not base._plugins.plugins:
        base.init_plugins()
    if load_available_repos:
        base.read_all_repos()
    base.fill_sack(load_system_repo=True, load_available_repos=True)
    return base


def _dnf_transaction(base, install=[], remove=[], full_update=False,
                     allow_erasing=False, cache_only=None):
    """
    command is an function excpecting dnf.Base() as an argument
    """
    try:
        if full_update:
            base.upgrade_all()
        else:
            for pkg in install:
                if pkg:
                    base.package_install(pkg)
            for pkg in remove:
                if pkg:
                    base.package_remove(pkg)

        base.resolve(allow_erasing)
        log.log_debug("Dependencies Resolved")
        if not len(base.transaction):
            raise dnf.exceptions.Error('empty transaction')
        if base.transaction.install_set:
            log.log_debug("Downloading and installing: ",
                          [str(p) for p in base.transaction.install_set])
            base.download_packages(base.transaction.install_set)
        if base.transaction.remove_set:
            log.log_debug("Removing: ",
                          [str(p) for p in base.transaction.remove_set])
        if not cache_only:
            base.do_transaction()

    except dnf.exceptions.MarkingError as e:
        data = {}
        data['version'] = "1"
        data['name'] = "package_install_failure"

        return (32, "Failed: Packages failed to install "
                "properly: %s" % str(e), data)
    except dnf.exceptions.MarkingError as e:
        data = {}
        data['version'] = 0
        data['name'] = "rpmremoveerrors"

        return (15, "%s" % str(e), data)
    except dnf.exceptions.DepsolveError as e:
        data = {}
        data["version"] = "1"
        data["name"] = "failed_deps"
        return (18, "Failed: packages requested raised "
                "dependency problems: %s" % str(e), data)
    except dnf.exceptions.Error as e:
        status = 6,
        message = "Error while executing packages action: %s" % str(e)
        data = {}
        return (status, message, data)
    finally:
        # workaround for RhBug:1218071
        base._plugins._unload()
        base.close()

    return (0, "Update Succeeded", {})


def _package_tup2obj(q, tup):
    (name, version, release, epoch) = tup[:4]
    arch = tup[4] if len(tup) > 4 else None
    query = {'name': name}
    if version is not None and len(version) > 0:
        query['version'] = version
    if release is not None and len(release) > 0:
        query['release'] = release
    if epoch is not None and len(epoch) > 0:
        query['epoch'] = int(epoch)
    if arch is not None and len(arch) > 0:
        query['arch'] = arch
    pkgs = q.filter(**query).run()
    if pkgs:
        return pkgs[0]
    return None


def _package_tup2str(package_tup):
    """ Create a package name from an rhn package tuple.
    """
    n, v, r, e, a = package_tup[:]
    if not e:
        e = '0'
    pkginfo = '%s-%s:%s-%s' % (n, e, v, r)
    if a:
        pkginfo += '.%s' % (a)
    return (pkginfo,)

hardware.py000075500000002125150515722440006723 0ustar00#!/usr/libexec/platform-python


# Copyright (c) 1999--2018 Red Hat, Inc.  Distributed under GPLv2.
#
# Author: Adrian Likins <alikins@redhat.com>


# imports are a bit weird here to avoid name collions on "harware"
from up2date_client import hardware
from up2date_client import up2dateAuth
from up2date_client import rpcServer
argVerbose = 0

__rhnexport__ = [
    'refresh_list' ]

# resync hardware information with the server profile
def refresh_list(cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})

    # read all hardware in
    hardwareList = hardware.Hardware()

    s = rpcServer.getServer()

    if argVerbose > 1:
        print("Called refresh_hardware")

    try:
        s.registration.refresh_hw_profile(up2dateAuth.getSystemId(),
                                          hardwareList)
    except:
        print("ERROR: sending hardware database for System Profile")
        return (12, "Error refreshing system hardware", {})

    return (0, "hardware list refreshed", {})

def main():
        print(refresh_list())

if __name__ == "__main__":
        main()
errata.py000064400000004625150515722440006410 0ustar00#
# Client code for Update Agent
# Copyright (c) 1999--2016 Red Hat, Inc.  Distributed under GPLv2.
#
# Author: Adrian Likins <alikins@redhat.com
#

# This file is copied from yum-rhn-plugin

from up2date_client import rhnserver
from up2date_client import up2dateAuth
from up2date_client import pkgUtils
from rhn.actions import packages

__rhnexport__ = [
    'update']

# action version we understand
ACTION_VERSION = 2

def __getErrataInfo(errata_id):
    s = rhnserver.RhnServer()
    return s.errata.getErrataInfo(up2dateAuth.getSystemId(), errata_id)

def update(errataidlist, cache_only=None):
    packagelist = []

    if type(errataidlist) not in [type([]), type(())]:
        errataidlist = [ errataidlist ]

    for errataid in errataidlist:
        tmpList = __getErrataInfo(errataid)
        packagelist = packagelist + tmpList

    current_packages_with_arch = {}
    current_packages ={}
    for p in pkgUtils.getInstalledPackageList(getArch=1):
        current_packages_with_arch[p['name'] + p['arch']] = p
        current_packages[p['name']] = p

    u = {}
    # only update packages that are currently installed
    # since an "applicable errata" may only contain some packages
    # that actually apply. aka kernel. Fun fun fun.

    if len(packagelist[0]) > 4:
        # Newer sats send down arch, filter using name+arch
        for p in packagelist:
            if "%s%s" % (p[0], p[4]) in current_packages_with_arch:
                u[p[0] + p[4]] = p
            elif "%snoarch" % p[0] in current_packages_with_arch:
                u[p[0] + p[4]] = p
            elif p[4] == "noarch" and p[0] in current_packages:
                u[p[0]] = p
    else:
        # 5.2 and older sats + hosted dont send arch
        for p in packagelist:
            if p[0] in current_packages:
                u[p[0]] = p


    # XXX: Fix me - once we keep all errata packages around,
    # this is the WRONG thing to do - we want to keep the specific versions
    # that the user has asked for.
    packagelist = list(u.values())

    if packagelist == []:
        data = {}
        data['version'] = "0"
        data['name'] = "errata.update.no_packages"
        data['erratas'] = errataidlist

        return (39,
                "No packages from that errata are available",
                data)

    return packages.update(packagelist, cache_only)


def main():
        print(update([23423423]))


if __name__ == "__main__":
        main()