Help me debug this script with argparse and if statements

Discussion in 'Python' started by Santosh Kumar, Feb 21, 2013.

  1. I have this script (setup.py):

    import os
    import sys
    import shutil
    from argparse import ArgumentParser

    if os.getuid() != 0:
    sys.exit("can't proceed, sudo privileges needed")


    installManto = '/usr/share/man/man1/'
    installBinTo = '/usr/local/bin/'
    capsLoc = '/usr/local/bin/myapp'
    mansLoc = '/usr/share/man/man1/mymanpage.1.gz'


    def install():
    shutil.copy2('doc/mymanpage.1.gz', installManto)
    shutil.copy2('myapp', installBinTo)


    def uninstall():
    os.remove(capsLoc)
    os.remove(mansLoc)


    def update():
    uninstall()
    install()


    parser = ArgumentParser(
    prog='setup.py',
    description='installer for myapp',
    )

    parser.add_argument(
    'install',
    nargs='?',
    help='install myapp'
    )

    parser.add_argument(
    'uninstall',
    nargs='?',
    help='uninstall myapp'
    )

    args = parser.parse_args()

    if args.install:
    if os.path.isfile(capsLoc) or os.path.isfile(mansLoc):
    print("The files exists, getting ready to update.")
    update()
    else:
    print("Running the initial setup...")
    install()
    elif args.uninstall:
    print("Uninstalling..")
    uninstall()
    else:
    parser.print_help()


    Here is what happens:

    1. I can copy the *myapp* and *mymanpage.1.gz* to their appropriate
    locations with *sudo python setup.py install*. This is what I expected,
    their is no problem upto here.

    2. Running* python setup.py uninstall* *copies* the files instead of
    removing them.

    3. Running * python setup.py uninstall *when installed *updates* the files
    instead of removing them.

    So what's the problem? What is the fix? Any further tips for me?
    --
    Twitter <https://twitter.com/sntshk> | Github <https://github.com/santosh>
     
    Santosh Kumar, Feb 21, 2013
    #1
    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. Neil Zanella
    Replies:
    8
    Views:
    1,219
    mfmehdi
    Oct 20, 2006
  2. Ghost

    Debug Print Statements

    Ghost, Jun 10, 2005, in forum: Java
    Replies:
    6
    Views:
    13,771
    Kenneth P. Turvey
    Jun 11, 2005
  3. Harry George
    Replies:
    6
    Views:
    431
    Bart Nessux
    Feb 23, 2004
  4. Vince
    Replies:
    12
    Views:
    768
    Martin Gregorie
    Jan 21, 2008
  5. John Crichton
    Replies:
    6
    Views:
    281
    John Crichton
    Jul 12, 2010
Loading...

Share This Page