GithubHelp home page GithubHelp logo

pombredanne / rpmlib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paradoxengine/rpmlib

0.0 2.0 0.0 899 KB

RPM package management API language bindings for Go language

License: Apache License 2.0

Go 100.00%

rpmlib's Introduction

rpmlib

RPM API language bindings for Go language

Description

RPM API language bindings for Go language.

Installation

This package depends on RPM C language API libraries. On RedHat/CentOS environment, you can get RPM development libraries by hitting following command.

yum -y install rpm-devel
rpm -qi rpm-devel

On Ubuntu, you can use the following:

sudo apt-get install librpm-dev

Please check the rpm-devel/librpm-dev package version. Currently, my language bindings were tested against RPM lib version 4.14.1.

Then, import to your project

export GOROOT=<Your Go language tools path>
export GOPATH=<Your Go project directory>
go get github.com/necomeshi/rpmlib

Usages

Currently, following APIs are available.

  • Searcing and getting installed package information
package main

import (
  "os"
  "fmt"
  "io"
  "github.com/necomeshi/rpmlib"
)

func main() {
  ts, err := rpmlib.NewTransactionSet()
  if err != nil {
    fmt.Fprintf(os.Stderr, "Cannot get transaction set: %s\n", err)
    os.Exit(1)
  }

  defer ts.Free()

  iter, err := ts.SequencialIterator()
  if err != nil {
    fmt.Fprintf(os.Stderr, "Cannot get iterator: %s\n", err)
    os.Exit(1)
  }

  defer iter.Free()

  for {
    h, itr_err := iter.Next()

    if itr_err == io.EOF {
      break
    }

    if itr_err != nil {
      fmt.Fprintf(os.Stderr, "Cannot get next iterator: %s\n", itr_err)
      break
    }

    defer h.Free()

    name, h_err := h.GetString(rpmlib.RPMTAG_NAME)
    if h_err != nil {
      fmt.Fprintf(os.Stderr, "Cannot get name from rpm header: %s\n", h_err)
      break
    }

    fmt.Println(name)

  }
}
  • Get a package file information
package main

import (
  "os"
  "fmt"
  "github.com/necomeshi/rpmlib"
)


func main() {

  if len(os.Args) == 0 {
    fmt.Fprintf(os.Stderr, "No package name is specified")
    os.Exit(1)
  }

  ts, err := rpmlib.NewTransactionSet()
  if err != nil {
    fmt.Fprintf(os.Stderr, "Cannot get transaction set: %s\n", err)
    os.Exit(1)
  }

  defer ts.Free()

  h, err := ts.ReadPackageFile(os.Args[1])
  if err != nil {
    fmt.Fprintf(os.Stderr, "Cannot get package rpm header: %s\n", err)
    os.Exit(1)
  }

  defer h.Free()

  name, err := h.GetStringArray(rpmlib.RPMTAG_NAME)
  if err != nil {
    fmt.Fprintf(os.Stderr, "Cannot get package name: %s\n", err)
  }

  fmt.Println(name)

}

Author

Necomeshi

Copyright

Copyright (c) 2018 necomeshi https://github.com/necomesh

see ./LICENSE

rpmlib's People

Contributors

paradoxengine avatar

Watchers

 avatar  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.