author | Sue Sohn <Susan.Sohn@Oracle.COM> |
Fri, 20 Aug 2010 11:31:18 -0600 | |
changeset 862 | e9f31f2f2f2d |
parent 649 | ba353c37b287 |
child 878 | ab329590d9ca |
permissions | -rw-r--r-- |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
1 |
# |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
2 |
# CDDL HEADER START |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
3 |
# |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
4 |
# The contents of this file are subject to the terms of the |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
5 |
# Common Development and Distribution License (the "License"). |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
6 |
# You may not use this file except in compliance with the License. |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
7 |
# |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
8 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
9 |
# or http://www.opensolaris.org/os/licensing. |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
10 |
# See the License for the specific language governing permissions |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
11 |
# and limitations under the License. |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
12 |
# |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
13 |
# When distributing Covered Code, include this CDDL HEADER in each |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
14 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
15 |
# If applicable, add the following below this CDDL HEADER, with the |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
16 |
# fields enclosed by brackets "[]" replaced with your own identifying |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
17 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
18 |
# |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
19 |
# CDDL HEADER END |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
20 |
# |
862
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
21 |
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
22 |
""" |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
23 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
24 |
A/I Database Routines |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
25 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
26 |
""" |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
27 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
28 |
import Queue |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
29 |
from sqlite3 import dbapi2 as sqlite |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
30 |
import threading |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
31 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
32 |
class DB: |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
33 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
34 |
Class to connect to, and look-up entries in the SQLite database |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
35 |
""" |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
36 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
37 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
38 |
def __init__(self, db, commit=False): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
39 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
40 |
Here we initialize the queue the DB thread will run, the DB |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
41 |
thread itself (as well as daemonize it, and start it) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
42 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
43 |
self._requests = Queue.Queue() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
44 |
self._runner = DBthread(db, self._requests, commit) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
45 |
self._runner.setDaemon(True) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
46 |
self._runner.start() |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
47 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
48 |
def getQueue(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
49 |
return self._requests |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
50 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
51 |
def verifyDBStructure(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
52 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
53 |
Ensures reasonable DB schema and columns or else raises a SystemExit |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
54 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
55 |
# get the names of each table in the database |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
56 |
query = DBrequest("SELECT * FROM SQLITE_MASTER") |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
57 |
self._requests.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
58 |
query.waitAns() |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
59 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
60 |
# iterate over each table in the database |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
61 |
for row in iter(query.getResponse()): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
62 |
if "manifests" == row['tbl_name']: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
63 |
break |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
64 |
# if we do not break out we do not have a manifest table |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
65 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
66 |
raise SystemExit(_("Error:\tNo manifests table")) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
67 |
# iterate over each column of the manifests table |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
68 |
query = DBrequest("PRAGMA table_info(manifests)") |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
69 |
self._requests.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
70 |
query.waitAns() |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
71 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
72 |
# gather column names in a list |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
73 |
columns = list() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
74 |
for col in iter(query.getResponse()): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
75 |
columns.append(col['name']) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
76 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
77 |
# ensure we have a name, instance and at least one criteria column |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
78 |
if "name" not in columns or "instance" not in columns or \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
79 |
len(columns) < 3: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
80 |
raise SystemExit(_("Error:\tDatabase columns appear malformed")) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
81 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
82 |
class DBrequest(object): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
83 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
84 |
Class to hold SQL queries and their responses |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
85 |
""" |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
86 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
87 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
88 |
def __init__(self, query, commit=False): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
89 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
90 |
Set the private SQL query and create the event to flag when |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
91 |
the query has returned. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
92 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
93 |
self._sql = str(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
94 |
self._e = threading.Event() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
95 |
self._ans = None |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
96 |
self._committable = commit |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
97 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
98 |
def needsCommit(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
99 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
100 |
Use needsCommit() to determine if the query needs to be committed. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
101 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
102 |
return(self._committable) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
103 |
|
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
104 |
def getSql(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
105 |
""" Use getSql() to access the SQL query string. """ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
106 |
return(self._sql) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
107 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
108 |
def setResponse(self, resp): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
109 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
110 |
Use setResponse() to set the DB response and update the event flag. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
111 |
(Will throw a RuntimeError if already set.) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
112 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
113 |
if self._e.isSet(): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
114 |
raise RuntimeError('Setting already set value') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
115 |
self._ans = resp |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
116 |
self._e.set() |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
117 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
118 |
def getResponse(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
119 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
120 |
Use getResponse() to retrieve the DB response. (Will throw a |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
121 |
NameError if not yet set.) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
122 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
123 |
# ensure the DBrequest's event is set and that _ans is a PySQLite list |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
124 |
if self._e.isSet() and isinstance(self._ans, list): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
125 |
return(self._ans) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
126 |
# is _ans is a string we have an error so handle it |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
127 |
elif self._e.isSet() and isinstance(self._ans, basestring): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
128 |
print self._ans |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
129 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
130 |
print _("Value not yet set") |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
131 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
132 |
def isFinished(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
133 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
134 |
finished() is similar to getResponse() allowing one to determine if the |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
135 |
DBrequest has been handled |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
136 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
137 |
return(self._e.isSet()) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
138 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
139 |
def waitAns(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
140 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
141 |
Use waitAns() to wait for setResponse() to set the event |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
142 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
143 |
# 15 second timeout is arbitrary to prevent possible deadlock |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
144 |
self._e.wait(15) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
145 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
146 |
class DBthread(threading.Thread): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
147 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
148 |
Class to interface with SQLite as the provider is single threaded |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
149 |
""" |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
150 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
151 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
152 |
def __init__(self, db, queue, commit): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
153 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
154 |
Here we create a new thread object, create a DB connection object, keep |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
155 |
track of the DB filename and track the request queue to run on. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
156 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
157 |
threading.Thread.__init__(self) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
158 |
self._con = None |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
159 |
self._dBfile = db |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
160 |
self._requests = queue |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
161 |
self._committable = commit |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
162 |
|
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
163 |
def __del__(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
164 |
""" On destruction, close the DB connection if still open """ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
165 |
if self._con is not None: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
166 |
self._con.close() |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
167 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
168 |
def run(self): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
169 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
170 |
Here we simply iterate over the request queue executing queries and |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
171 |
reporting responses, errors are set as strings for that DBrequest. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
172 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
173 |
if self._committable: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
174 |
# use SQLite IMMEDIATE isolation to prevent any writers changing |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
175 |
# the DB while we are working on it (but don't use EXCLUSIVE since |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
176 |
# there may be persistent readers) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
177 |
self._con = sqlite.connect(self._dBfile, |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
178 |
isolation_level="IMMEDIATE") |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
179 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
180 |
self._con = sqlite.connect(self._dBfile) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
181 |
# allow access by both index and column name |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
182 |
self._con.row_factory = sqlite.Row |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
183 |
self._cursor = self._con.cursor() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
184 |
# iterate over each DBrequest object in the queue |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
185 |
while True: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
186 |
request = self._requests.get() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
187 |
# skip already processed DBrequest's |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
188 |
if request is not None and not request.isFinished(): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
189 |
# if the connection and query are committable then execute the |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
190 |
# query and commit it |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
191 |
if request.needsCommit() and self._committable: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
192 |
try: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
193 |
self._cursor.execute(request.getSql()) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
194 |
self._con.commit() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
195 |
except Exception, e: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
196 |
# save error string for caller to trigger |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
197 |
request.setResponse(_("Database failure with SQL: %s") % |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
198 |
request.getSql() + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
199 |
"\n\t" + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
200 |
_("Error: %s") % str(e)) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
201 |
# ensure we do not continue processing this request |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
202 |
continue |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
203 |
# the query does not need to commit |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
204 |
elif not request.needsCommit(): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
205 |
try: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
206 |
self._cursor.execute(request.getSql()) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
207 |
except Exception, e: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
208 |
# save error string for caller to trigger |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
209 |
request.setResponse(_("Database failure with SQL: %s") % |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
210 |
request.getSql() + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
211 |
"\n\t" + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
212 |
_("Error: %s") % str(e)) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
213 |
# ensure we do not continue processing this request |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
214 |
continue |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
215 |
# the query needs commit access and the connection does not |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
216 |
# support it |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
217 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
218 |
# save error string for caller to trigger |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
219 |
request.setResponse(_("Database failure with SQL: %s") % |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
220 |
request.getSql() + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
221 |
"\n\t" + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
222 |
_("Error: Connection not committable")) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
223 |
# ensure we do not continue processing this request |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
224 |
continue |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
225 |
request.setResponse(self._cursor.fetchall()) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
226 |
# |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
227 |
# Functions below here |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
228 |
# |
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
229 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
230 |
def sanitizeSQL(s): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
231 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
232 |
Use to remove special SQL characters which could cause damage or |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
233 |
unintended results if unexpectedly embedded in an SQL query. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
234 |
This shouldn't be expected to make a SQL injection attack somehow |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
235 |
return valid data, but it should cause it to not be a threat to the DB. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
236 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
237 |
s = s.replace('%', '') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
238 |
s = s.replace('*', '') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
239 |
s = s.replace(',', '') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
240 |
s = s.replace(';', '') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
241 |
s = s.replace('(', '') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
242 |
s = s.replace(')', '') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
243 |
# note: "'" should not get stripped as x'<hex>' is how one flags a hex |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
244 |
# value to SQLite3 so that it returns the string in a string not byte |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
245 |
# format |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
246 |
return str(s) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
247 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
248 |
def numInstances(manifest, queue): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
249 |
""" Run to return the number of instances for manifest in the DB """ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
250 |
query = DBrequest('SELECT COUNT(instance) FROM manifests WHERE ' + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
251 |
'name = "' + manifest + '"') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
252 |
queue.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
253 |
query.waitAns() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
254 |
return(query.getResponse()[0][0]) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
255 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
256 |
def numManifests(queue): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
257 |
""" Run to return the number of manifests in the DB """ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
258 |
query = DBrequest('SELECT COUNT(DISTINCT(name)) FROM manifests') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
259 |
queue.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
260 |
query.waitAns() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
261 |
return(query.getResponse()[0][0]) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
262 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
263 |
def getManNames(queue): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
264 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
265 |
Use to create a generator which provides the names of manifests |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
266 |
in the DB |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
267 |
""" |
862
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
268 |
# Whether the DBrequest should be in or out of the for loop depends on if |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
269 |
# doing one large SQL query and iterating the responses (but holding the |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
270 |
# response in memory) is better than requesting row by row, and |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
271 |
# doing more DB transactions in less memory |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
272 |
for i in range(numManifests(queue)): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
273 |
query = DBrequest('SELECT DISTINCT(name) FROM manifests LIMIT 1 ' + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
274 |
'OFFSET %s' % i) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
275 |
queue.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
276 |
query.waitAns() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
277 |
yield(query.getResponse()[0][0]) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
278 |
return |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
279 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
280 |
def findManifestsByCriteria(queue, criteria): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
281 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
282 |
Returns the manifest names and instance tuple as specified by a list of |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
283 |
criteria tuples (crit, value) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
284 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
285 |
queryStr = "SELECT name, instance FROM manifests WHERE " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
286 |
# warning if there's a massive number of criteria this may pass the SQL |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
287 |
# query length for the database in use |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
288 |
for crit in criteria: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
289 |
queryStr += crit[0] + ' = "' + crit[1l] + '" AND ' |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
290 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
291 |
# cut off extraneous '" AND ' |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
292 |
queryStr = queryStr[:-5] |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
293 |
query = DBrequest(queryStr) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
294 |
queue.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
295 |
query.waitAns() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
296 |
return(query.respnse()) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
297 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
298 |
def getSpecificCriteria(queue, criteria, criteria2=None, |
862
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
299 |
provideManNameAndInstance=False, |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
300 |
excludeManifests=None): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
301 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
302 |
Returns the criteria specified as an iterable list (can provide a second |
862
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
303 |
criteria to return a range (i.e. MIN and MAX memory). The excludeManifests |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
304 |
argument filters out the rows with the manifest names given in that list. |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
305 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
306 |
if provideManNameAndInstance: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
307 |
queryStr = "SELECT name, instance, " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
308 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
309 |
queryStr = "SELECT " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
310 |
if criteria2 is not None: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
311 |
if criteria.endswith('mac'): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
312 |
# for hexadecimal values we need to use the SQL HEX() function to |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
313 |
# properly return a hex value |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
314 |
queryStr += ("HEX(" + criteria + "), HEX(" + criteria2 + |
862
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
315 |
") FROM manifests WHERE (" + criteria + |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
316 |
" IS NOT NULL OR " + criteria2 + " IS NOT NULL)") |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
317 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
318 |
# this is a decimal range value |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
319 |
queryStr += (criteria + ", " + criteria2 + |
862
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
320 |
" FROM manifests WHERE (" + criteria + |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
321 |
" IS NOT NULL OR " + criteria2 + " IS NOT NULL)") |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
322 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
323 |
if criteria.endswith('mac'): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
324 |
# for hexadecimal values we need to use the SQL HEX() function to |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
325 |
# properly return a hex value |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
326 |
queryStr += ("HEX(" + criteria + ") FROM manifests WHERE " + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
327 |
criteria + " IS NOT NULL") |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
328 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
329 |
# this is a decimal range value or string |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
330 |
queryStr += (criteria + " FROM manifests WHERE " + criteria + |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
331 |
" IS NOT NULL") |
862
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
332 |
|
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
333 |
if excludeManifests is not None: |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
334 |
for manifest in excludeManifests: |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
335 |
queryStr += " AND name IS NOT '" + manifest + "'" |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
336 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
337 |
query = DBrequest(queryStr) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
338 |
queue.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
339 |
query.waitAns() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
340 |
return(query.getResponse()) |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
341 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
342 |
def getCriteria(queue, onlyUsed=True, strip=True): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
343 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
344 |
Provides a list of criteria which are used in the DB (i.e. what |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
345 |
needs to be queried on the client). If strip is False, return |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
346 |
exact DB column names not (more) human names. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
347 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
348 |
# first get the names of the columns (criteria) by using the SQL PRAGMA |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
349 |
# statement on the manifest table |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
350 |
query = DBrequest("PRAGMA table_info(manifests)") |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
351 |
queue.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
352 |
query.waitAns() |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
353 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
354 |
columns = list() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
355 |
queryStr = "SELECT " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
356 |
# build a query so we can determine which columns (criteria) are in use |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
357 |
# using the output from the PRAGMA statement |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
358 |
for col in iter(query.getResponse()): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
359 |
colName = col['name'] |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
360 |
# skip the manifest name and instance column as they are not criteria |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
361 |
if (colName == "name"): continue |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
362 |
if (colName == "instance"): continue |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
363 |
# use the SQL COUNT() aggregator to determine if the criteria is in use |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
364 |
queryStr += "COUNT(" + colName + ") as " + colName + ", " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
365 |
# add the column name to the list of columns |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
366 |
columns.append(colName) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
367 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
368 |
# strip extra ", " from the query |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
369 |
queryStr = queryStr[:-2] |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
370 |
queryStr += " FROM manifests" |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
371 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
372 |
if not (onlyUsed or strip): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
373 |
# if we are not gleaning the unused columns and not stripping the |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
374 |
# column names then yield them now |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
375 |
for column in columns: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
376 |
yield str(column) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
377 |
return |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
378 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
379 |
elif not onlyUsed: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
380 |
# if we are only stripping the column names yield the result now |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
381 |
for column in columns: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
382 |
if not column.startswith('MAX'): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
383 |
yield str(column.replace('MIN', '')) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
384 |
return |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
385 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
386 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
387 |
# we need to run the query from above and determine which columns are |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
388 |
# in use we will gather used criteria for the response from the above |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
389 |
# query which is like: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
390 |
# "SELECT COUNT(memMIN), COUNT(memMAX), ... FROM manifests" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
391 |
query = DBrequest(queryStr) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
392 |
queue.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
393 |
query.waitAns() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
394 |
response = dict() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
395 |
# iterate over each column |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
396 |
for colName in columns: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
397 |
# only take columns which have a positive count |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
398 |
if query.getResponse()[0][str(colName)] > 0: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
399 |
if strip: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
400 |
# take only the criteria name, not a qualifier |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
401 |
# (i.e. MIN, MAX) but use both MAX and MIN in case one is |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
402 |
# unused we need ensure we still return the stripped result |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
403 |
if colName.startswith('MAX') or colName.startswith('MIN'): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
404 |
# we have reported this criteria do not repeat it |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
405 |
if response.has_key(colName.replace('MIN', '', 1).\ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
406 |
replace('MAX', '', 1)): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
407 |
continue |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
408 |
colName = colName.replace('MIN', '', 1) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
409 |
colName = colName.replace('MAX', '', 1) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
410 |
response[colName] = 1 |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
411 |
yield str(colName) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
412 |
return |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
413 |
|
862
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
414 |
def isRangeCriteria(queue, name): |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
415 |
""" |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
416 |
Returns True if the criteria 'name' is a range criteria in the DB. |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
417 |
Returns False otherwise. |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
418 |
""" |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
419 |
criteria = getCriteria(queue, onlyUsed=False, strip=False) |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
420 |
for crit in criteria: |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
421 |
if crit.startswith('MIN'): |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
422 |
if name == crit.replace('MIN', ''): |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
423 |
return True |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
424 |
|
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
425 |
return False |
e9f31f2f2f2d
16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents:
649
diff
changeset
|
426 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
427 |
def getManifestCriteria(name, instance, queue, humanOutput=False, |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
428 |
onlyUsed=True): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
429 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
430 |
Returns the criteria (as a subset of used criteria) for a particular |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
431 |
manifest given (human output returns HEX() for mac opposed to byte output) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
432 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
433 |
queryStr = "SELECT " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
434 |
for crit in getCriteria(queue, onlyUsed=onlyUsed, strip=False): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
435 |
if str(crit).endswith('mac') and humanOutput: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
436 |
queryStr += "HEX(" + str(crit) + ") AS " + str(crit) + ", " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
437 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
438 |
queryStr += str(crit) + ", " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
439 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
440 |
if getCriteria(queue, onlyUsed=onlyUsed, strip=False).next() is not None: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
441 |
queryStr = queryStr[:-2] |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
442 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
443 |
raise AssertionError(_("Database contains no criteria!")) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
444 |
queryStr += ' FROM manifests WHERE name = "' + name + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
445 |
'" AND instance = "' + str(instance) + '"' |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
446 |
query = DBrequest(queryStr) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
447 |
queue.put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
448 |
query.waitAns() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
449 |
return query.getResponse()[0] |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
450 |
|
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
451 |
def findManifest(criteria, db): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
452 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
453 |
findManifest() returns a query response provided a criteria |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
454 |
dictionary. (The response may contain 0 or more manifests depending on |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
455 |
criteria.) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
456 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
457 |
# If we didn't get any criteria bail providing no manifest |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
458 |
if len(criteria) == 0: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
459 |
return 0 |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
460 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
461 |
curCount = 0 |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
462 |
queryStr = "SELECT name FROM manifests WHERE " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
463 |
for crit in getCriteria(db.getQueue(), strip=False): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
464 |
prevCount = curCount |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
465 |
queryStr1 = queryStr |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
466 |
try: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
467 |
if crit.startswith("MIN"): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
468 |
if crit.endswith("mac"): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
469 |
# setup a clause like HEX(MINmac) <= HEX(x'F00') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
470 |
queryStr1 += "HEX(" + crit + ") <= HEX(x'" + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
471 |
sanitizeSQL( |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
472 |
criteria[crit.replace('MIN', '',1)]) + "')" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
473 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
474 |
# setup a clause like crit <= value |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
475 |
queryStr1 += crit + " " + "<= " + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
476 |
sanitizeSQL(criteria[crit.replace('MIN', '',1)]) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
477 |
elif crit.startswith("MAX"): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
478 |
if crit.endswith("mac"): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
479 |
# setup a clause like HEX(MINmac) >= HEX(x'F000') |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
480 |
queryStr1 += "HEX(" + crit + ") >= HEX(x'" + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
481 |
sanitizeSQL( |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
482 |
criteria[crit.replace('MAX', '',1)]) + "')" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
483 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
484 |
# setup a clause like crit <= value |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
485 |
queryStr1 += crit + " " + ">= " + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
486 |
sanitizeSQL(criteria[crit.replace('MAX', '',1)]) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
487 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
488 |
# store single values in lower case |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
489 |
# setup a clause like crit = lower(value) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
490 |
queryStr1 += crit + " " + '= LOWER("' + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
491 |
sanitizeSQL(criteria[crit]) + '")' |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
492 |
except KeyError: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
493 |
print _("Missing criteria: %s;returning 0 - oft default.xml") % crit |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
494 |
return 0 |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
495 |
query = DBrequest(queryStr1) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
496 |
db.getQueue().put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
497 |
query.waitAns() |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
498 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
499 |
try: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
500 |
curCount = len(query.getResponse()) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
501 |
except Exception: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
502 |
# we'll not get a response if we were provided a criteria which |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
503 |
# isn't in the DB (we'll generate a DB error); shouldn't happen |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
504 |
# unless getCriteria() is really confused |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
505 |
print _("Bad criteria: %s;returning 0 - oft default.xml") % crit |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
506 |
return 0 |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
507 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
508 |
if len(query.getResponse()) >= 1: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
509 |
queryStr = queryStr1 + " AND " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
510 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
511 |
# criteria reduced effective set to zero (add a NULL criteria |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
512 |
# instead) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
513 |
queryStr += crit + " IS NULL AND " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
514 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
515 |
# remove extraneous " AND " |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
516 |
queryStr = queryStr[:-5] |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
517 |
query = DBrequest(queryStr) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
518 |
db.getQueue().put(query) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
519 |
query.waitAns() |
287
13cbbc65259c
3440 Need webserver for A/I support
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
diff
changeset
|
520 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
521 |
# see if we got one, more or zero manifests back |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
522 |
if len(query.getResponse()) == 1: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
523 |
return query.getResponse()[0]['name'] |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
524 |
elif len(query.getResponse()) > 1: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
525 |
return len(query.getResponse()) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
526 |
# got zero manifests back |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
527 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
528 |
return 0 |
523
9abfbbe9b302
4325 Better syntactic treatment of IP and MAC address AI criteria
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents:
329
diff
changeset
|
529 |
|
9abfbbe9b302
4325 Better syntactic treatment of IP and MAC address AI criteria
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents:
329
diff
changeset
|
530 |
def formatValue(key, value): |
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
531 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
532 |
Format and stringify database values. |
523
9abfbbe9b302
4325 Better syntactic treatment of IP and MAC address AI criteria
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents:
329
diff
changeset
|
533 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
534 |
Args: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
535 |
key: a database criterion key. Starting "MIN" and "MAX" are stripped |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
536 |
off to get the type of datum the key represents. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
537 |
The following user-friendly output formatting is done: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
538 |
- mac addresses have colons added. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
539 |
- IP addresses have dots added. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
540 |
- memory sizes have "MB" added to the end. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
541 |
- All other criteria types are stringified only. |
523
9abfbbe9b302
4325 Better syntactic treatment of IP and MAC address AI criteria
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents:
329
diff
changeset
|
542 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
543 |
value: The raw database value to format and stringify. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
544 |
|
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
545 |
Returns: a nicely-readable string representing the value. If value is none |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
546 |
returns none |
523
9abfbbe9b302
4325 Better syntactic treatment of IP and MAC address AI criteria
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents:
329
diff
changeset
|
547 |
|
649
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
548 |
Raises: N/A |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
549 |
""" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
550 |
key = key.strip() |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
551 |
key = key.replace("MIN", "", 1) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
552 |
key = key.replace("MAX", "", 1) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
553 |
if (key == "mac" and value): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
554 |
# Note: MAC addresses are already strings. |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
555 |
ret = value[0:2] + ":" + value[2:4] + ":" + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
556 |
value[4:6] + ":" + value[6:8] + ":" + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
557 |
value[8:10] + ":" + value[10:12] |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
558 |
elif (key == "ipv4" and value): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
559 |
svalue = "%12.12d" % long(value) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
560 |
ret = svalue[0:3] + "." + svalue[3:6] + "." + \ |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
561 |
svalue[6:9] + "." + svalue[9:12] |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
562 |
elif (key == "mem" and value): |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
563 |
ret = str(value) + " MB" |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
564 |
else: |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
565 |
ret = str(value) |
ba353c37b287
12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents:
523
diff
changeset
|
566 |
return ret |