* cli'da ufak tefek iyilestirmeler, ama hala svn'in tam bir gopyasi

deeel.
This commit is contained in:
Eray Özkural
2005-08-14 14:51:36 +00:00
parent 0d2d9229ec
commit ee4f39b4ad
3 changed files with 21 additions and 18 deletions
+16 -13
View File
@@ -18,7 +18,7 @@ from pisi.purl import PUrl
from pisi.cli.common import * from pisi.cli.common import *
def commandsString(): def commands_string():
s = '' s = ''
list = commands.keys() list = commands.keys()
list.sort() list.sort()
@@ -27,8 +27,7 @@ def commandsString():
return s return s
# helper functions def get_command(cmd, fail=False):
def cmdObject(cmd, fail=False):
if commands.has_key(cmd): if commands.has_key(cmd):
obj = commands[cmd]() obj = commands[cmd]()
@@ -47,7 +46,7 @@ class Command(object):
def __init__(self): def __init__(self):
# now for the real parser # now for the real parser
import pisi import pisi
self.parser = OptionParser(usage=usage_text, self.parser = OptionParser(usage=getattr(self, "__doc__"),
version="%prog " + pisi.__version__) version="%prog " + pisi.__version__)
self.options() self.options()
self.parser = commonopts(self.parser) self.parser = commonopts(self.parser)
@@ -61,14 +60,14 @@ class Command(object):
pisi.config.config = pisi.config.Config(self.options) pisi.config.config = pisi.config.Config(self.options)
pisi.ui.ui = pisi.ui.CLI(self.options.debug) pisi.ui.ui = pisi.ui.CLI(self.options.debug)
self.checkAuthInfo() self.check_auth_info()
def options(self): def options(self):
"""This is a fall back function. If the implementer module provides an """This is a fall back function. If the implementer module provides an
options function it will be called""" options function it will be called"""
pass pass
def checkAuthInfo(self): def check_auth_info(self):
username = self.options.username username = self.options.username
password = self.options.password password = self.options.password
@@ -106,7 +105,8 @@ class Command(object):
pass pass
def help(self): def help(self):
print getattr(self, "__doc__") self.parser.print_help()
#print getattr(self, "__doc__")
def die(self): def die(self):
print 'Program terminated abnormally.' print 'Program terminated abnormally.'
@@ -114,7 +114,7 @@ class Command(object):
class Help(Command): class Help(Command):
"""Prints usage """Prints help for a given command
Usage: Usage:
help [command-name] help [command-name]
@@ -122,13 +122,17 @@ class Help(Command):
If run without parameters will print the general usage documentation. If run without parameters will print the general usage documentation.
If run with a command name as the parameter will print the documentation If run with a command name as the parameter will print the documentation
for that command. for that command, where command is one of:
""" """
def __init__(self): def __init__(self):
self.__doc__ = usage_text
super(Help, self).__init__() super(Help, self).__init__()
def run(self): def run(self):
if not self.args: if not self.args:
self.parser.set_usage(usage_text)
self.parser.print_help() self.parser.print_help()
return return
@@ -136,13 +140,12 @@ for that command.
for arg in self.args: for arg in self.args:
print print
pisi.ui.ui.info("%s: " % arg) pisi.ui.ui.info("command: %s\n" % arg)
obj = cmdObject(arg, True) obj = get_command(arg, True)
obj.help() obj.help()
self.finalize() self.finalize()
class Build(Command): class Build(Command):
"""Build a PISI package using a pspec.xml file """Build a PISI package using a pspec.xml file
@@ -683,5 +686,5 @@ commands = {"help": Help,
"list-repo": ListRepo "list-repo": ListRepo
} }
usage_text = (usage_text1 + commandsString() + usage_text2) usage_text = (usage_text1 + commands_string() + usage_text2)
+2 -2
View File
@@ -15,9 +15,9 @@ where <command> is one of:
""" """
usage_text2 = """ usage_text2 = """
Use \"%prog help <command>\" for help on a specific subcommand. Use \"%prog help <command>\" for help on a specific command.
PISI Package Manager PiSi Package Manager
""" """
def commonopts(parser): def commonopts(parser):
+1 -1
View File
@@ -52,7 +52,7 @@ class PisiCLI(object):
self.die() self.die()
cmd = self.parser.rargs[0] cmd = self.parser.rargs[0]
self.command = cmdObject(cmd) self.command = get_command(cmd)
if not self.command: if not self.command:
print "Unrecognized command: ", cmd print "Unrecognized command: ", cmd
self.die() self.die()