diff options
author | P. J. McDermott <pjm@nac.net> | 2012-02-09 10:56:43 (EST) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2012-02-09 10:56:43 (EST) |
commit | f431cd1a48a6a5186633bf5f16a2d21cb4399e8c (patch) | |
tree | 337e36fd9d7884fcf76ba769ab7b0039f52d9d31 /src/tests/regress/opkgcl.py |
Initial commit.
TODO: Copyright information.
Including source code and a patch to add files generated by GNU Autoconf
is not very pretty... Running 'make dist' in the SVN trunk to generate
a source archive might be better.
Diffstat (limited to 'src/tests/regress/opkgcl.py')
-rwxr-xr-x | src/tests/regress/opkgcl.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/tests/regress/opkgcl.py b/src/tests/regress/opkgcl.py new file mode 100755 index 0000000..47e7dd3 --- /dev/null +++ b/src/tests/regress/opkgcl.py @@ -0,0 +1,64 @@ +#!/usr/bin/python3 + +import os, subprocess +import cfg + +def opkgcl(opkg_args): + cmd = "{} -o {} {}".format(cfg.opkgcl, cfg.offline_root, opkg_args) + #print(cmd) + return subprocess.getstatusoutput(cmd) + +def install(pkg_name, flags=""): + return opkgcl("{} install {}".format(flags, pkg_name))[0] + +def remove(pkg_name, flags=""): + return opkgcl("{} remove {}".format(flags, pkg_name))[0] + +def update(): + return opkgcl("update")[0] + +def upgrade(params=None): + if params: + opkgcl("upgrade {}".format(params))[0] + else: + return opkgcl("upgrade")[0] + +def files(pkg_name): + output = opkgcl("files {}".format(pkg_name))[1] + return output.split("\n")[1:] + + +def flag_unpacked(pkg_name): + out = opkgcl("flag unpacked {}".format(pkg_name)) + return out == "Setting flags for package {} to unpacked.".format(pkg_name) + +def is_installed(pkg_name, version=None): + out = opkgcl("list_installed {}".format(pkg_name))[1] + if len(out) == 0 or out.split()[0] != pkg_name: + return False + if version and out.split()[2] != version: + return False + if not os.path.exists("{}/usr/lib/opkg/info/{}.control"\ + .format(cfg.offline_root, pkg_name)): + return False + return True + +def is_autoinstalled(pkg_name): + status_path = "{}/usr/lib/opkg/status".format(cfg.offline_root) + if not os.path.exists(status_path): + return False + status_file = open(status_path, "r") + status = status_file.read() + status_file.close() + index_start = status.find("Package: {}".format(pkg_name)) + if index_start < 0: + return False + index_end = status.find("\n\n", index_start) + return status.find("Auto-Installed: yes", index_start, index_end) >= 0 + + +if __name__ == '__main__': + import sys + (status, output) = opkgcl(" ".join(sys.argv[1:])) + print(output) + exit(status) |