GithubHelp home page GithubHelp logo

pombredanne / rpminfo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from remicollet/rpminfo

0.0 0.0 0.0 189 KB

Mirror of https://git.remirepo.net/cgit/tools/php-rpminfo.git/

License: Other

M4 3.75% C 71.88% PHP 24.37%

rpminfo's Introduction

RPM information extension for PHP

Retrieve RPM information from PHP code using librpm.

This extension can be considered as stable, and be used on production environement.

But be aware that if its API will probably stay stable, some changes may occur before version 1.0.0.


Sources

Build

You need the rpm development files (rpm-devel) version >= 4.11.3.

From the sources tree

$ phpize
$ ./configure --enable-rpminfo
$ make
$ make test

Usage

rpmvercmp

int rpmvercmp(string evr1, string evr2);

Allow to compare 2 EVR (epoch:version-release) strings. The return value is < 0 if evr1 < evr2, > 0 if evr1 > evr2, 0 if equal.

$ php -a
php > var_dump(rpmvercmp("1.0", "1.1"));
int(-1)
php > var_dump(rpmvercmp("1:1.0", "1.1"));
int(1)

rpminfo

array rpminfo(string path [, bool full  [, string &error]]);

Retrieve information from a rpm file, reading its metadata. If given error will be used to store error message instead of raising a warning. The return value is a hash table, or false if it fails.

$ php -a
php > print_r(rpminfo("tests/bidon.rpm"));
Array
(
    [Name] => bidon
    [Version] => 1
    [Release] => 1.fc25.remi
    [Arch] => x86_64
)

php > print_r(rpminfo("tests/bidon.rpm", true));
Array
(
    [Headeri18ntable] => C
    [Sigsize] => 2304
    [Sigmd5] => 644819c3566819b1e10a5c97943de094
    [Sha1header] => 0a86742fe53973ac9ab4611187a83ffb44f1de5a
    [Sha256header] => 9aab7242a80212ad1fe4fdd3b250c0c4f176c0b3fb1355c0d62ff094fc3f7da0
    [Name] => bidon
    [Version] => 1
    [Release] => 1.fc25.remi
    [Summary] => Bidon
    [Description] => A dummy package
    ...
    [IsSource] => 
)

php > var_dump(rpminfo("missing.rpm"));
Warning: rpminfo(): Can't open 'missing.rpm': No such file or directory in php shell code on line 1
bool(false)

php > var_dump(rpminfo("missing.rpm", false, $error));
bool(false)
php > echo $error;
Can't open 'missing.rpm': No such file or directory

rpmdbinfo

array rpmdbinfo(string path [, bool full ]);

Retrieve information from rpm database about an installed package. The return value is an array of hash tables, or false if it fails.

$ php -a
php > print_r(rpmdbinfo("php"));
Array
(
    [0] => Array
        (
            [Name] => php
            [Version] => 7.3.5
            [Release] => 1.fc31.remi
            [Summary] => PHP scripting language for creating dynamic web sites
            [Arch] => x86_64
        )
)

Retrieve information from rpm database about installed packages using glob or regex. The return value is an array of hash tables, or false if it fails.

$ php -a
php > print_r(rpmdbsearch("php-pecl-r*", RPMTAG_NAME, RPMMIRE_GLOB));
Array
(
    [0] => Array
        (
            [Name] => php-pecl-radius
            [Version] => 1.4.0
            [Release] => 0.10.b1.fc31
            [Summary] => Radius client library
            [Arch] => x86_64
        )
    [1] => Array
        (
            [Name] => php-pecl-redis5
            [Version] => 5.2.0
            [Release] => 1.fc31.remi.7.3
            [Summary] => Extension for communicating with the Redis key-value store
            [Arch] => x86_64
        )
    [2] => Array
        (
            [Name] => php-pecl-rpminfo
            [Version] => 0.2.3
            [Release] => 1.fc31.remi.7.3
            [Summary] => RPM information
            [Arch] => x86_64
        )
)

$ php -a
php > print_r(rpmdbsearch("^php-pecl-r", RPMTAG_NAME, RPMMIRE_REGEX));
Array
(
    [0] => Array
        (
            [Name] => php-pecl-radius
            [Version] => 1.4.0
            [Release] => 0.10.b1.fc31
            [Summary] => Radius client library
            [Arch] => x86_64
        )
    [1] => Array
        (
            [Name] => php-pecl-redis5
            [Version] => 5.2.0
            [Release] => 1.fc31.remi.7.3
            [Summary] => Extension for communicating with the Redis key-value store
            [Arch] => x86_64
        )
    [2] => Array
        (
            [Name] => php-pecl-rpminfo
            [Version] => 0.2.3
            [Release] => 1.fc31.remi.7.3
            [Summary] => RPM information
            [Arch] => x86_64
        )
)

$ php -a
php > print_r(rpmdbsearch(PHP_BINARY, RPMTAG_INSTFILENAMES));
Array
(
    [0] => Array
        (
            [Name] => php-cli
            [Version] => 7.3.15
            [Release] => 1.fc31.remi
            [Summary] => Command-line interface for PHP
            [Arch] => x86_64
        )
)

LICENSE

Author: Remi Collet

This extension is licensed under The PHP License, version 3.01


History

Created as a PoC, for fun, see history on https://blog.remirepo.net/post/2018/01/26/About-repomanage-performance-regression

rpminfo's People

Contributors

omega13a avatar remicollet avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.