#!/usr/bin/env python
from __future__ import absolute_import

import sys, os
from glob import glob
import opkg

pkg_dir=sys.argv[1]
pkg_filename = sys.argv[2]

if ( not pkg_dir or not pkg_filename ):
	sys.stderr.write("Usage: opkg-update-index <package_directory> <pkgfilename>\n")
	sys.exit(1)

packages = opkg.Packages()

packages.read_packages_file(pkg_dir + '/Packages')

names = list(packages.packages.keys())

packages.add_package(opkg.Package(pkg_filename, relpath=pkg_dir))

packages.write_packages_file(pkg_dir + '/Packages.new')
os.rename(pkg_dir + '/Packages.new', pkg_dir + '/Packages')
