home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / hplip / base / service.py < prev    next >
Encoding:
Python Source  |  2006-08-30  |  3.2 KB  |  110 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2003-2006 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22.  
  23. #Std Lib
  24. import socket
  25.  
  26. # Local
  27. from g import *
  28. from codes import *
  29. import msg
  30.  
  31.  
  32. def registerGUI(sock, username, host, port, pid, typ):
  33.     msg.sendEvent(sock,
  34.                   "RegisterGUIEvent",
  35.                   None,
  36.                   { 'username' : username,
  37.                     'hostname' : host,
  38.                     'port' : port,
  39.                     'pid' : pid,
  40.                     'type' : typ }
  41.                   )
  42.  
  43.  
  44. def unregisterGUI(sock, username, pid, typ):
  45.     msg.sendEvent(sock,
  46.                    "UnRegisterGUIEvent",
  47.                    None,
  48.                    {
  49.                        'username' : username,
  50.                        'pid' : pid,
  51.                        'type' : typ,
  52.                    }
  53.                   )
  54.  
  55.  
  56.  
  57. def testEmail(sock, username): 
  58.     fields = {}
  59.     result_code = ERROR_SUCCESS
  60.     try:
  61.         fields, data, result_code = \
  62.             msg.xmitMessage(sock,
  63.                             "TestEmail",
  64.                             None,
  65.                             {'username': username,})
  66.     except Error, e:
  67.         result_code = e.opt
  68.         utils.log_exception()
  69.  
  70.     return result_code
  71.  
  72.  
  73. def sendEvent(sock, event, typ='event', jobid=0, 
  74.               username=prop.username, device_uri='', 
  75.               other_fields={}, data=None):
  76.     
  77.     fields = {'job-id'        : jobid,
  78.               'event-type'    : typ,
  79.               'event-code'    : event,
  80.               'username'      : username,
  81.               'device-uri'    : device_uri,
  82.               'retry-timeout' : 0,}
  83.  
  84.     if other_fields:
  85.         fields.update(other_fields)
  86.  
  87.     msg.sendEvent(sock, 'Event', data, fields)
  88.  
  89.  
  90. def setAlertsEx(sock):
  91.     email_to_addresses = user_cfg.alerts.email_to_addresses
  92.     email_from_address = user_cfg.alerts.email_from_address
  93.     email_alerts = user_cfg.alerts.email_alerts
  94.     
  95.     setAlerts(sock, email_alerts, email_from_address, email_to_addresses)
  96.     
  97.  
  98. def setAlerts(sock, email_alerts, email_from_address, email_to_addresses): 
  99.     fields, data, result_code = \
  100.         msg.xmitMessage(sock,
  101.                         "SetAlerts",
  102.                         None,
  103.                         {
  104.                             'username'      : prop.username,
  105.                             'email-alerts'  : email_alerts,
  106.                             'email-from-address' : email_from_address,
  107.                             'email-to-addresses' : email_to_addresses,
  108.                         })
  109.                         
  110.