2be28a9f02ec42063286539a9621017442e4d95c
[platform/framework/web/crosswalk.git] / src / third_party / chromite / lib / upgrade_table.py
1 #!/usr/bin/python
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.
5
6 """UpgradeTable class is used in Portage package upgrade process."""
7
8 from chromite.lib import table
9
10 class UpgradeTable(table.Table):
11   """Class to represent upgrade data in memory, can be written to csv."""
12
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'
16   COL_SLOT = 'Slot'
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'
26
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'
37
38   @staticmethod
39   def GetColumnName(col, arch=None):
40     """Translate from generic column name to specific given |arch|."""
41     if arch:
42       return col.replace('ARCH', arch)
43     return col
44
45   def __init__(self, arch, upgrade=False, name=None):
46     self._arch = arch
47
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,
52                self.COL_SLOT,
53                self.COL_OVERLAY,
54                self.COL_CURRENT_VER,
55                self.COL_STABLE_UPSTREAM_VER,
56                self.COL_LATEST_UPSTREAM_VER,
57                self.COL_STATE,
58                self.COL_DEPENDS_ON,
59                self.COL_USED_BY,
60                self.COL_TARGET,
61                ]
62
63     if upgrade:
64       columns.append(self.COL_UPGRADED)
65
66     table.Table.__init__(self, columns, name=name)
67
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)
73     else:
74       return object.__getattribute__(self, name)
75
76   def GetArch(self):
77     """Get the architecture associated with this UpgradeTable."""
78     return self._arch