Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Help me debug this script with argparse and if statements (http://www.velocityreviews.com/forums/t957875-help-me-debug-this-script-with-argparse-and-if-statements.html)

Santosh Kumar 02-21-2013 10:05 AM

Help me debug this script with argparse and if statements
 
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>



All times are GMT. The time now is 11:48 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.