diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 18:07:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 18:07:41 +0000 |
commit | 76926159194e180003aa78de97e5f287bf4325a5 (patch) | |
tree | 2cea7245cdc3f66355900c820c145eba90598766 /doc/source/examples/apt-cdrom.py | |
parent | Initial commit. (diff) | |
download | python-apt-76926159194e180003aa78de97e5f287bf4325a5.tar.xz python-apt-76926159194e180003aa78de97e5f287bf4325a5.zip |
Adding upstream version 2.7.6.upstream/2.7.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'doc/source/examples/apt-cdrom.py')
-rw-r--r-- | doc/source/examples/apt-cdrom.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/doc/source/examples/apt-cdrom.py b/doc/source/examples/apt-cdrom.py new file mode 100644 index 0000000..13bfb97 --- /dev/null +++ b/doc/source/examples/apt-cdrom.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 +import sys + +import apt_pkg + +import apt + + +def show_help(): + print(f"apt {apt_pkg.VERSION} compiled on {apt_pkg.DATE} {apt_pkg.TIME}") + if apt_pkg.config.find_b("version"): + return 0 + + # Copied from apt-cdrom + print( + "Usage: apt-cdrom [options] command\n" + "\n" + "apt-cdrom is a tool to add CDROM's to APT's source list. The\n" + "CDROM mount point and device information is taken from apt.conf\n" + "and /etc/fstab.\n" + "\n" + "Commands:\n" + " add - Add a CDROM\n" + " ident - Report the identity of a CDROM\n" + "\n" + "Options:\n" + " -h This help text\n" + " -d CD-ROM mount point\n" + " -r Rename a recognized CD-ROM\n" + " -m No mounting\n" + " -f Fast mode, don't check package files\n" + " -a Thorough scan mode\n" + " -c=? Read this configuration file\n" + " -o=? Set an arbitrary configuration option, eg -o " + "dir::cache=/tmp\n" + "See fstab(5)" + ) + return 0 + + +def main(args): + arguments = apt_pkg.parse_commandline( + apt_pkg.config, + [ + ("h", "help", "help"), + ("v", "version", "version"), + ("d", "cdrom", "Acquire::cdrom::mount", "HasArg"), + ("r", "rename", "APT::CDROM::Rename"), + ("m", "no-mount", "APT::CDROM::NoMount"), + ("f", "fast", "APT::CDROM::Fast"), + ("n", "just-print", "APT::CDROM::NoAct"), + ("n", "recon", "APT::CDROM::NoAct"), + ("n", "no-act", "APT::CDROM::NoAct"), + ("a", "thorough", "APT::CDROM::Thorough"), + ("c", "config-file", "", "ConfigFile"), + ("o", "option", "", "ArbItem"), + ], + args, + ) + + if apt_pkg.config.find_b("help") or apt_pkg.config.find_b("version"): + return show_help() + + progress = apt.progress.text.CdromProgress() + cdrom = apt_pkg.Cdrom() + + if not arguments: + return show_help() + elif arguments[0] == "add": + cdrom.add(progress) + elif arguments[0] == "ident": + cdrom.ident(progress) + else: + sys.stderr.write("E: Invalid operation %s\n" % arguments[0]) + return 1 + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) |