I’m facing a problem from past few months. I have tried hard to find a solution.
I’m using Java over Fedora 14
The problem is, I’m trying to download and install a package using Runtime.exec(“yum -y install somePkg”) but when I use pc.getInputStream() to capture stdout, I don’t get to see the current download progress status i.e. the percentage download in any form. The output sticks at ‘downloading packages:’ until yum has finished downloading. After successful download. I see only a overall installed packages list and donwload complete message in the output console.
I need a solution even if it’s a dirty one. I need to somehow capture the whole download progress of yum using java.
Directly answering the question, as asked:
Found in the Yum (/usr/share/yum-cli/output.py) source:
So, the hacky solution would be to allocate a pty for Yum…
Unfortunately, it looks like the stock Java libraries don’t provide access to the ptmx interface that Linux uses for allocating PTY’s (although, one could conceivably do so with a JNI binding — the code would not be terribly complex; although a quick Google search didn’t turn up any nice stock libraries to do so, so perhaps there’s something I’m missing, or I would suspect someone should have one lying around by now), so the “easiest” way to do this might be to write a Python wrapper that calls into the Yum internals to do its bidding, and asks for a callback. Either way, not pure Java, but linking to an external Python interpreter (and, since Yum is Python, you know that there must be one installed) might be less hassle than doing JNI linking with some C code. (As an example, you might peek at ProcessTransPackageKitCallback in /usr/share/PackageKit/helpers/yum/yumBackend.py)
However:
Alternatively, have you considered using pkcon, or using DBus to talk to PackageKit?
Using DBus wouldn’t require external libraries, but might require rethinking your installation process a bit. There’s a Java DBus library at http://dbus.freedesktop.org/doc/dbus-java/ that wraps the connection logic, at which point, the examples at http://www.packagekit.org/pk-faq.html#session-methods should give you the gist of accessing it. I believe that the DBus interface provides a way to check on a transaction as it progresses — but I’m not familiar enough with DBus to give a solid statement to that effect. That might be the least “hacky” solution I see; and, as a bonus, it’s portable to Ubuntu, at least (I believe).
pkcon, however, would be an option. It appears to write progress to stdout in a nice, parseable format, even though it does reduce its output when it’s not a tty:
That’s the actual output, so the granularity isn’t so great, but it looks pretty friendly for parsing.
I’m afraid I don’t have a Fedora 14 box to compare against — this is on Fedora 15 — so your mileage may vary.