Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39408 > unrolled thread

Help me debug this script with argparse and if statements

Started bySantosh Kumar <sntshkmr60@gmail.com>
First post2013-02-21 15:35 +0530
Last post2013-02-21 15:35 +0530
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Help me debug this script with argparse and if statements Santosh Kumar <sntshkmr60@gmail.com> - 2013-02-21 15:35 +0530

#39408 — Help me debug this script with argparse and if statements

FromSantosh Kumar <sntshkmr60@gmail.com>
Date2013-02-21 15:35 +0530
SubjectHelp me debug this script with argparse and if statements
Message-ID<mailman.2150.1361441149.2939.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web