1#!/usr/bin/python3 2 3import os, subprocess 4import cfg 5 6def opkgcl(opkg_args): 7 cmd = "{} -o {} {}".format(cfg.opkgcl, cfg.offline_root, opkg_args) 8 #print(cmd) 9 return subprocess.getstatusoutput(cmd) 10 11def install(pkg_name, flags=""): 12 return opkgcl("{} install {}".format(flags, pkg_name))[0] 13 14def remove(pkg_name, flags=""): 15 return opkgcl("{} remove {}".format(flags, pkg_name))[0] 16 17def update(): 18 return opkgcl("update")[0] 19 20def upgrade(): 21 return opkgcl("upgrade")[0] 22 23def files(pkg_name): 24 output = opkgcl("files {}".format(pkg_name))[1] 25 return output.split("\n")[1:] 26 27 28def is_installed(pkg_name, version=None): 29 out = opkgcl("list_installed {}".format(pkg_name))[1] 30 if len(out) == 0 or out.split()[0] != pkg_name: 31 return False 32 if version and out.split()[2] != version: 33 return False 34 if not os.path.exists("{}/usr/lib/opkg/info/{}.control"\ 35 .format(cfg.offline_root, pkg_name)): 36 return False 37 return True 38 39 40if __name__ == '__main__': 41 import sys 42 (status, output) = opkgcl(" ".join(sys.argv[1:])) 43 print(output) 44 exit(status) 45