what's wrong with my popen reasoning?

Discussion in 'Python' started by Rick Spencer, Feb 5, 2006.

  1. Rick Spencer

    Rick Spencer Guest

    Hi all,

    I am very new to Python programming. I am writing a program to manage
    wireless connections, this is for GNOME on Linux. I present the user with
    a "connect" button. I want to handle the connection for them slightly
    different depending on whether or not the wireless access point they are
    trying to connect to is secure. In either case, I have a similar question.

    In the first case, the wireless access point is secured. I want to bring
    up the GNOME applet for configuring a wireless access interface. I can
    pass the command line commands to bring it up, but I can't figure out how
    to bring it up in a modal fashion, so that my Python program waits for the
    user to dismiss it before my program gets control again.

    In the second case, the access point is not secured. I just want to fire
    off the command line utility (iwconfig) for connecting. In this case, I
    want my program to wait until iwconfig is done before continuing on. I
    figure that I could just write a line of code to read in from the console,
    but I thought there might be a more pythonic way of doing it.

    Here's my function so far, with variables replaced with constants to make
    it easier to read:

    def connect_clicked(self, widget, data=None):
    if locked:
    os.popen("sudo network-admin -c ath0")
    self.emit('connection-attempted', "ath0")

    else:
    os.popen("sudo iwconfig ath0 ap 00:0F:B3:31:CB:01")
    self.emit('connection-attempted', "ath0")

    Thanks much!

    Cheers, Rick
     
    Rick Spencer, Feb 5, 2006
    #1
    1. Advertising

  2. Rick Spencer

    Rick Spencer Guest

    On Sun, 05 Feb 2006 10:39:18 -0800, Rick Spencer wrote:
    <snip>

    >I just want to fire
    > off the command line utility (iwconfig) for connecting. In this case, I
    > want my program to wait until iwconfig is done before continuing on. I
    > figure that I could just write a line of code to read in from the console,
    > but I thought there might be a more pythonic way of doing it.
    >
    > Here's my function so far, with variables replaced with constants to make
    > it easier to read:
    >
    > def connect_clicked(self, widget, data=None):
    > if locked:
    > os.popen("sudo network-admin -c ath0")
    > self.emit('connection-attempted', "ath0")
    >
    > else:
    > os.popen("sudo iwconfig ath0 ap 00:0F:B3:31:CB:01")
    > self.emit('connection-attempted', "ath0")
    >
    > Thanks much!
    >
    > Cheers, Rick


    I found some python code that had the answer.

    def connect_clicked(self, widget, data=None):
    if self.wirelessconnection.locked:
    subprocess.call(["network-admin", "-c", "ath0"])

    This makes my app just wait until the network-admin process is gone.

    Cheers, Rick
     
    Rick Spencer, Feb 5, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blu4899
    Replies:
    4
    Views:
    1,750
    Bob Foster
    Oct 31, 2003
  2. Andy Baker

    Reasoning behind nested scope

    Andy Baker, Aug 3, 2004, in forum: Python
    Replies:
    6
    Views:
    335
    Nigel Rowe
    Aug 5, 2004
  3. GHUM
    Replies:
    1
    Views:
    266
    Marc 'BlackJack' Rintsch
    Oct 17, 2008
  4. Mark

    reasoning for a macro

    Mark, May 28, 2010, in forum: C Programming
    Replies:
    14
    Views:
    548
  5. small Pox
    Replies:
    5
    Views:
    268
    small Pox
    Dec 5, 2010
Loading...

Share This Page