1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#!/usr/bin/env python
import os, tempfile, shutil, sys
from ctypes import *
import ctypes
#GLOBAL
pacman=cdll.LoadLibrary("libpacman.so")
CFG_FILE = "/etc/pacman-g2.conf"
#for print debug messages
debug=1
#some class for pacman-g2
class PM_LIST(Structure):
pass
PM_LIST._fields_ = [
("data", ctypes.c_void_p),
("prev", POINTER(PM_LIST)),
("next", POINTER(PM_LIST)),
("last", POINTER(PM_LIST))]
class PM_DB(Structure):
pass
PM_DB._fields_ = [
("path", ctypes.c_char_p),
("treename", ctypes.c_char * 255),
("handle", ctypes.c_void_p),
("pkgcache", POINTER(PM_LIST)),
("grpcache", POINTER(PM_LIST)),
("handle", POINTER(PM_LIST)),
("servers", ctypes.c_char),
("lastupdate", ctypes.c_char * 16)]
def _db_cb (section,db):
print_debug("passe")
print_debug(db)
return
def pacman_init():
pacman.pacman_release()
if pacman.pacman_initialize("/") == -1:
print "Can't initialise pacman-g2"
sys.exit(0)
def pacman_init_database():
print_debug("init database")
pacman_cb_db_register = CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p, POINTER(PM_DB))
print_debug("pacman_parse_config")
pacman.pacman_parse_config.argtypes = [ctypes.c_char_p,pacman_cb_db_register,ctypes.c_char_p]
pacman.pacman_parse_config.restype = ctypes.c_int
pacman.pacman_parse_config(CFG_FILE,pacman_cb_db_register(_db_cb),'')
print_debug("pacman_parse_config fini")
def main():
pacman_init()
pacman_init_database()
def help():
print "help :"
print "--search Package"
sys.exit(0)
def print_debug(textConsole):
if debug <> 1:
return
print "DEBUG : "+textConsole
def _db_cb(section , db):
print db
#start main program
main() |
Partager