File: service.py

package info (click to toggle)
hplip 1.6.10-3etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 35,140 kB
  • ctags: 10,985
  • sloc: ansic: 48,004; cpp: 40,938; python: 29,973; xml: 14,675; sh: 9,841; perl: 4,257; makefile: 786
file content (109 lines) | stat: -rw-r--r-- 3,284 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
#
# (c) Copyright 2003-2006 Hewlett-Packard Development Company, L.P.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
#
# Author: Don Welch
#


#Std Lib
import socket

# Local
from g import *
from codes import *
import msg


def registerGUI(sock, username, host, port, pid, typ):
    msg.sendEvent(sock,
                  "RegisterGUIEvent",
                  None,
                  { 'username' : username,
                    'hostname' : host,
                    'port' : port,
                    'pid' : pid,
                    'type' : typ }
                  )


def unregisterGUI(sock, username, pid, typ):
    msg.sendEvent(sock,
                   "UnRegisterGUIEvent",
                   None,
                   {
                       'username' : username,
                       'pid' : pid,
                       'type' : typ,
                   }
                  )



def testEmail(sock, username): 
    fields = {}
    result_code = ERROR_SUCCESS
    try:
        fields, data, result_code = \
            msg.xmitMessage(sock,
                            "TestEmail",
                            None,
                            {'username': username,})
    except Error, e:
        result_code = e.opt
        utils.log_exception()

    return result_code


def sendEvent(sock, event, typ='event', jobid=0, 
              username=prop.username, device_uri='', 
              other_fields={}, data=None):
    
    fields = {'job-id'        : jobid,
              'event-type'    : typ,
              'event-code'    : event,
              'username'      : username,
              'device-uri'    : device_uri,
              'retry-timeout' : 0,}

    if other_fields:
        fields.update(other_fields)

    msg.sendEvent(sock, 'Event', data, fields)


def setAlertsEx(sock):
    email_to_addresses = user_cfg.alerts.email_to_addresses
    email_from_address = user_cfg.alerts.email_from_address
    email_alerts = user_cfg.alerts.email_alerts
    
    setAlerts(sock, email_alerts, email_from_address, email_to_addresses)
    

def setAlerts(sock, email_alerts, email_from_address, email_to_addresses): 
    fields, data, result_code = \
        msg.xmitMessage(sock,
                        "SetAlerts",
                        None,
                        {
                            'username'      : prop.username,
                            'email-alerts'  : email_alerts,
                            'email-from-address' : email_from_address,
                            'email-to-addresses' : email_to_addresses,
                        })