← Back to team overview

ubuntu-tour team mailing list archive

Re: Determining running processes

 

Thanks, that's a much nicer solution. And in Python. :D

I made a quick little terminal-only demonstration of the Software Centre
automation. Apologies if it contains bad coding.

On Fri, 2010-08-20 at 12:09 -0400, Brandon Jardine wrote:
> Sure,
> 
> 
> you can do something like this too (in python)
> 
> 
> import commands
> output = commands.getoutput('ps -A')
> if 'firefox' in output:
>     print "Firefox is running!!"
> 
> 
> 
> 
> Cheers
> -
> Brandon Jardine
> 
> 
> 
> On Fri, Aug 20, 2010 at 00:19, Alexander Lancey <alex@xxxxxxxxxxxxx>
> wrote:
>         This seems to be a shorter method of doing the same task:
>         
>         ps -C firefox
>         
>         This is probably more efficient, but it takes all the strings
>         literally.
>         For example, ps -C chromium doesn't see Chrome, because it is
>         running
>         with an argument or something.
>         
>         
>         
>         _______________________________________________
>         Mailing list: https://launchpad.net/~ubuntu-tour
>         Post to     : ubuntu-tour@xxxxxxxxxxxxxxxxxxx
>         Unsubscribe : https://launchpad.net/~ubuntu-tour
>         More help   : https://help.launchpad.net/ListHelp
>         
> 
> 

#!/usr/bin/python

import sys
import os
import time
import commands

Output = "nothing"
Agave = 0
Home = os.getenv("HOME")
NotInstalled = "Package: agave\nStatus: unknown ok not-installed\nPriority: optional\nSection: gnome\n"
AgaveStatus = NotInstalled

print "Open the Software Center.\n\n"

while 'software-center' not in Output:
	time.sleep(1)
	Output = commands.getoutput('ps -A')

print "Install the package \"agave\".\n\n"

while Agave == 0:
	time.sleep(1)
	os.system("dpkg -s agave > ~/.agave_status")
	f = open(Home + "/.agave_status", "r")
	AgaveStatus = f.read()
	os.remove(Home + "/.agave_status")
	if (AgaveStatus != NotInstalled and "deinstall" not in AgaveStatus):
		Agave = 1

print "Good. Now remove the package.\n\n"

while Agave == 1:
	time.sleep(1)
	os.system("dpkg -s agave > ~/.agave_status")
	f = open(Home + "/.agave_status", "r")
	AgaveStatus = f.read()
	os.remove(Home + "/.agave_status")
	if ("deinstall" in AgaveStatus):
		Agave = 0

print "You can close the Software Center now.\n\n"

while 'software-center' in Output:
	time.sleep(1)
	Output = commands.getoutput('ps -A')

References