- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/jython/datastore.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/ippToPsps/jython/datastore.py
r32120 r33415 5 5 import logging 6 6 import sys 7 import re 7 8 from xml.etree.ElementTree import ElementTree, Element, tostring 9 10 from ipptopspsdb import IppToPspsDb 8 11 9 12 ''' … … 16 19 17 20 ''' 18 def __init__(self, logger, doc):21 def __init__(self, logger, config, ippToPspsDb): 19 22 20 23 # setup logger 21 24 self.logger = logger 22 self.doc = doc 23 self.logger.debug("Datastore constructor") 24 25 # open config 26 self.product = doc.find("datastore/product").text 27 self.type = doc.find("datastore/type").text 28 29 self.logger.debug("Using product: '" + self.product + "' and type: '" + self.type + "'") 25 self.config = config 26 self.ippToPspsDb = ippToPspsDb 30 27 31 28 ''' … … 34 31 def publish(self, name, path, file, fileType): 35 32 33 # TODO should handle this better 34 batchID = int(name[1:]) 35 36 36 self.logger.infoPair("Attempting to publish", path + "/" + file) 37 37 tempFile = tempfile.NamedTemporaryFile(mode='w+b') … … 39 39 tempFile.seek(0) 40 40 41 # build dsreg command command41 # build dsreg command 42 42 command = "dsreg --add " + name + "\ 43 -- copy--datapath " + path + "\44 --type " + self. type + "\45 --product " + self. product + "\43 --link --datapath " + path + "\ 44 --type " + self.config.datastoreType + "\ 45 --product " + self.config.datastoreProduct + "\ 46 46 --list " + tempFile.name 47 47 … … 52 52 self.logger.errorPair("Datastore publish", "failed") 53 53 ret = False 54 self.ippToPspsDb.updateLoadedToDatastore(batchID, -1) 54 55 else: 55 56 self.logger.infoPair("Datastore publish", "successful") 56 57 ret = True 58 self.ippToPspsDb.updateLoadedToDatastore(batchID, 1) 57 59 60 tempFile.close() 58 61 59 tempFile.close()60 62 return ret 61 62 63 63 64 ''' 64 65 Removes an item from the datastore 66 67 NB this will return a success if the batch is not found on the datastore 65 68 ''' 66 69 def remove(self, name): 70 71 # TODO should handle this better 72 batchID = int(name[1:]) 67 73 68 74 command = "dsreg \ 69 75 --del " + name + " \ 70 76 --rm \ 71 --product " + self. product77 --product " + self.config.datastoreProduct 72 78 73 p = Popen(command, shell=True, stdout=PIPE )79 p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) 74 80 p.wait() 81 output, errors = p.communicate() 75 82 76 83 if p.returncode != 0: 77 self.logger.errorPair("Datastore removal failed", name) 78 ret = False 84 if re.search("not found in", errors): 85 self.logger.infoPair("Datastore batch not found", name) 86 ret = True 87 self.ippToPspsDb.updateDeletedDatastore(batchID, 1) 88 else: 89 self.logger.infoPair("Datastore removal FAILED", name) 90 ret = False 79 91 else: 92 self.logger.infoPair("Datastore removal successful", name) 80 93 ret = True 81 self. logger.infoPair("Datastore removal successful", name)94 self.ippToPspsDb.updateDeletedDatastore(batchID, 1) 82 95 83 96 return ret
Note:
See TracChangeset
for help on using the changeset viewer.
