2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """UpgradeTable class is used in Portage package upgrade process."""
8 from chromite.lib import table
10 class UpgradeTable(table.Table):
11 """Class to represent upgrade data in memory, can be written to csv."""
13 # Column names. Note that 'ARCH' is replaced with a real arch name when
14 # these are accessed as attributes off an UpgradeTable object.
15 COL_PACKAGE = 'Package'
17 COL_OVERLAY = 'Overlay'
18 COL_CURRENT_VER = 'Current ARCH Version'
19 COL_STABLE_UPSTREAM_VER = 'Stable Upstream ARCH Version'
20 COL_LATEST_UPSTREAM_VER = 'Latest Upstream ARCH Version'
21 COL_STATE = 'State On ARCH'
22 COL_DEPENDS_ON = 'Dependencies On ARCH'
23 COL_USED_BY = 'Required By On ARCH'
24 COL_TARGET = 'Root Target'
25 COL_UPGRADED = 'Upgraded ARCH Version'
27 # COL_STATE values should be one of the following:
28 STATE_UNKNOWN = 'unknown'
29 STATE_LOCAL_ONLY = 'local only'
30 STATE_UPSTREAM_ONLY = 'upstream only'
31 STATE_NEEDS_UPGRADE = 'needs upgrade'
32 STATE_PATCHED = 'patched locally'
33 STATE_DUPLICATED = 'duplicated locally'
34 STATE_NEEDS_UPGRADE_AND_PATCHED = 'needs upgrade and patched locally'
35 STATE_NEEDS_UPGRADE_AND_DUPLICATED = 'needs upgrade and duplicated locally'
36 STATE_CURRENT = 'current'
39 def GetColumnName(col, arch=None):
40 """Translate from generic column name to specific given |arch|."""
42 return col.replace('ARCH', arch)
45 def __init__(self, arch, upgrade=False, name=None):
48 # These constants serve two roles, for csv output:
49 # 1) Restrict which column names are valid.
50 # 2) Specify the order of those columns.
51 columns = [self.COL_PACKAGE,
55 self.COL_STABLE_UPSTREAM_VER,
56 self.COL_LATEST_UPSTREAM_VER,
64 columns.append(self.COL_UPGRADED)
66 table.Table.__init__(self, columns, name=name)
68 def __getattribute__(self, name):
69 """When accessing self.COL_*, substitute ARCH name."""
70 if name.startswith('COL_'):
71 text = getattr(UpgradeTable, name)
72 return UpgradeTable.GetColumnName(text, arch=self._arch)
74 return object.__getattribute__(self, name)
77 """Get the architecture associated with this UpgradeTable."""