References:
        http://www.cyberciti.biz/faq/find-out-if-package-is-installed-in-linux/
760270
def check_installed_debian(pkgname):
    
    import utool as ut
    #pkgname = 'espeak'
    #pkgname = 'sudo'
    #ut.cmd('hash ' + pkgname + ' 2>/dev/null')
    tup = ut.cmd('hash ' + pkgname + ' 2>/dev/null', quiet=True, pad_stdout=False)
    out, err, ret = tup
    is_installed = (ret == 0)
    return is_installed
279678
def check_license(package_info, *args):
    
    classifiers = package_info.get('classifiers')
    reason = "No License"
    result = False

    if len([c for c in classifiers if c.startswith('License ::')]) > 0:
        result = True

    return result, reason, HAS_LICENSE
218445
def filter_installed_packages(packages):
    """"""
    cache = apt_cache()
    _pkgs = []
    for package in packages:
        try:
            p = cache[package]
            p.current_ver or _pkgs.append(package)
        except KeyError:
            log('Package {} has no installation candidate.'.format(package),
                level='WARNING')
            _pkgs.append(package)
    return _pkgs
1043936
def check_pypi(self):
        """"""
        for dist in get_installed_distributions():
            name = dist.project_name
            if name in self.reqs.keys():
                self.reqs[name]["dist"] = dist

        pypi = ServerProxy("https://pypi.python.org/pypi")
        for name, req in list(self.reqs.items()):
            if req["url"]:
                continue  # skipping github packages.
            elif "dist" in req:
                dist = req["dist"]
                dist_version = LooseVersion(dist.version)
                available = pypi.package_releases(req["pip_req"].name, True) or pypi.package_releases(req["pip_req"].name.replace('-', '_'), True)
                available_version = self._available_version(dist_version, available)

                if not available_version:
                    msg = self.style.WARN("release is not on pypi (check capitalization and/or --extra-index-url)")
                elif self.options['show_newer'] and dist_version > available_version:
                    msg = self.style.INFO("{0} available (newer installed)".format(available_version))
                elif available_version > dist_version:
                    msg = self.style.INFO("{0} available".format(available_version))
                else:
                    msg = "up to date"
                    del self.reqs[name]
                    continue
                pkg_info = self.style.BOLD("{dist.project_name} {dist.version}".format(dist=dist))
            else:
                msg = "not installed"
                pkg_info = name
            self.stdout.write("{pkg_info:40} {msg}".format(pkg_info=pkg_info, msg=msg))
            del self.reqs[name]
241426
private function checkDestination($package)
    {
        $question_helper = $this->getHelper('question');

        Installer::isValidDestination($this->destination . DS . $package->install_path);

        if (Installer::lastErrorCode() == Installer::IS_LINK) {
            $this->output->write("\x0D");
            $this->output->writeln('  |- Checking destination...  <yellow>symbolic link</yellow>');

            if ($this->all_yes) {
                $this->output->writeln("  |     '- <yellow>Skipped automatically.</yellow>");

                return false;
            }

            $question = new ConfirmationQuestion("  |  '- Destination has been detected as symlink, delete symbolic link first? [y|N] ",
                false);
            $answer = $question_helper->ask($this->input, $this->output, $question);

            if (!$answer) {
                $this->output->writeln("  |     '- <red>You decided to not delete the symlink automatically.</red>");

                return false;
            }

            unlink($this->destination . DS . $package->install_path);
        }

        $this->output->write("\x0D");
        $this->output->writeln('  |- Checking destination...  <green>ok</green>');

        return true;
    }
1179705
def distro_check():
    """"""
    distro_data = platform.linux_distribution()
    distro = [d.lower() for d in distro_data if d.isalpha()]

    if any(['ubuntu' in distro, 'debian' in distro]) is True:
        return 'apt'
    elif any(['centos' in distro, 'redhat' in distro]) is True:
        return 'yum'
    elif any(['suse' in distro]) is True:
        return 'zypper'
    else:
        raise AssertionError(
            'Distro [ %s ] is unsupported.' % distro
        )
914695
public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        if (false === parent::isInstalled($repo, $package)) {
            return false;
        }

        $targetRoot = $this->getContaoRoot();

        foreach ($this->getSources($package) as $targetPath) {
            if (!file_exists($this->filesystem->normalizePath($targetRoot . '/' . $targetPath))) {
                return false;
            }
        }

        return true;
    }
408033
function isPackageAlreadyInstalled(packageInstallFolder) {
    try {
        const flagFilePath = path.join(packageInstallFolder, INSTALLED_FLAG_FILENAME);
        if (!fs.existsSync(flagFilePath)) {
            return false;
        }
        const fileContents = fs.readFileSync(flagFilePath).toString();
        return fileContents.trim() === process.version;
    }
    catch (e) {
        return false;
    }
}
46471
def display(self):
        
        for pkg in self.binary:
            name = GetFromInstalled(pkg).name()
            ver = GetFromInstalled(pkg).version()
            find = find_package("{0}{1}{2}".format(name, ver, self.meta.sp),
                                self.meta.pkg_path)
            if find:
                package = Utils().read_file(
                    self.meta.pkg_path + "".join(find))
                print(package)
            else:
                message = "Can't dislpay"
                if len(self.binary) > 1:
                    bol = eol = ""
                else:
                    bol = eol = "\n"
                self.msg.pkg_not_found(bol, pkg, message, eol)
                raise SystemExit(1)
1248175
def check_pseudo_package(path):
    
    if not os.path.isdir(path):
        raise Exception("Please make sure pseudo-package %s exists." % path)
    else:
        assets = os.listdir(path)
        if len(assets) == 0:
            raise Exception("Please make sure pseudo-package %s is populated." % path)
508965
public function isPackage()
	{
		// A simple package does not have a manifest file
		try
		{
			// There must be just one root folder with the format 'us-gaap-yyyy-mm-dd'
			if ( count( $this->contents ) != 1 ) return false;

			$root = $this->getFirstFolderName();
			$matches = false;
			if ( ! preg_match( "/^us-gaap-(?<date>(?<year>\d{4,4})-\d{2,2}-\d{2,2})$/", $root, $matches ) )
			{
				return false;
			}

			$this->publicationDate = $matches['date'];

			$found = false;
			$this->traverseContents( function( $path, $name, $type ) use( &$found )
			{
				if ( $type == PATHINFO_DIRNAME ) return true;
				$found = $name == XBRL_SEC_XML_Package::manifestFilename || XBRL::endsWith( $name, '.json' );
				return ! $found;
			} );

			if ( $found )
			{
				throw XBRL_TaxonomyPackageException::withError( "tpe:metadataFileFound", "The package contains a manifest.xml file or JSON manifest file." );
			}

			if ( isset( XBRL_US_TaxonomyPackage::$defaultEntryPoints[ $this->publicationDate ] ) )
			{
				$this->schemaFile = XBRL_US_TaxonomyPackage::$defaultEntryPoints[ $this->publicationDate ];
				$this->actualSchemaFilename = $this->getActualUri( $this->schemaFile );
				// $this->schemaNamespace = XBRL_US_TaxonomyPackage::namespacePrefix . "{$matches['date']}/";
			}
			else
			{
				$this->schemaFile = XBRL_US_TaxonomyPackage::filePrefix . "{$this->taxonomyYear}/elts/us-gaap-{$matches['date']}.xsd";
				$this->actualSchemaFilename = "{$root}/elts/us-gaap-{$matches['date']}.xsd";
			}

			$this->taxonomyYear = $matches['year'];
			$contents = $this->getFile( $this->actualSchemaFilename );
			if ( ! $contents )
			{
				throw XBRL_TaxonomyPackageException::withError( "tpe:noSchemaFileFound", "The package must contain a schema file (.xsd)." );
			}

			$this->schemaNamespace = $this->getTargetNamespace( $this->actualSchemaFilename, $contents );
			// $this->schemaNamespace = XBRL_US_TaxonomyPackage::namespacePrefix . "{$matches['date']}/";

			return true;
		}
		catch ( Exception $ex )
		{
			$code = $ex instanceof XBRL_TaxonomyPackageException ? $ex->error : $ex->getCode();
			$this->errors[ $code ] = $ex->getMessage();
		}

		return false;
	}
559813
def package_ensure_apt(*packages):
    """"""
    package = " ".join(packages)
    status = run("dpkg-query -W -f='${{Status}} ' {p}; true".format(p=package))
    status = status.lower()
    if 'no packages found' in status or 'not-installed' in status:
        sudo("apt-get --yes install " + package)
        return False
    else:
        return True
46462
public function isLibrary(): bool
    {
        $this->findPackage();

        if (!isset($this->package->type) || $this->package->type !== 'wpzapp-lib') {
            return false;
        }

        return true;
    }
991207
def pkg_list(self):
        
        options = [
            "-l",
            "--list"
        ]
        flag = ["--index", "--installed", "--name"]
        name = INDEX = installed = False
        for arg in self.args[2:]:
            if flag[0] == arg:
                INDEX = True
            if flag[1] in arg:
                installed = True
            if flag[2] == arg:
                name = True
            if arg not in flag:
                usage("")
                raise SystemExit()
        if (len(self.args) > 1 and len(self.args) <= 5 and
                self.args[0] in options):
            if self.args[1] in self.meta.repositories:
                PackageManager(binary=None).package_list(self.args[1],
                                                         name,
                                                         INDEX,
                                                         installed)
            else:
                usage(self.args[1])
        else:
            usage("")
608002
public static boolean isAppInstalled(final Context context, final String packageName){
        try {
            context.getPackageManager().getPackageInfo(packageName, 0);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
248244
def stdlib(self):
        
        if self.module == 'pkg_resources' or self.module.startswith('pkg_resources.'):
            return False
        elif self.filename.startswith(SITE_PACKAGES_PATHS):
            # if it's in site-packages then its definitely not stdlib
            return False
        elif self.filename.startswith(SYS_PREFIX_PATHS):
            return True
        else:
            return False
692937
private boolean isAnyPackageFromListInstalled(List<String> packages){
        boolean result = false;

        PackageManager pm = mContext.getPackageManager();

        for (String packageName : packages) {
            try {
                // Root app detected
                pm.getPackageInfo(packageName, 0);
                QLog.e(packageName + " ROOT management app detected!");
                result = true;
            } catch (PackageManager.NameNotFoundException e) {
                // Exception thrown, package is not installed into the system
            }
        }

        return result;
    }