aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgsxws.py184
1 files changed, 100 insertions, 84 deletions
diff --git a/gsxws.py b/gsxws.py
index 8afd359..256d53b 100755
--- a/gsxws.py
+++ b/gsxws.py
@@ -5,24 +5,24 @@
"""
Copyright (c) 2013, Filipp Lepalaan All rights reserved.
-Redistribution and use in source and binary forms, with or without modification,
+Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
-- Redistributions of source code must retain the above copyright notice,
+- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-- Redistributions in binary form must reproduce the above copyright notice,
-this list of conditions and the following disclaimer in the documentation
+- Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
@@ -32,7 +32,6 @@ import json
import suds
import base64
import urllib
-import urlparse
import hashlib
import tempfile
@@ -84,6 +83,7 @@ ENVIRONMENTS = (
('it', "Testing"),
)
+
def validate(value, what=None):
"""
Tries to guess the meaning of value or validate that
@@ -95,29 +95,31 @@ def validate(value, what=None):
raise ValueError('%s is not valid input')
rex = {
- 'partNumber' : r'^([A-Z]{1,2})?\d{3}\-?(\d{4}|[A-Z]{2})(/[A-Z])?$',
- 'serialNumber' : r'^[A-Z0-9]{11,12}$',
- 'eeeCode' : r'^[A-Z0-9]{3,4}$',
- 'returnOrder' : r'^7\d{9}$',
- 'repairNumber' : r'^\d{12}$',
- 'dispatchId' : r'^G\d{9}$',
- 'alternateDeviceId' : r'^\d{15}$',
+ 'partNumber': r'^([A-Z]{1,2})?\d{3}\-?(\d{4}|[A-Z]{2})(/[A-Z])?$',
+ 'serialNumber': r'^[A-Z0-9]{11,12}$',
+ 'eeeCode': r'^[A-Z0-9]{3,4}$',
+ 'returnOrder': r'^7\d{9}$',
+ 'repairNumber': r'^\d{12}$',
+ 'dispatchId': r'^G\d{9}$',
+ 'alternateDeviceId': r'^\d{15}$',
'diagnosticEventNumber': r'^\d{23}$',
- 'productName' : r'^i?Mac',
+ 'productName': r'^i?Mac',
}
-
+
for k, v in rex.items():
if re.match(v, value):
result = k
return (result == what) if what else result
+
def get_format(locale=LOCALE):
df = open(os.path.join(os.path.dirname(__file__), 'langs.json'), 'r')
data = json.load(df)
return data[locale]
+
class GsxObject(object):
"""
The thing that gets sent to and from GSX
@@ -127,7 +129,7 @@ class GsxObject(object):
method = 'Authenticate' # The SOAP method to call on the GSX server
def __init__(self, *args, **kwargs):
-
+
formats = get_format()
# native types are not welcome here :)
@@ -138,7 +140,7 @@ class GsxObject(object):
kwargs[k] = v.strftime(formats['tf'])
if isinstance(v, bool):
kwargs[k] = 'Y' if v else 'N'
-
+
self.data = kwargs
if CLIENT is not None:
@@ -489,21 +491,22 @@ class Diagnostics(GsxObject):
result = CLIENT.service.FetchIOSDiagnostic(dt)
except suds.WebFault, e:
raise GsxError(fault=e)
-
+
root = ET.fromstring(result).findall('*//%s' % 'FetchIOSDiagnosticResponse')[0]
else:
dt = self._make_type('ns3:fetchRepairDiagnosticRequestType')
dt.lookupRequestData = self.data
-
+
try:
result = CLIENT.service.FetchRepairDiagnostic(dt)
except suds.WebFault, e:
raise GsxError(fault=e)
root = ET.fromstring(result).findall('*//%s' % 'FetchRepairDiagnosticResponse')[0]
-
+
return GsxResponse.Process(root)
+
class Order(GsxObject):
def __init__(self, type='stocking', *args, **kwargs):
super(Order, self).__init__(*args, **kwargs)
@@ -512,7 +515,7 @@ class Order(GsxObject):
def add_part(self, part_number, quantity):
self.data['orderLines'].append({
'partNumber': part_number, 'quantity': quantity
- })
+ })
def submit(self):
dt = CLIENT.factory.create('ns1:createStockingOrderRequestType')
@@ -525,27 +528,28 @@ class Order(GsxObject):
except suds.WebFault, e:
raise GsxError(fault=e)
+
class Returns(GsxObject):
def __init__(self, order_number=None, *args, **kwargs):
super(Returns, self).__init__(*args, **kwargs)
-
+
if order_number is not None:
self.data['returnOrderNumber'] = order_number
def get_pending(self):
"""
- The Parts Pending Return API returns a list of all parts that
- are pending for return, based on the search criteria.
+ The Parts Pending Return API returns a list of all parts that
+ are pending for return, based on the search criteria.
"""
dt = self._make_type('ns1:partsPendingReturnRequestType')
dt.repairData = self.data
-
+
return self.submit('PartsPendingReturn', dt, 'partsPendingResponse')
def get_report(self):
"""
- The Return Report API returns a list of all parts that are returned
- or pending for return, based on the search criteria.
+ The Return Report API returns a list of all parts that are returned
+ or pending for return, based on the search criteria.
"""
dt = self._make_type('ns1:returnReportRequestType')
dt.returnRequestData = self.data
@@ -581,9 +585,14 @@ class Returns(GsxObject):
el = ET.fromstring(result).findall('*//%s' % 'returnLabelData')[0]
for r in el.iter():
+
k, v = r.tag, r.text
+
if k in ['packingList', 'proformaFileData', 'returnLabelFileData']:
v = base64.b64decode(v)
+ of = tempfile.NamedTemporaryFile(suffix=".pdf", delete=False)
+ of.write(v)
+ v = of.name
setattr(rd, k, v)
@@ -591,32 +600,33 @@ class Returns(GsxObject):
def get_proforma(self):
"""
- The View Bulk Return Proforma API allows you to view
+ The View Bulk Return Proforma API allows you to view
the proforma label for a given Bulk Return Id.
- You can create a parts bulk return
- by using the Register Parts for Bulk Return API.
+ You can create a parts bulk return
+ by using the Register Parts for Bulk Return API.
"""
pass
def register_parts(self, parts):
"""
- The Register Parts for Bulk Return API creates a bulk return for
+ The Register Parts for Bulk Return API creates a bulk return for
the registered parts.
The API returns the Bulk Return Id with the packing list.
"""
- dt = self._make_type('ns1:registerPartsForBulkReturnRequestType')
+ dt = self._make_type("ns1:registerPartsForBulkReturnRequestType")
self.data['bulkReturnOrder'] = parts
dt.bulkPartsRegistrationRequest = self.data
- result = self.submit('RegisterPartsForBulkReturn', dt, 'bulkPartsRegistrationData')
+ result = self.submit("RegisterPartsForBulkReturn", dt, "bulkPartsRegistrationData")
pdf = base64.b64decode(result.packingList)
- of = tempfile.NamedTemporaryFile(suffix='.pdf', delete=False)
+ of = tempfile.NamedTemporaryFile(suffix=".pdf", delete=False)
of.write(pdf)
result.packingList = of.name
return result
+
class Part(GsxObject):
def lookup(self):
lookup = Lookup(**self.data)
@@ -638,6 +648,7 @@ class Part(GsxObject):
except Exception, e:
raise GsxError('Failed to fetch part image: %s' % e)
+
class Escalation(GsxObject):
def create(self):
"""
@@ -657,14 +668,15 @@ class Escalation(GsxObject):
dt.escalationRequest = self.data
return self.submit("UpdateGeneralEscalation", dt, "escalationConfirmation")
+
class Repair(GsxObject):
-
+
dt = 'ns6:repairLookupInfoType'
request_dt = 'ns1:repairLookupRequestType'
def __init__(self, number=None, *args, **kwargs):
super(Repair, self).__init__(*args, **kwargs)
-
+
if number is not None:
self.data['repairConfirmationNumber'] = number
@@ -677,11 +689,11 @@ class Repair(GsxObject):
dt.repairData = self.data
return self.submit('CreateCarryInRepair', dt, 'repairConfirmation')
-
+
def create_cnd(self):
"""
- The Create CND Repair API allows Service Providers to create a repair
- whenever the reported issue cannot be duplicated, and the repair
+ The Create CND Repair API allows Service Providers to create a repair
+ whenever the reported issue cannot be duplicated, and the repair
requires no parts replacement.
N01 Unable to Replicate
N02 Software Update/Issue
@@ -696,10 +708,10 @@ class Repair(GsxObject):
def update_carryin(self, newdata):
"""
Description
- The Update Carry-In Repair API allows the service providers
- to update the existing open carry-in repairs.
- This API assists in addition/deletion of parts and addition of notes
- to a repair. On successful update, the repair confirmation number and
+ The Update Carry-In Repair API allows the service providers
+ to update the existing open carry-in repairs.
+ This API assists in addition/deletion of parts and addition of notes
+ to a repair. On successful update, the repair confirmation number and
quote for any newly added parts would be returned.
In case of any validation error or unsuccessful update, a fault code is issued.
@@ -710,7 +722,7 @@ class Repair(GsxObject):
RFPU Ready for Pickup
"""
dt = self._make_type('ns1:updateCarryInRequestType')
-
+
# Merge old and new data (old data should have Dispatch ID)
dt.repairData = dict(self.data.items() + newdata.items())
@@ -719,31 +731,31 @@ class Repair(GsxObject):
def update_sn(self, parts):
"""
Description
- The Update Serial Number API allows the service providers to
- update the module serial numbers.
+ The Update Serial Number API allows the service providers to
+ update the module serial numbers.
Context:
- The API is not applicable for whole unit replacement
+ The API is not applicable for whole unit replacement
serial number entry (see KGB serial update).
"""
dt = self._make_type('ns1:updateSerialNumberRequestType')
repairData = {'repairConfirmationNumber': self.data.get('dispatchId')}
repairData['partInfo'] = parts
dt.repairData = repairData
-
+
return self.submit('UpdateSerialNumber', dt, 'repairConfirmation')
def update_kgb_sn(self, sn):
"""
Description:
- The KGB Serial Number Update API is always to be used on
- whole unit repairs that are in a released state.
- This API allows users to provide the KGB serial number for the
- whole unit exchange repairs. It also checks for the privilege
- to create/ update whole unit exchange repairs
+ The KGB Serial Number Update API is always to be used on
+ whole unit repairs that are in a released state.
+ This API allows users to provide the KGB serial number for the
+ whole unit exchange repairs. It also checks for the privilege
+ to create/ update whole unit exchange repairs
before updating the whole unit exchange repair.
Context:
- The API is to be used on whole unit repairs that are in a released state.
+ The API is to be used on whole unit repairs that are in a released state.
This API can be invoked only after carry-in repair creation API.
"""
@@ -758,7 +770,7 @@ class Repair(GsxObject):
result = CLIENT.service.KGBSerialNumberUpdate(dt)
except suds.WebFault, e:
raise GsxError(fault=e)
-
+
root = ET.fromstring(result).findall('*//%s' % 'UpdateKGBSerialNumberResponse')
return GsxResponse.Process(root[0])
@@ -767,14 +779,14 @@ class Repair(GsxObject):
Description:
The Repair Lookup API mimics the front-end repair search functionality.
It fetches up to 2500 repairs in a given criteria.
- Subsequently, the extended Repair Status API can be used
- to retrieve more details of the repair.
+ Subsequently, the extended Repair Status API can be used
+ to retrieve more details of the repair.
"""
return Lookup(**self.data).repairs()
def mark_complete(self, numbers=None):
"""
- The Mark Repair Complete API allows a single or an array of
+ The Mark Repair Complete API allows a single or an array of
repair confirmation numbers to be submitted to GSX to be marked as complete.
"""
dt = self._make_type('ns1:markRepairCompleteRequestType')
@@ -788,9 +800,9 @@ class Repair(GsxObject):
def delete(self):
"""
- The Delete Repair API allows the service providers to delete
- the existing GSX Initiated Carry-In, Return Before Replace & Onsite repairs
- which are in Declined-Rejected By TSPS Approver state,
+ The Delete Repair API allows the service providers to delete
+ the existing GSX Initiated Carry-In, Return Before Replace & Onsite repairs
+ which are in Declined-Rejected By TSPS Approver state,
that do not have an active repair id.
"""
pass
@@ -811,8 +823,8 @@ class Repair(GsxObject):
def get_details(self):
"""
- The Repair Details API includes the shipment information
- similar to the Repair Lookup API.
+ The Repair Details API includes the shipment information
+ similar to the Repair Lookup API.
"""
dt = self._make_type('ns0:repairDetailsRequestType')
dt.dispatchId = self.data['dispatchId']
@@ -824,32 +836,34 @@ class Repair(GsxObject):
try:
url = re.sub('<<TRKNO>>', p.deliveryTrackingNumber, p.carrierURL)
details.partsInfo[i].carrierURL = url
- except AttributeError, e:
+ except AttributeError:
pass
return details
+
class Communication(GsxObject):
def get_content():
"""
The Fetch Communication Content API allows the service providers/depot/carriers
- to fetch the communication content by article ID from the service news channel.
+ to fetch the communication content by article ID from the service news channel.
"""
def get_articles():
"""
The Fetch Communication Articles API allows the service partners
- to fetch all the active communication message IDs.
+ to fetch all the active communication message IDs.
"""
+
class Product(GsxObject):
-
+
dt = 'ns7:unitDetailType'
def __init__(self, serialNumber, *args, **kwargs):
super(Product, self).__init__(*args, **kwargs)
self.serialNumber = serialNumber
-
+
if SESSION:
self.dt.serialNumber = serialNumber
self.lookup = Lookup(serialNumber=self.serialNumber)
@@ -878,11 +892,10 @@ class Product(GsxObject):
result = self.submit("WarrantyStatus", dt, "warrantyDetailInfo")
return self._process(result)
-
def get_activation(self):
"""
- The Fetch iOS Activation Details API is used to
- fetch activation details of iOS Devices.
+ The Fetch iOS Activation Details API is used to
+ fetch activation details of iOS Devices.
"""
dt = self._make_type('ns3:fetchIOSActivationDetailsRequestType')
dt.serialNumber = self.serialNumber
@@ -908,6 +921,7 @@ class Product(GsxObject):
except Exception, e:
raise GsxError('Failed to fetch product image: %s' % e)
+
def init(env='ut', region='emea'):
"""
Initialize the SOAP client
@@ -931,12 +945,13 @@ def init(env='ut', region='emea'):
cache = CLIENT.options.cache
cache.setduration(weeks=1)
+
def connect(
user_id,
password,
- sold_to,
+ sold_to,
language='en',
- timezone='CEST',
+ timezone='CEST',
environment='ut',
region='emea',
locale=LOCALE):
@@ -944,7 +959,7 @@ def connect(
Establishes connection with GSX Web Services.
Returns the session ID of the new connection.
"""
-
+
global CACHE
global LOCALE
global SESSION
@@ -980,6 +995,7 @@ def connect(
except suds.WebFault, e:
raise GsxError(fault=e)
+
def logout():
CLIENT.service.Logout()
@@ -987,7 +1003,7 @@ if __name__ == '__main__':
import sys
import json
import argparse
-
+
parser = argparse.ArgumentParser(description='Communicate with GSX Web Services')
parser.add_argument('user_id')
@@ -997,5 +1013,5 @@ if __name__ == '__main__':
parser.add_argument('--timezone', default='CEST')
parser.add_argument('--environment', default='pr')
parser.add_argument('--region', default='emea')
-
+
args = parser.parse_args()
> 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648