Package conary :: Module conarycfg
[hide private]
[frames] | no frames]

Source Code for Module conary.conarycfg

   1  # Copyright (c) 2004-2008 rPath, Inc. 
   2  # 
   3  # This program is distributed under the terms of the Common Public License, 
   4  # version 1.0. A copy of this license should have been distributed with this 
   5  # source file in a file called LICENSE. If it is not present, the license 
   6  # is always available at http://www.rpath.com/permanent/licenses/CPL-1.0. 
   7  # 
   8  # This program is distributed in the hope that it will be useful, but 
   9  # without any warranty; without even the implied warranty of merchantability 
  10  # or fitness for a particular purpose. See the Common Public License for 
  11  # full details. 
  12  # 
  13  """ 
  14  Implements conaryrc handling. 
  15  """ 
  16  import fnmatch 
  17  import os 
  18  import sys 
  19  import xml 
  20  import re 
  21  import traceback 
  22  import pwd 
  23   
  24  from conary.deps import deps, arch 
  25  from conary.lib import util 
  26  from conary.lib.cfg import * 
  27  from conary import errors 
  28  from conary import versions 
  29  from conary import flavorcfg 
  30   
  31  # ----------- conary specific types 
  32   
33 -class ServerGlobList(list):
34 35 multipleMatches = False 36
37 - def find(self, server):
38 l = [] 39 for (serverGlob, item) in ServerGlobList.__iter__(self): 40 # this is case insensitve, which is perfect for hostnames 41 if fnmatch.fnmatch(server, serverGlob): 42 if not self.multipleMatches: 43 return item 44 l.append(item) 45 46 if not self.multipleMatches: 47 return None 48 49 return l
50
51 - def _fncmp(self, a, b):
52 # Comparison function 53 # Equal elements 54 if a[0] == b[0]: 55 return 0 56 if fnmatch.fnmatch(a[0], b[0]): 57 return -1 58 return 1
59
60 - def extend(self, itemList):
61 # Look for the first item which globs to this, and insert the new 62 # item before it. That makes sure find always matches on the 63 # most-specific instance 64 for newItem in reversed(itemList): 65 self.append(newItem)
66
67 - def extendSort(self, itemList):
68 """Extend the current list with the new items, categorizing them and 69 eliminating duplicates""" 70 nlist = sorted(self + [ x for x in reversed(itemList)], self._fncmp) 71 # Walk the list, remove duplicates 72 del self[:] 73 74 lasti = None 75 for ent in nlist: 76 if lasti is not None and lasti[0] == ent[0]: 77 self[-1] = ent 78 else: 79 list.append(self, ent) 80 lasti = ent
81
82 - def append(self, newItem):
83 location = None 84 removeOld = False 85 for i, (serverGlob, info) in enumerate(ServerGlobList.__iter__(self)): 86 if fnmatch.fnmatch(newItem[0], serverGlob): 87 if not self.multipleMatches and serverGlob == newItem[0]: 88 removeOld = True 89 location = i 90 break 91 92 if location is None: 93 list.append(self, newItem) 94 elif removeOld: 95 self[location] = newItem 96 else: 97 self.insert(location, newItem)
98
99 -class UserInformation(ServerGlobList):
100
101 - def __iter__(self):
102 for x in ServerGlobList.__iter__(self): 103 yield (x[0], x[1][0], x[1][1])
104
105 - def addServerGlob(self, *args):
106 # handle (glob, name, passwd) and transform to (glob, (name, passwd))a 107 if len(args) == 3: 108 args = args[0], (args[1], args[2]) 109 ServerGlobList.append(self, args)
110
111 - def addServerGlobs(self, globList):
112 ServerGlobList.extendSort(self, globList)
113
114 - def extend(self, other):
115 for item in other: 116 self.addServerGlob(*item)
117
118 - def append(self, item):
119 self.addServerGlob(*item)
120
121 - def remove(self, item):
122 if len(item) == 3: 123 item = (item[0], (item[1], item[2])) 124 ServerGlobList.remove(self, item)
125
126 - def insert(self, pos, item):
127 if len(item) == 3: 128 item = (item[0], (item[1], item[2])) 129 ServerGlobList.insert(self, pos, item)
130
131 - def __init__(self, initVal = None):