def search_pick_node(search_query, api): """ Perform node search for `search_query` with `api`, lets the user pick interactivly if there are multiple nodes returned Throws LookupError if can't find a matching node """ nodes = [node for node in chef.Search('node', search_query, api=api)] node = None # no nodes match the search if not nodes: raise exceptions.LookupError("Can't find a node matching %s" % (search_query,)) # more than one node matched the search. let the user choose one elif len(nodes) > 1: # sort the results before displaying them nodes.sort(lambda a,b: cmp(a.object.name.lower(), b.object.name.lower())) print '%d nodes matched your query:' % (len(nodes),) for i, current_node in enumerate(nodes): print "\t%d. %s" % (i+1, current_node.object.name,) while not node: selected_node = raw_input('Please select one: ') if not selected_node.isdigit() or not 1 <= int(selected_node) <= len(nodes): print 'Invalid selection. Please choose a number between 1 and %d' % (len(nodes),) else: node = nodes[int(selected_node) - 1] print # only one result. that's our node. else: node = nodes[0] return node
def get_distro_actions(name, version, logger): name_and_version = name + ":" + version if name_and_version in DistroMap: return DistroMap[name_and_version](logger) elif name in DistroMap: return DistroMap[name](logger) raise exceptions.LookupError('{0} is not a supported distro'.format(name_and_version))
def get_mail_envelope(self, uid): # SLOOOW #print >>sys.stderr, "get_mail_envelope UID", uid items = None if self.current_directory_contents is not None and uid in self.current_directory_contents: items_cachetime, items = self.current_directory_contents[ uid] # [x for x in self.current_directory_contents if x[lisp.symbol("UID")] == uid] if time.time() - items_cachetime >= timeout.timeout: # too old items = None #items = None # FIXME for i in range(3): if items is None or items == []: # FIXME the latter is weird... and not necessary anymore status, items = self.connection.uid( "FETCH", uid, '(UID ENVELOPE RFC822.SIZE FLAGS)') #f = file("/tmp/uid-%s" % uid, "w") #import pickle #pickle.dump(items, f) # FIXME FIXME #f.close() items = [x for x in parse_items(items, True)] if items == []: # weird, give it some time time.sleep(1) else: items = items[0] break if items == []: # not found raise exceptions.LookupError( "message with UID %s not found in mailbox \"%s\"" % (uid, self.current_directory)) #print >>sys.stderr, "items ENV", items uid = items[lisp.symbol("UID")] size = items[lisp.symbol("RFC822.SIZE")] envelope = items[lisp.symbol("ENVELOPE")] flags = items[lisp.symbol("FLAGS")] """[ 'Wed, 10 Jan 2007 18:16:22 +0200', 'Some subject', [['Long, Name', [], 'Silvio.Ziegelwanger', 'fabalabs.org']], [['Long, Name', [], 'Long.Name', 'fabalabs.org']], [['Long, Name', [], 'Long.Name', 'fabalabs.org']], [['Milosavljevic, Danny', [], 'Danny.Milosavljevic', 'fabasoft.com'], ['Pesendorfer, Klaus', [], 'Klaus.Pesendorfer', 'fabasoft.com']], [], [], [], '<*****@*****.**>' ]""" date, subject, from_, sender, reply_to, to_, cc, bcc, in_reply_to, message_id = envelope[: 10] date = from_internaldate(date) return uid, flags, size, date, subject, from_, sender, reply_to, to_, cc, bcc, in_reply_to, message_id
def get_time_interpolation_files(self, prop, grid, attime): (file0, tprop0), (file1, tprop1) = self.get_interpolation_bracket( prop, grid, attime) (zfile0, tz0), (zfile1, tz1) = self.get_interpolation_bracket( "z", grid, attime) # sea level elevation if (tprop0 != tz0) or (tprop1 != tz1): raise exceptions.LookupError( "(prop,z) frames does not match time wise: %d vs %d ; %d vs %d" % (tz0, tprop0, tz1, tprop1)) # --- compute relative weigths for left/right bracket --- dt = tprop1 - tprop0 tseek = _create_time_hash(attime) w0 = (tprop1 - tseek) / dt w1 = 1.0 - w0 return (file0, zfile0, w0), (file1, zfile1, w1)
def get_interpolation_bracket(self, prop, grid, attime): tseek = _create_time_hash(attime) try: i1 = searchsorted(self.datasets[prop][grid][0], tseek) except: print tseek print self.datasets[prop][grid][0] raise exceptions.LookupError( "searchsorted failed for %s in %s for %s" % (prop, grid, ` attime `)) nt = len(self.datasets[prop][grid][1]) if nt < 2: raise exceptions.LookupError( "too few fields for %s in %s to time interpolate" % (prop, grid)) if i1 >= nt: raise exceptions.ValueError("i1 >= nt", attime) i0 = i1 - 1 if i0 < 0: raise exceptions.ValueError("i0<0", attime) # --- we've identified the proper time bracket --- ths = self.datasets[prop][grid][0] fnames = self.datasets[prop][grid][1] return (fnames[i0], ths[i0]), (fnames[i1], ths[i1])
+ except LookupError: """ fall back """ pass @@ -395,7 +394,7 @@ enc2 = self._getContentEncoding( change.path, change.revision ) - except exceptions.LookupError: + except LookupError: """ fall back """ pass @@ -423,7 +422,6 @@ The specified encoding is not implemented or no encoding was specified """ - from encodings import exceptions # first try the svn:mime-type enc = self.getEncodingFromMimeType(path, revision) @@ -461,7 +459,7 @@ codecs.lookup(enc) return enc - raise exceptions.LookupError("No Encoding configured") + raise LookupError("No Encoding configured") def getEncodingFromMimeType(self, path, revision):