From 54331c8677c35449809524154fcde1fed7c84c42 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Mon, 13 May 2013 09:11:45 +0300 Subject: Better imports --- gsxws/__init__.py | 10 ++++++++++ gsxws/comptia.py | 38 +++++++++++++++++++++----------------- gsxws/core.py | 33 +++++++++++++++++---------------- gsxws/orders.py | 7 +++++-- gsxws/returns.py | 7 +++++-- 5 files changed, 58 insertions(+), 37 deletions(-) diff --git a/gsxws/__init__.py b/gsxws/__init__.py index e69de29..0bbc631 100644 --- a/gsxws/__init__.py +++ b/gsxws/__init__.py @@ -0,0 +1,10 @@ +from core import * +from repairs import * +from products import * +from returns import * +from comms import * +from diagnostics import * +from parts import * +from comptia import * +from escalations import * +from lookups import * diff --git a/gsxws/comptia.py b/gsxws/comptia.py index f7e7ff7..8d56fc0 100644 --- a/gsxws/comptia.py +++ b/gsxws/comptia.py @@ -1,3 +1,8 @@ +import os +import json + +from core import GsxObject, GsxError, GsxCache + MODIFIERS = ( ("A", "Not Applicable"), ("B", "Continuous"), @@ -9,32 +14,31 @@ MODIFIERS = ( ) 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'), + ('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): +class CompTIA(GsxObject): "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) + self._data = json.load(df) def fetch(self): """ diff --git a/gsxws/core.py b/gsxws/core.py index c2b0aba..2b4b7be 100644 --- a/gsxws/core.py +++ b/gsxws/core.py @@ -36,11 +36,21 @@ import xml.etree.ElementTree as ET from datetime import date, time, datetime, timedelta -GSX_ENV = "it" -GSX_LANG = "en" -GSX_REGION = "emea" -GSX_LOCALE = "en_XXX" -GSX_SESSION = None +GSX_ENV = "it" +GSX_LANG = "en" +GSX_REGION = "emea" +GSX_LOCALE = "en_XXX" + +GSX_SESSION = None + +GSX_REGIONS = ( + ('002', "Asia/Pacific"), + ('003', "Japan"), + ('004', "Europe"), + ('005', "United States"), + ('006', "Canadia"), + ('007', "Latin America"), +) GSX_TIMEZONES = ( ('GMT', "UTC (Greenwich Mean Time)"), @@ -62,15 +72,6 @@ GSX_TIMEZONES = ( ('NZST', "UTC + 12h (New Zealand Standard Time)"), ) -GSX_REGIONS = ( - ('002', "Asia/Pacific"), - ('003', "Japan"), - ('004', "Europe"), - ('005', "United States"), - ('006', "Canadia"), - ('007', "Latin America"), -) - REGION_CODES = ('apac', 'am', 'la', 'emea',) ENVIRONMENTS = ( @@ -144,11 +145,11 @@ class GsxCache(object): """ shelf = None tmpdir = tempfile.gettempdir() - expires = timedelta(minutes=20) filename = os.path.join(tmpdir, "gsxws.tmp") - def __init__(self, key): + def __init__(self, key, expires=timedelta(minutes=20)): self.key = key + self.expires = expires self.shelf = shelve.open(self.filename, protocol=-1) self.now = datetime.now() diff --git a/gsxws/orders.py b/gsxws/orders.py index 1687931..e097cf6 100644 --- a/gsxws/orders.py +++ b/gsxws/orders.py @@ -1,6 +1,9 @@ -class Order(GsxObject): +from core import GsxObject + + +class StockingOrder(GsxObject): def __init__(self, type='stocking', *args, **kwargs): - super(Order, self).__init__(*args, **kwargs) + super(StockingOrder, self).__init__(*args, **kwargs) self.data['orderLines'] = list() def add_part(self, part_number, quantity): diff --git a/gsxws/returns.py b/gsxws/returns.py index 4584b3e..65d1dae 100644 --- a/gsxws/returns.py +++ b/gsxws/returns.py @@ -1,4 +1,6 @@ -from gsxws import GsxObject +import base64 + +from core import GsxObject, validate RETURN_TYPES = ( (1, "Dead On Arrival"), @@ -38,9 +40,10 @@ CARRIERS = ( ('XYMT', "YAMATO"), ) + class Return(GsxObject): def __init__(self, order_number=None, *args, **kwargs): - super(Returns, self).__init__(*args, **kwargs) + super(Return, self).__init__(*args, **kwargs) if order_number is not None: self.data['returnOrderNumber'] = order_number -- cgit v1.2.3