* deminki commit'de onemli bir degisiklik vardi unuttum:

option'lari goster ulan!
* kisa komut adlari icin altyapiya basla
* help'i daha da guzel yap
This commit is contained in:
Eray Özkural
2005-08-14 15:46:02 +00:00
parent ee4f39b4ad
commit dfde5729dd
+129 -69
View File
@@ -51,7 +51,6 @@ class Command(object):
self.options() self.options()
self.parser = commonopts(self.parser) self.parser = commonopts(self.parser)
(self.options, self.args) = self.parser.parse_args() (self.options, self.args) = self.parser.parse_args()
#print 'opts,args = ', self.options, self.args
self.args.pop(0) # exclude command arg self.args.pop(0) # exclude command arg
import pisi import pisi
@@ -93,22 +92,35 @@ class Command(object):
def init(self, database = False): def init(self, database = False):
"""initialize PiSi components""" """initialize PiSi components"""
# IMPORTANT: command imports here or in the command class run fxns # NB: command imports here or in the command class run fxns
import pisi.toplevel import pisi.toplevel
from pisi.ui import ui from pisi.ui import ui
# initialize repository databases
if database: if database:
from pisi.repodb import repodb from pisi.repodb import repodb
repodb.init_dbs() repodb.init_dbs()
def finalize(self): def finalize(self):
"""do cleanup work for PiSi components"""
pass
def name(self):
"""(command name, shortname) pair to be filled by subclasses"""
pass pass
def format_name(self):
(name, shortname) = self.name()
return "%s (%s)" % (name, shortname)
def help(self): def help(self):
self.parser.print_help() """print help for the command"""
#print getattr(self, "__doc__") pisi.ui.ui.info(self.format_name() + ': ')
print getattr(self, "__doc__")
print self.parser.format_option_help()
def die(self): def die(self):
"""exit program"""
print 'Program terminated abnormally.' print 'Program terminated abnormally.'
sys.exit(-1) sys.exit(-1)
@@ -116,8 +128,7 @@ class Command(object):
class Help(Command): class Help(Command):
"""Prints help for a given command """Prints help for a given command
Usage: Usage: help <command1> <command2> ... <commandn>
help [command-name]
If run without parameters will print the general usage documentation. If run without parameters will print the general usage documentation.
@@ -127,9 +138,14 @@ for that command, where command is one of:
""" """
def __init__(self): def __init__(self):
self.__doc__ = usage_text #TODO? Discard Help's own usage doc in favor of general usage doc
#self.__doc__ = usage_text
self.__doc__ += commands_string()
super(Help, self).__init__() super(Help, self).__init__()
def name(self):
return ("help", "h")
def run(self): def run(self):
if not self.args: if not self.args:
self.parser.set_usage(usage_text) self.parser.set_usage(usage_text)
@@ -139,25 +155,26 @@ for that command, where command is one of:
self.init() self.init()
for arg in self.args: for arg in self.args:
print
pisi.ui.ui.info("command: %s\n" % arg)
obj = get_command(arg, True) obj = get_command(arg, True)
obj.help() obj.help()
print
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
Usage: Usage: build <pspec.xml>
build pspec.xml
You can give an URI of the pspec.xml file. PISI will You can give a URI of the pspec.xml file. PISI will
fetch all necessary files and build the package for you. fetch all necessary files and build the package for you.
""" """
def __init__(self): def __init__(self):
super(Build, self).__init__() super(Build, self).__init__()
def name(self):
return ("build", "bi")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -205,8 +222,7 @@ class PackageOp(Command):
class Install(PackageOp): class Install(PackageOp):
"""Install PISI packages """Install PISI packages
Usage: Usage: install <package1> <package2> ... <packagen>
install package1 package2 ... packagen
You may use filenames, URIs or package names for packages. If you have You may use filenames, URIs or package names for packages. If you have
specified a package name, it should exist in a specified repository. specified a package name, it should exist in a specified repository.
@@ -214,6 +230,9 @@ specified a package name, it should exist in a specified repository.
def __init__(self): def __init__(self):
super(Install, self).__init__() super(Install, self).__init__()
def name(self):
return ("install", "it")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -227,8 +246,7 @@ specified a package name, it should exist in a specified repository.
class Upgrade(PackageOp): class Upgrade(PackageOp):
"""Upgrade PISI packages """Upgrade PISI packages
Usage: Usage: Upgrade <package1> <package2> ... <packagen>
Upgrade package1 package2 ... packagen
You may use filenames, URIs or package names for packages. If you have You may use filenames, URIs or package names for packages. If you have
specified a package name, it should exist in a specified repository. specified a package name, it should exist in a specified repository.
@@ -236,6 +254,9 @@ specified a package name, it should exist in a specified repository.
def __init__(self): def __init__(self):
super(Upgrade, self).__init__() super(Upgrade, self).__init__()
def name(self):
return ("upgrade", "up")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -249,14 +270,16 @@ specified a package name, it should exist in a specified repository.
class Remove(PackageOp): class Remove(PackageOp):
"""Remove PISI packages """Remove PISI packages
Usage: Usage: remove <package1> <package2> ... <packagen>
remove package1-name package2-name ... packagen-name
Remove a package from your system. Just give the package name to remove. Remove package(s) from your system. Just give the package names to remove.
""" """
def __init__(self): def __init__(self):
super(Remove, self).__init__() super(Remove, self).__init__()
def name(self):
return ("remove", "rm")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -268,11 +291,15 @@ Remove a package from your system. Just give the package name to remove.
class ConfigurePending(PackageOp): class ConfigurePending(PackageOp):
"""configure pending packages""" """configure pending packages
"""
def __init__(self): def __init__(self):
super(ConfigurePending, self).__init__() super(ConfigurePending, self).__init__()
def name(self):
return ("configure-pending", "cp")
def run(self): def run(self):
self.init() self.init()
@@ -281,16 +308,18 @@ class ConfigurePending(PackageOp):
class Info(Command): class Info(Command):
"""Display information about a package """Display package information
Usage: Usage: info <package1> <package2> ... <packagen>
info <package>
TODO: Some description... TODO: Some description
""" """
def __init__(self): def __init__(self):
super(Info, self).__init__() super(Info, self).__init__()
def name(self):
return ("info", "i")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -312,14 +341,18 @@ TODO: Some description...
class Index(Command): class Index(Command):
"""Index PISI files in a given directory """Index PISI files in a given directory
Usage: Usage: index directory
index directory
TODO: Some description... index command searches for all PiSi files in a directory and accumulates
the information in an XML file. In particular, it indexes both source and
binary packages.
""" """
def __init__(self): def __init__(self):
super(Index, self).__init__() super(Index, self).__init__()
def name(self):
return ("index", "ix")
def run(self): def run(self):
self.init() self.init()
@@ -337,15 +370,16 @@ TODO: Some description...
class ListInstalled(Command): class ListInstalled(Command):
"""Print the list of all installed packages """Print the list of all installed packages
Usage: Usage: list-installed
list-installed
TODO: Some description...
""" """
def __init__(self): def __init__(self):
super(ListInstalled, self).__init__() super(ListInstalled, self).__init__()
def name(self):
return ("list-installed", "li")
def options(self): def options(self):
self.parser.add_option("-l", "--long", action="store_true", self.parser.add_option("-l", "--long", action="store_true",
default=False, help="show in long format") default=False, help="show in long format")
@@ -363,16 +397,19 @@ TODO: Some description...
class UpdateRepo(Command): class UpdateRepo(Command):
"""Update the databases of a repository """Update repository databases
Usage: Usage: update-repo <repo1> <repo2> ... <repon>
update-repo <repo1> <repo2>
TODO: Some description... <repoi>: repository name
Synchronizes the PiSi databases with the current repository.
""" """
def __init__(self): def __init__(self):
super(UpdateRepo, self).__init__() super(UpdateRepo, self).__init__()
def name(self):
return ("update-repo", "ur")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -386,14 +423,19 @@ TODO: Some description...
class AddRepo(Command): class AddRepo(Command):
"""Add a repository """Add a repository
Usage: Usage: add-repo <repo> <indexuri>
add-repo <repo> <indexuri>
TODO: Some description... <repo>: name of repository to add
<indexuri>: URI of index file
NB: We support only local files (e.g., /a/b/c) and http:// URIs at the moment
""" """
def __init__(self): def __init__(self):
super(AddRepo, self).__init__() super(AddRepo, self).__init__()
def name(self):
return ("add-repo", "ar")
def run(self): def run(self):
if len(self.args)>=2: if len(self.args)>=2:
@@ -408,22 +450,24 @@ TODO: Some description...
class RemoveRepo(Command): class RemoveRepo(Command):
"""Remove a repository """Remove repositories
Usage: Usage: remove-repo <repo1> <repo2> ... <repon>
remove-repo <repo>
TODO: Some description... Remove all repository information from the system.
""" """
def __init__(self): def __init__(self):
super(RemoveRepo, self).__init__() super(RemoveRepo, self).__init__()
def name(self):
return ("remove-repo", "rr")
def run(self): def run(self):
if len(self.args)>=1: if len(self.args)>=1:
self.init() self.init()
name = self.args[0] for repo in self.args:
pisi.toplevel.remove_repo(name) toplevel.remove_repo(repo)
self.finalize() self.finalize()
else: else:
self.help() self.help()
@@ -433,14 +477,16 @@ TODO: Some description...
class ListRepo(Command): class ListRepo(Command):
"""List repositories """List repositories
Usage: Usage: list-repo
list-repo
TODO: Some description... Lists currently tracked repositories.
""" """
def __init__(self): def __init__(self):
super(ListRepo, self).__init__() super(ListRepo, self).__init__()
def name(self):
return ("list-repo", "lr")
def run(self): def run(self):
self.init() self.init()
@@ -454,14 +500,16 @@ TODO: Some description...
class ListAvailable(Command): class ListAvailable(Command):
"""List available packages in the repositories """List available packages in the repositories
Usage: Usage: list-available [ <repo1> <repo2> ... repon ]
list-available [repo]
TODO: desc... Gives a brief list of PiSi components published in the repository.
""" """
def __init__(self): def __init__(self):
super(ListAvailable, self).__init__() super(ListAvailable, self).__init__()
def name(self):
return ("list-available", "li")
def run(self): def run(self):
from pisi.repodb import repodb from pisi.repodb import repodb
from pisi.ui import ui from pisi.ui import ui
@@ -492,6 +540,9 @@ class ListPending(Command):
def __init__(self): def __init__(self):
super(ListPending, self).__init__() super(ListPending, self).__init__()
def name(self):
return ("list-pending", "lp")
def run(self): def run(self):
from pisi.installdb import installdb from pisi.installdb import installdb
from pisi.ui import ui from pisi.ui import ui
@@ -506,24 +557,21 @@ class ListPending(Command):
class SearchAvailable(Command): class SearchAvailable(Command):
"""Search in available packages """Search in available packages
Usage: Usage: search-available <search pattern>
search-available <search pattern>
TODO: Some description... FIXME: this is bogus
""" """
pass pass
# Partial build commands # Partial build commands
class BuildUntil(Command): class BuildUntil(Command):
"""Run the build process partially """Run the build process partially
Usage: Usage: -sStateName build-until <pspec file>
-sStateName build-until <pspec file>
Where states are: where states are:
unpack, setupaction, buildaction, installaction, buildpackages unpack, setupaction, buildaction, installaction, buildpackages
You can give an URI of the pspec.xml file. PISI will fetch all You can give an URI of the pspec.xml file. PISI will fetch all
necessary files and unpack the source and prepare a source directory necessary files and unpack the source and prepare a source directory
@@ -532,6 +580,9 @@ for you.
def __init__(self): def __init__(self):
super(BuildUntil, self).__init__() super(BuildUntil, self).__init__()
def name(self):
return ("build-until", "bu")
def options(self): def options(self):
self.parser.add_option("-s", action="store", dest="state") self.parser.add_option("-s", action="store", dest="state")
@@ -552,14 +603,16 @@ for you.
class BuildUnpack(Command): class BuildUnpack(Command):
"""Unpack the source archive """Unpack the source archive
Usage: Usage: build-dounpack <pspec file>
build-dounpack <pspec file>
TODO: desc. TODO: desc.
""" """
def __init__(self): def __init__(self):
super(BuildUnpack, self).__init__() super(BuildUnpack, self).__init__()
def name(self):
return ("build-unpack", "biu")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -574,14 +627,16 @@ TODO: desc.
class BuildSetup(Command): class BuildSetup(Command):
"""Setup the source """Setup the source
Usage: Usage: build-dosetup <pspec file>
build-dosetup <pspec file>
TODO: desc. TODO: desc.
""" """
def __init__(self): def __init__(self):
super(BuildSetup, self).__init__() super(BuildSetup, self).__init__()
def name(self):
return ("build-setup", "bis")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -597,14 +652,16 @@ TODO: desc.
class BuildBuild(Command): class BuildBuild(Command):
"""Setup the source """Setup the source
Usage: Usage: build-dobuild <pspec file>
build-dobuild <pspec file>
TODO: desc. TODO: desc.
""" """
def __init__(self): def __init__(self):
super(BuildBuild, self).__init__() super(BuildBuild, self).__init__()
def name(self):
return ("build-dobuild", "bib")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -619,14 +676,16 @@ TODO: desc.
class BuildInstall(Command): class BuildInstall(Command):
"""Install to the sandbox """Install to the sandbox
Usage: Usage: build-doinstall <pspec file>
build-doinstall <pspec file>
TODO: desc. TODO: desc.
""" """
def __init__(self): def __init__(self):
super(BuildInstall, self).__init__() super(BuildInstall, self).__init__()
def name(self):
return ("build-doinstall", "bii")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -642,14 +701,16 @@ TODO: desc.
class BuildPackage(Command): class BuildPackage(Command):
"""Setup the source """Setup the source
Usage: Usage: build-dobuild <pspec file>
build-dobuild <pspec file>
TODO: desc. TODO: desc.
""" """
def __init__(self): def __init__(self):
super(BuildPackage, self).__init__() super(BuildPackage, self).__init__()
def name(self):
return ("build-dopackage", "bip")
def run(self): def run(self):
if not self.args: if not self.args:
self.help() self.help()
@@ -687,4 +748,3 @@ commands = {"help": Help,
} }
usage_text = (usage_text1 + commands_string() + usage_text2) usage_text = (usage_text1 + commands_string() + usage_text2)