Package up2date_client :: Module transaction
[hide private]
[frames] | no frames]

Source Code for Module up2date_client.transaction

  1   
  2  # 
  3  # Client code for Update Agent 
  4  # Copyright (c) 1999--2016 Red Hat, Inc.  Distributed under GPLv2. 
  5  # 
  6  #         Adrian Likins <alikins@redhat.com 
  7  # 
  8  # 
  9  # a couple of classes wrapping up transactions so that we 
 10  #    can share transactions instead of creating new ones all over 
 11  # 
 12   
 13  import rpm 
 14   
 15  read_ts = None 
 16  ts = None 
 17   
 18  # ************* NOTE: ************# 
 19  # for the sake of clarity, the names "added/removed" as used here 
 20  # are indicative of what happened when the original transaction was 
 21  # ran. Aka, if you "up2date foobar" and it updates foobar-1-0 with 
 22  # foobar-2-0, you added foobar-2-0 and removed foobar-1-0 
 23  # 
 24  # The reason I mention this explicitly is the trouble of describing 
 25  # what happens when you rollback the transaction, which is basically 
 26  # the opposite, and leads to plenty of confusion 
 27  # 
 28   
 29   
30 -class TransactionData:
31 # simple data structure designed to transport info 32 # about rpm transactions around
33 - def __init__(self):
34 self.data = {} 35 # a list of tuples of pkg info, and mode ('e', 'i', 'u') 36 # the pkgInfo is tuple of [name, version, release, epoch, arch] 37 # size is never used directly for this, it's here as a place holder 38 # arch is optional, if the server specifies it, go with what 39 # removed packages only need [n,v,r,e,arch] 40 self.data['packages'] = [] 41 # list of flags to set for the transaction 42 self.data['flags'] = [] 43 self.data['vsflags'] = [] 44 self.data['probFilterFlags'] = []
45 46
47 - def display(self):
48 out = "" 49 removed = [] 50 installed = [] 51 updated = [] 52 misc = [] 53 for (pkgInfo, mode) in self.data['packages']: 54 if mode == 'u': 55 updated.append(pkgInfo) 56 elif mode == 'i': 57 installed.append(pkgInfo) 58 elif mode == 'e': 59 removed.append(pkgInfo) 60 else: 61 misc.append(pkgInfo) 62 for pkgInfo in removed: 63 out = out + "\t\t[e] %s-%s-%s:%s\n" % (pkgInfo[0], pkgInfo[1], pkgInfo[2], pkgInfo[3]) 64 for pkgInfo in installed: 65 out = out + "\t\t[i] %s-%s-%s:%s\n" % (pkgInfo[0], pkgInfo[1], pkgInfo[2], pkgInfo[3]) 66 for pkgInfo in updated: 67 out = out + "\t\t[u] %s-%s-%s:%s\n" % (pkgInfo[0], pkgInfo[1], pkgInfo[2], pkgInfo[3]) 68 for pkgInfo in misc: 69 out = out + "\t\t[%s] %s-%s-%s:%s\n" % (pkgInfo[5], pkgInfo[0], pkgInfo[1], 70 pkgInfo[2], pkgInfo[3]) 71 return out
72 73 74 # wrapper/proxy class for rpm.Transaction so we can 75 # instrument it, etc easily
76 -class Up2dateTransaction:
77 - def __init__(self):
78 self.ts = rpm.TransactionSet() 79 self._methods = ['dbMatch', 80 'check', 81 'order', 82 'addErase', 83 'addInstall', 84 'run', 85 'IDTXload', 86 'IDTXglob', 87 'rollback', 88 'pgpImportPubkey', 89 'pgpPrtPkts', 90 'Debug', 91 'setFlags', 92 'setVSFlags', 93 'setProbFilter', 94 'hdrFromFdno'] 95 self.tsflags = []
96
97 - def __getattr__(self, attr):
98 if attr in self._methods: 99 return self.getMethod(attr) 100 else: 101 raise AttributeError(attr)
102
103 - def getMethod(self, method):
104 # in theory, we can override this with 105 # profile/etc info 106 return getattr(self.ts, method)
107 108 # push/pop methods so we dont lose the previous 109 # set value, and we can potentiall debug a bit 110 # easier
111 - def pushVSFlags(self, flags):
112 self.tsflags.append(flags) 113 self.ts.setVSFlags(self.tsflags[-1])
114
115 - def popVSFlags(self):
116 del self.tsflags[-1] 117 self.ts.setVSFlags(self.tsflags[-1])
118
119 -def initReadOnlyTransaction():
120 global read_ts 121 if read_ts == None: 122 read_ts = Up2dateTransaction() 123 # FIXME: replace with macro defination 124 read_ts.pushVSFlags(-1) 125 return read_ts
126