aboutsummaryrefslogtreecommitdiffstats
path: root/gsxws/comptia.py
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-05-12 22:34:53 +0300
committerFilipp Lepalaan <f@230.to>2013-05-12 22:34:53 +0300
commitaaacaebb861beaf2ef39b6bc54db2d12262e9b0d (patch)
tree2d373fc7d04ab03f87bfe5e4d13f36d6d7bc81a5 /gsxws/comptia.py
parent452005bbb83059913d4c8b7648d9e368936e53da (diff)
downloadpy-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.tar.gz
py-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.tar.bz2
py-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.zip
More speed, more power, less suds, WIP
Diffstat (limited to 'gsxws/comptia.py')
-rw-r--r--gsxws/comptia.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/gsxws/comptia.py b/gsxws/comptia.py
new file mode 100644
index 0000000..f7e7ff7
--- /dev/null
+++ b/gsxws/comptia.py
@@ -0,0 +1,89 @@
+MODIFIERS = (
+ ("A", "Not Applicable"),
+ ("B", "Continuous"),
+ ("C", "Intermittent"),
+ ("D", "Fails After Warm Up"),
+ ("E", "Environmental"),
+ ("F", "Configuration: Peripheral"),
+ ("G", "Damaged"),
+)
+
+GROUPS = (
+ ('0', 'General'),
+ ('1', 'Visual'),
+ ('2', 'Displays'),
+ ('3', 'Mass Storage'),
+ ('4', 'Input Devices'),
+ ('5', 'Boards'),
+ ('6', 'Power'),
+ ('7', 'Printer'),
+ ('8', 'Multi-function Device'),
+ ('9', 'Communication Devices'),
+ ('A', 'Share'),
+ ('B', 'iPhone'),
+ ('E', 'iPod'),
+ ('F', 'iPad'),
+)
+
+
+class CompTIA(object):
+ "Stores and accesses CompTIA codes."
+
+ def __init__(self):
+ """
+ Initialize CompTIA symptoms from JSON file
+ """
+ df = open(os.path.join(os.path.dirname(__file__), 'comptia.json'))
+ self.data = json.load(df)
+
+ def fetch(self):
+ """
+ The CompTIA Codes Lookup API retrieves a list of CompTIA groups and modifiers.
+
+ Here we must resort to raw XML parsing since SUDS throws this:
+ suds.TypeNotFound: Type not found: 'comptiaDescription'
+ when calling CompTIACodes()...
+
+ >>> CompTIA().fetch()
+ {'A': {'972': 'iPod not recognized',...
+ """
+ global COMPTIA_CACHE
+ if COMPTIA_CACHE.get("comptia"):
+ return COMPTIA_CACHE.get("comptia")
+
+ CLIENT.set_options(retxml=True)
+ dt = CLIENT.factory.create("ns3:comptiaCodeLookupRequestType")
+ dt.userSession = SESSION
+
+ try:
+ xml = CLIENT.service.CompTIACodes(dt)
+ except suds.WebFault, e:
+ raise GsxError(fault=e)
+
+ root = ET.fromstring(xml).findall('.//%s' % 'comptiaInfo')[0]
+
+ for el in root.findall(".//comptiaGroup"):
+ group = {}
+ comp_id = el[0].text
+
+ for ci in el.findall('comptiaCodeInfo'):
+ group[ci[0].text] = ci[1].text
+
+ self.data[comp_id] = group
+
+ COMPTIA_CACHE.put("comptia", self.data)
+ return self.data
+
+ def symptoms(self, component=None):
+ """
+ Returns all known CompTIA symptom codes or just the ones
+ belonging to the given component code.
+ """
+ r = dict()
+
+ for g, codes in self.data.items():
+ r[g] = list()
+ for k, v in codes.items():
+ r[g].append((k, v,))
+
+ return r[component] if component else r