| OLD | NEW |
| 1 # Copyright (c) 2014 The Native Client Authors. All rights reserved. | 1 # Copyright (c) 2014 The Native Client Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 | 6 |
| 7 from naclports.util import Trace, Log, Warn | 7 from naclports.util import Trace, Log, Warn |
| 8 from naclports.error import Error | 8 from naclports.error import Error |
| 9 from naclports import configuration, pkg_info, util | 9 from naclports import configuration, pkg_info, util |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 def __hash__(self): | 72 def __hash__(self): |
| 73 return hash((self.NAME, self.VERSION, self.config)) | 73 return hash((self.NAME, self.VERSION, self.config)) |
| 74 | 74 |
| 75 def __str__(self): | 75 def __str__(self): |
| 76 return '<Package %s %s %s>' % (self.NAME, self.VERSION, self.config) | 76 return '<Package %s %s %s>' % (self.NAME, self.VERSION, self.config) |
| 77 | 77 |
| 78 def InfoString(self): | 78 def InfoString(self): |
| 79 return "'%s' [%s]" % (self.NAME, self.config) | 79 return "'%s' [%s]" % (self.NAME, self.config) |
| 80 | 80 |
| 81 def LogStatus(self, message, suffix=''): |
| 82 util.LogHeading(message, " '%s' [%s] %s" % ( |
| 83 util.Color(self.NAME, 'yellow'), |
| 84 util.Color(self.config, 'blue'), |
| 85 suffix)) |
| 86 |
| 81 def CheckDeps(self, valid_packages): | 87 def CheckDeps(self, valid_packages): |
| 82 for package in self.DEPENDS: | 88 for package in self.DEPENDS: |
| 83 if package not in valid_packages: | 89 if package not in valid_packages: |
| 84 Log('%s: Invalid dependency: %s' % (self.info, package)) | 90 Log('%s: Invalid dependency: %s' % (self.info, package)) |
| 85 return False | 91 return False |
| 86 | 92 |
| 87 for package in self.CONFLICTS: | 93 for package in self.CONFLICTS: |
| 88 if package not in valid_packages: | 94 if package not in valid_packages: |
| 89 Log('%s: Invalid conflict: %s' % (self.info, package)) | 95 Log('%s: Invalid conflict: %s' % (self.info, package)) |
| 90 return False | 96 return False |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 class InstalledPackage(Package): | 112 class InstalledPackage(Package): |
| 107 extra_keys = EXTRA_KEYS | 113 extra_keys = EXTRA_KEYS |
| 108 | 114 |
| 109 def __init__(self, info_file): | 115 def __init__(self, info_file): |
| 110 super(InstalledPackage, self).__init__(info_file) | 116 super(InstalledPackage, self).__init__(info_file) |
| 111 self.config = configuration.Configuration(self.BUILD_ARCH, | 117 self.config = configuration.Configuration(self.BUILD_ARCH, |
| 112 self.BUILD_TOOLCHAIN, | 118 self.BUILD_TOOLCHAIN, |
| 113 self.BUILD_CONFIG == 'debug') | 119 self.BUILD_CONFIG == 'debug') |
| 114 | 120 |
| 115 def Uninstall(self): | 121 def Uninstall(self): |
| 116 Log("Uninstalling %s" % self.InfoString()) | 122 self.LogStatus('Uninstalling') |
| 117 self.DoUninstall() | 123 self.DoUninstall() |
| 118 | 124 |
| 119 def Files(self): | 125 def Files(self): |
| 120 """Yields the list of files currently installed by this package.""" | 126 """Yields the list of files currently installed by this package.""" |
| 121 with open(self.GetListFile()) as f: | 127 with open(self.GetListFile()) as f: |
| 122 for line in f: | 128 for line in f: |
| 123 yield line.strip() | 129 yield line.strip() |
| 124 | 130 |
| 125 def DoUninstall(self): | 131 def DoUninstall(self): |
| 126 with util.InstallLock(self.config): | 132 with util.InstallLock(self.config): |
| (...skipping 21 matching lines...) Expand all Loading... |
| 148 continue | 154 continue |
| 149 yield InstalledPackage(os.path.join(stamp_root, filename)) | 155 yield InstalledPackage(os.path.join(stamp_root, filename)) |
| 150 | 156 |
| 151 | 157 |
| 152 def CreateInstalledPackage(package_name, config=None): | 158 def CreateInstalledPackage(package_name, config=None): |
| 153 stamp_root = util.GetInstallStampRoot(config) | 159 stamp_root = util.GetInstallStampRoot(config) |
| 154 info_file = os.path.join(stamp_root, package_name + '.info') | 160 info_file = os.path.join(stamp_root, package_name + '.info') |
| 155 if not os.path.exists(info_file): | 161 if not os.path.exists(info_file): |
| 156 raise Error('package not installed: %s [%s]' % (package_name, config)) | 162 raise Error('package not installed: %s [%s]' % (package_name, config)) |
| 157 return InstalledPackage(info_file) | 163 return InstalledPackage(info_file) |
| OLD | NEW |