[opensuse-buildservice] calling osc from Python scripts
Hi, I'm writing some simple user helper scripts. One of it need to do for example a 'osc copypac origproject package newproject'. I did this with a function: def obs_copypac(org, pkg, new): cmdline = "osc copypac -e %s %s %s" % (org, pkg, new) dbg_print( "cmdline: %s" % cmdline ) p = Popen(cmdline, shell=True, stdout=PIPE, stderr=PIPE) (stdout, stderr) = p.communicate() rc = p.returncode dbg_print( "osc copypac output: %s" % stdout ) if rc: print( osc copypac error: %s" % stderr return rc Works as expected. Then I remembered that osc itself was written in Python as well, so it should be better to call the python stuff directly. I looked at the osc-wrapper.py and was thinking that it should be easy to do. Simple give the commandline.Osc() call the arguments for the osc command like osccli = commandline.Osc("copypac","-e", org, pkg, new) r = babysitter.run(osccli) But this does not work, it seems the arguments are ignored, I get always the osc help page (same as running osc with no arguments). What do I missing here ? Thanks Karsten -- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-buildservice+owner@opensuse.org
On 2013-07-31 13:22:42 +0200, Karsten Keil wrote: <SNIP>
I looked at the osc-wrapper.py and was thinking that it should be easy to do. Simple give the commandline.Osc() call the arguments for the osc command like
osccli = commandline.Osc("copypac","-e", org, pkg, new) r = babysitter.run(osccli)
The constructor parameters are not interpreted as a "command".
But this does not work, it seems the arguments are ignored, I get always the osc help page (same as running osc with no arguments).
Something like this should work: from osc import commandline cli = commandline.Osc() cli.main(['osc', 'ls', 'home:Marcus_H']) If needed I can also adjust the babysitter so that you can pass a "command" to its "run" method. Marcus -- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-buildservice+owner@opensuse.org
Hi Marcus, Am 31.07.2013 14:24, schrieb Marcus Hüwe:
On 2013-07-31 13:22:42 +0200, Karsten Keil wrote:
<SNIP>
I looked at the osc-wrapper.py and was thinking that it should be easy to do. Simple give the commandline.Osc() call the arguments for the osc command like
osccli = commandline.Osc("copypac","-e", org, pkg, new) r = babysitter.run(osccli)
The constructor parameters are not interpreted as a "command".
Ahh, yes I only guessed that because the constructor did have *args, **kwargs, I did not looked deeper in the code.
But this does not work, it seems the arguments are ignored, I get always the osc help page (same as running osc with no arguments).
Something like this should work:
from osc import commandline cli = commandline.Osc() cli.main(['osc', 'ls', 'home:Marcus_H'])
That satisfy my needs, thank a lot.
If needed I can also adjust the babysitter so that you can pass a "command" to its "run" method.
For my application it's not needed, but in general it maybe a good idea to have this option. Karsten -- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-buildservice+owner@opensuse.org
On 2013-08-05 08:44:18 +0200, Karsten Keil wrote:
Am 31.07.2013 14:24, schrieb Marcus Hüwe:
<SNIP>
If needed I can also adjust the babysitter so that you can pass a "command" to its "run" method.
For my application it's not needed, but in general it maybe a good idea to have this option.
I just added an optional argv parameter to the babysitter's run method. It can be used like this: from osc import babysitter, commandline cli = commandline.Osc() babysitter.run(cli, ['osc', 'ls', 'home:Marcus_H']) Marcus -- To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-buildservice+owner@opensuse.org
participants (2)
-
Karsten Keil
-
Marcus Hüwe