home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / base / service.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  3.2 KB  |  109 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2003-2007 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. #Std Lib
  23. import socket
  24.  
  25. # Local
  26. from g import *
  27. from codes import *
  28. import msg
  29.  
  30.  
  31. def registerGUI(sock, username, host, port, pid, typ):
  32.     msg.sendEvent(sock,
  33.                   "RegisterGUIEvent",
  34.                   None,
  35.                   { 'username' : username,
  36.                     'hostname' : host,
  37.                     'port' : port,
  38.                     'pid' : pid,
  39.                     'type' : typ }
  40.                   )
  41.  
  42.  
  43. def unregisterGUI(sock, username, pid, typ):
  44.     msg.sendEvent(sock,
  45.                    "UnRegisterGUIEvent",
  46.                    None,
  47.                    {
  48.                        'username' : username,
  49.                        'pid' : pid,
  50.                        'type' : typ,
  51.                    }
  52.                   )
  53.  
  54.  
  55.  
  56. def testEmail(sock, username): 
  57.     fields = {}
  58.     result_code = ERROR_SUCCESS
  59.     try:
  60.         fields, data, result_code = \
  61.             msg.xmitMessage(sock,
  62.                             "TestEmail",
  63.                             None,
  64.                             {'username': username,})
  65.     except Error, e:
  66.         result_code = e.opt
  67.         utils.log_exception()
  68.  
  69.     return result_code
  70.  
  71.  
  72. def sendEvent(sock, event, typ='event', jobid=0, 
  73.               username=prop.username, device_uri='', 
  74.               other_fields={}, data=None):
  75.  
  76.     fields = {'job-id'        : jobid,
  77.               'event-type'    : typ,
  78.               'event-code'    : event,
  79.               'username'      : username,
  80.               'device-uri'    : device_uri,
  81.               'retry-timeout' : 0,}
  82.  
  83.     if other_fields:
  84.         fields.update(other_fields)
  85.  
  86.     msg.sendEvent(sock, 'Event', data, fields)
  87.  
  88.  
  89. def setAlertsEx(sock):
  90.     email_to_addresses = user_cfg.alerts.email_to_addresses
  91.     email_from_address = user_cfg.alerts.email_from_address
  92.     email_alerts = user_cfg.alerts.email_alerts
  93.  
  94.     setAlerts(sock, email_alerts, email_from_address, email_to_addresses)
  95.  
  96.  
  97. def setAlerts(sock, email_alerts, email_from_address, email_to_addresses): 
  98.     fields, data, result_code = \
  99.         msg.xmitMessage(sock,
  100.                         "SetAlerts",
  101.                         None,
  102.                         {
  103.                             'username'      : prop.username,
  104.                             'email-alerts'  : email_alerts,
  105.                             'email-from-address' : email_from_address,
  106.                             'email-to-addresses' : email_to_addresses,
  107.                         })
  108.  
  109.