def _verify(self): """Check if the installation is valid. A valid installation provides all expected libraries and commands. Subclasses may wish to perform additional checks. Returns: True: If the installation at self.install_prefix is valid. Raises: SoftwarePackageError: Describs why the installation is invalid. """ LOGGER.debug("Checking %s installation at '%s' targeting %s %s", self.name, self.install_prefix, self.target_arch, self.target_os) if not os.path.exists(self.install_prefix): raise SoftwarePackageError("'%s' does not exist" % self.install_prefix) for cmd in self.commands: path = os.path.join(self.bin_path, cmd) if not os.path.exists(path): raise SoftwarePackageError("'%s' is missing" % path) if not os.access(path, os.X_OK): raise SoftwarePackageError("'%s' exists but is not executable" % path) for lib in self.libraries: path = os.path.join(self.lib_path, lib) if not util.file_accessible(path): raise SoftwarePackageError("'%s' is not accessible" % path) LOGGER.debug("%s installation at '%s' is valid", self.name, self.install_prefix) return True
def __call__(self, parser, namespace, flag, unused_option_string=None): """Sets the `self.dest` attribute in `namespace` to the parsed value of `flag`. If `flag` parses to a boolean True value then the attribute value is 'download'. If `flag` parses to a boolean False value then the attribute value is ``None``. Otherwise the attribute value is the value of `flag`. Args: parser (str): Argument parser object this group belongs to. namespace (object): Namespace to receive parsed value via setattr. flag (str): Value parsed from the command line. """ try: flag_as_bool = util.parse_bool(flag, additional_true=['download']) except TypeError: if util.is_url(flag): value = flag else: value = os.path.abspath(os.path.expanduser(flag)) if not (os.path.isdir(value) or util.file_accessible(value)): raise argparse.ArgumentError(self, "Boolean, 'download', valid path, or URL required: %s" % value) else: if flag_as_bool == True: value = 'download' elif flag_as_bool == False: value = None setattr(namespace, self.dest, value)
def connect_database(self, *args, **kwargs): """Open the database for reading and writing.""" if self._database is None: dbfile = os.path.join(self.prefix, self.name + ".json") try: self._database = tinydb.TinyDB(dbfile, storage=_JsonFileStorage) except IOError as err: raise StorageError( "Failed to access %s database '%s': %s" % (self.name, dbfile, err), "Check that you have `write` access", ) if not util.file_accessible(dbfile): raise StorageError( "Database file '%s' exists but cannot be read." % dbfile, "Check that you have `read` access" ) LOGGER.debug("Initialized %s database '%s'", self.name, dbfile)