You are not logged in.

#1 2005-05-26 17:45:15

Riklaunim
Member
Registered: 2005-04-09
Posts: 106
Website

PHP script - list packages on a repo

I've made a small PHP function which collect data about packages form the repository DB.

function list_dir($patch)
    {
    IF(ereg('..', $patch)) { die('.. in $patch'); }
    IF(strip_tags($patch) != $patch) { die('invalid chars in $patch'); }
    $katalog = @dir($patch);
    while ($plik_kat = $katalog->read())
    IF($plik_kat != '.' and $plik_kat != '..')
        {
        IF(!is_file($patch.'/'.$plik_kat))
            {
            $lista[$patch.'/'.$plik_kat] = list_dir($patch.'/'.$plik_kat);
            }
        else
            {
            $plik = fopen($patch.'/'.$plik_kat, 'r');
            $result = fread($plik, filesize($patch.'/'.$plik_kat));
            fclose($plik);
            $result = explode("n", $result);
            $result = array_unique($result);
            IF($plik_kat == 'desc')
                {
                $result2 = array('name' => $result[1], 'version' => $result[4], 'desc' => $result[7], 'size' => $result[10], 'md5' => $result[13], 'groups' => $result[16]);
                }
            else
                {
                foreach($result as $key => $val)
                    {
                    IF($val == '%DEPENDS%')
                        {
                        $dep = $key;
                        }
                    IF($val == '%CONFLICTS%')
                        {
                        $con = $key;
                        }
                    IF($val == '%PROVIDES%')
                        {
                        $prov = $key;
                        }
                    }
                foreach($result as $key => $val)
                    {
                    // Dependencies
                    IF(isset($con))
                        {
                        IF($key > $dep and $key < $con and $val != '')
                            {
                            $depend[] = $val;
                            }
                        }
                    elseIF(isset($prov))
                        {
                        IF($key > $dep and $key < $prov and $val != '')
                            {
                            $depend[] = $val;
                            }
                        }
                    else
                        {
                        IF($key > $dep and $val != '')
                            {
                            $depend[] = $val;
                            }
                        }
                    // Conflicts
                    IF(isset($prov) and isset($con))
                        {
                        IF($key > $con and $key < $prov and $val != '')
                            {
                            $confl[] = $val;
                            }
                        }
                    elseIF(isset($con))
                        {
                        IF($key > $con and $val != '')
                            {
                            $confl[] = $val;
                            }
                        }
                    // Provides
                    IF(isset($prov))
                        {
                        IF($key > $prov and $val != '')
                            {
                            $provide[] = $val;
                            }
                        }
                    }
                $result2 = array('depend' => $depend, 'conflict' => $confl, 'provide' => $provide);
                }
            $lista[$plik_kat] = $result2;
            }
        }
    $katalog->close();
    return $lista;
    }

You will get an array like:

Array
(
    [arch/embryo-cvs-20050403-1] => Array
        (
            [desc] => Array
                (
                    [name] => embryo-cvs
                    [version] => 20050403-1
                    [desc] => EDJE Virtual Machine
                    [size] => 100561
                    [md5] => 6728251b7eeb829104759bbbcf0a97c1
                    [groups] => efl
                )

            [depends] => Array
                (
                    [depend] => 
                    [conflict] => 
                    [provide] => Array
                        (
                            [0] => embryo
                        )

                )

        )

    [arch/py2play-0.1.7-1] => Array
        (
            [desc] => Array
                (
                    [name] => py2play
                    [version] => 0.1.7-1
                    [desc] => A peer-to-peer network game engine in Python
                    [size] => 31958
                    [md5] => c7280c20c7ec1bbf0ca64c3872cdce81
                    [groups] => 
                )

            [depends] => Array
                (
                    [depend] => Array
                        (
                            [0] => python
                            [1] => x-server
                        )

                    [conflict] => 
                    [provide] => 
                )

        )

    [arch/esmart-cvs-20050403-1] => Array
        (
            [desc] => Array
                (
                    [name] => esmart-cvs
                    [version] => 20050403-1
                    [desc] => A Collection of Evas Smart Objects in a Library
                    [size] => 140686
                    [md5] => 3a70f0d09c358a6d1afff3363126334b
                    [groups] => efl
                )

            [depends] => Array
                (
                    [depend] => Array
                        (
                            [0] => epsilon-cvs
                            [1] => edje-cvs
                            [2] => libtool
                        )

                    [conflict] => 
                    [provide] => Array
                        (
                            [0] => esmart
                        )

                )

        )

usage:

$x = list_dir('patch/to/repo/data');
echo '<pre>';
print_r($x);

$x is the array an you can use it as you desire... You have to download the repo *.db.tar.gz file - like on ftp://ftp.archlinux.org/tur/rensel you have rensel.db.tar.gz and then extract it to a folder and enter the path in the script - do it on localhost smile

You can use this function to make your own scripts that will do something with this data. I've made it for my RkCMF smile I'm planning to make a search-like script:
- script 1: make a SQL file with collected data (so you can make it on localhost witout uploading tons of files)
- RkCMF module: list packages in nice categories + some search options

Offline

#2 2005-05-26 18:54:08

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: PHP script - list packages on a repo

I have similar script functionality, in ruby for my primal repo manager.

I also wrote some php to snag repo.db.tar.gz contents remotely, without needing to save a file locally. The downside is it requires wget and tar on the system, and they have to be accessible by the php user (I use safemode=on for my php stuff, so i have to copy them to the exec dir). Still, it saves me from having to store db files when I only want the contents for processing purposes.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#3 2005-05-26 19:33:15

Riklaunim
Member
Registered: 2005-04-09
Posts: 106
Website

Re: PHP script - list packages on a repo

A small example of a module based on that code: link (array generated by the function is serialized and saved to file - which is called by the listing class)

Offline

Board footer

Powered by FluxBB