Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help me debug this script with argparse and if statements

Reply
Thread Tools

Help me debug this script with argparse and if statements

 
 
Santosh Kumar
Guest
Posts: n/a
 
      02-21-2013
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>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statements and case statements questions John Crichton Ruby 6 07-12-2010 06:17 PM
Prepare Statements VS Statements Vince Java 12 01-21-2008 01:18 PM
component statements within architecture statements Neil Zanella VHDL 8 10-20-2006 09:05 AM
Debug Print Statements Ghost Java 6 06-11-2005 05:32 PM
if statements with or w/o else statements Harry George Python 6 02-23-2004 06:48 PM



Advertisments