* komutlar icin ayri ayri option'lari implement et
- bunun icin iki kere parse etmek gerekiyor, ayrintilar kod'da - bir komut icin komut_opts() diye birsey yaziyorsunuz oluyor optionlar - index'i de koy - biraz duzenle optimize et - pisi-index'i cikar
This commit is contained in:
@@ -7,9 +7,9 @@ from optparse import OptionParser
|
|||||||
import pisi
|
import pisi
|
||||||
from pisi.cli import buildhelper, installhelper, indexhelper
|
from pisi.cli import buildhelper, installhelper, indexhelper
|
||||||
|
|
||||||
usage = """%prog <subcommand> [options] [arguments]
|
usage = """%prog <command> [options] [arguments]
|
||||||
|
|
||||||
Subcommands:
|
where <command> is one of:
|
||||||
|
|
||||||
help
|
help
|
||||||
build
|
build
|
||||||
@@ -17,7 +17,7 @@ install
|
|||||||
index
|
index
|
||||||
updatedb
|
updatedb
|
||||||
|
|
||||||
Use \"%prog help <subcommand>\" for help on a specific subcommand.
|
Use \"%prog help <command>\" for help on a specific subcommand.
|
||||||
|
|
||||||
PISI Package Manager
|
PISI Package Manager
|
||||||
"""
|
"""
|
||||||
@@ -38,28 +38,75 @@ def commonopts(parser):
|
|||||||
would be done")
|
would be done")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
class ParserError:
|
||||||
|
def __init__(self, msg):
|
||||||
|
self.msg = msg
|
||||||
|
|
||||||
|
class Parser(OptionParser):
|
||||||
|
|
||||||
|
def __init__(self, usage, version):
|
||||||
|
OptionParser.__init__(self, usage=usage, version=version)
|
||||||
|
|
||||||
|
def error(self, msg):
|
||||||
|
raise ParserError(msg)
|
||||||
|
|
||||||
class PisiCLI(object):
|
class PisiCLI(object):
|
||||||
|
|
||||||
|
commands = ["help", "build", "install", "index", "updatedb"]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
parser = OptionParser(usage=usage,
|
|
||||||
version="%prog " + pisi.__version__)
|
# first construct a parser for common options
|
||||||
|
# this is really dummy
|
||||||
|
parser = Parser(usage=usage, version="%prog " + pisi.__version__)
|
||||||
parser.allow_interspersed_args = False
|
parser.allow_interspersed_args = False
|
||||||
parser = commonopts(parser)
|
parser = commonopts(parser)
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
self.command = ""
|
||||||
|
|
||||||
self.parser = parser
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cmd = args[0]
|
(options, args) = parser.parse_args()
|
||||||
self.args = args[1:]
|
if len(parser.rargs)==0:
|
||||||
self.options = options
|
self.die()
|
||||||
except IndexError:
|
self.command = args[0]
|
||||||
print usage
|
except ParserError:
|
||||||
sys.exit(1)
|
# fully expected :) let's see if we got an argument
|
||||||
|
if len(parser.rargs)==0:
|
||||||
|
self.die()
|
||||||
|
#print 'rargs', parser.rargs, 'vals', parser.values
|
||||||
|
self.command = parser.rargs[0]
|
||||||
|
|
||||||
|
# now for the real parser
|
||||||
|
parser = OptionParser(usage=usage, version="%prog " + pisi.__version__)
|
||||||
|
parser.allow_interspersed_args = False
|
||||||
|
self.parser = commonopts(parser)
|
||||||
|
self.add_subcommand_opts()
|
||||||
|
(self.options, args) = self.parser.parse_args()
|
||||||
|
self.args = args[1:]
|
||||||
|
|
||||||
self.authInfo = None
|
self.authInfo = None
|
||||||
self.checkAuthInfo()
|
self.checkAuthInfo()
|
||||||
|
|
||||||
|
def die(self):
|
||||||
|
print usage
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def add_subcommand_opts(self):
|
||||||
|
if self.command in self.commands:
|
||||||
|
f = self.__getattribute__(self.command + '_opts')
|
||||||
|
f()
|
||||||
|
else:
|
||||||
|
print 'Unrecognized command:', self.command
|
||||||
|
self.die()
|
||||||
|
|
||||||
|
def runCommand(self):
|
||||||
|
if self.command in self.commands:
|
||||||
|
f = self.__getattribute__(self.command)
|
||||||
|
f()
|
||||||
|
else:
|
||||||
|
print 'Unrecognized command:', self.command
|
||||||
|
self.die()
|
||||||
|
|
||||||
def checkAuthInfo(self):
|
def checkAuthInfo(self):
|
||||||
username = self.options.username
|
username = self.options.username
|
||||||
password = self.options.password
|
password = self.options.password
|
||||||
@@ -81,6 +128,9 @@ class PisiCLI(object):
|
|||||||
|
|
||||||
|
|
||||||
# FIX: her komut için ayrı help
|
# FIX: her komut için ayrı help
|
||||||
|
def help_opts(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def help(self, command=""):
|
def help(self, command=""):
|
||||||
if not self.args:
|
if not self.args:
|
||||||
print usage
|
print usage
|
||||||
@@ -88,12 +138,34 @@ class PisiCLI(object):
|
|||||||
|
|
||||||
self.parser.print_help()
|
self.parser.print_help()
|
||||||
|
|
||||||
|
def index_opts(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def index(self):
|
||||||
|
if not self.args:
|
||||||
|
self.help("index")
|
||||||
|
|
||||||
|
if len(self.args)==1:
|
||||||
|
indexhelper.index(self.args[0])
|
||||||
|
elif len(self.args)==0:
|
||||||
|
indexhelper.index()
|
||||||
|
else:
|
||||||
|
print 'Indexing only a single directory supported'
|
||||||
|
self.die()
|
||||||
|
|
||||||
|
def install_opts(self):
|
||||||
|
self.parser.add_option("", "--test", action="store_true",
|
||||||
|
default=True, help="xxxx")
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
if not self.args:
|
if not self.args:
|
||||||
self.help("install")
|
self.help("install")
|
||||||
for arg in self.args:
|
for arg in self.args:
|
||||||
installhelper.install(arg)
|
installhelper.install(arg)
|
||||||
|
|
||||||
|
def build_opts(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
if not self.args:
|
if not self.args:
|
||||||
self.help("build")
|
self.help("build")
|
||||||
@@ -101,26 +173,16 @@ class PisiCLI(object):
|
|||||||
for arg in self.args:
|
for arg in self.args:
|
||||||
buildhelper.build(arg, self.authInfo)
|
buildhelper.build(arg, self.authInfo)
|
||||||
|
|
||||||
def updateindex(self):
|
def updatedb_opts(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def updatedb(self):
|
||||||
"""Update the repos db with the given index file (pisi-index.xml)"""
|
"""Update the repos db with the given index file (pisi-index.xml)"""
|
||||||
if len(self.args) != 1:
|
if len(self.args) != 1:
|
||||||
self.help("updateindex")
|
self.help("updatedb")
|
||||||
|
|
||||||
indexfile = self.args[0]
|
indexfile = self.args[0]
|
||||||
indexhelper.updateindex(indexfile)
|
indexhelper.updatedb(indexfile)
|
||||||
|
|
||||||
def runCommand(self):
|
|
||||||
commands = {
|
|
||||||
"help": self.help,
|
|
||||||
"install": self.install,
|
|
||||||
"build": self.build,
|
|
||||||
"updateindex": self.updateindex
|
|
||||||
}
|
|
||||||
|
|
||||||
for key in commands.keys():
|
|
||||||
if key == self.cmd:
|
|
||||||
commands[key]()
|
|
||||||
break
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli = PisiCLI()
|
cli = PisiCLI()
|
||||||
|
|||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
#! /usr/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# sys modules
|
|
||||||
import sys
|
|
||||||
from optparse import OptionParser
|
|
||||||
|
|
||||||
#sys.path.append("./lib")
|
|
||||||
from pisi.index import Index
|
|
||||||
import pisi.util
|
|
||||||
from pisi.ui import ui
|
|
||||||
|
|
||||||
class ArgError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def main():
|
|
||||||
|
|
||||||
usage = "usage: %prog [options] <package>"
|
|
||||||
parser = OptionParser(usage=usage,version="%prog " + pisi.__version__)
|
|
||||||
parser.add_option("-D", "--destdir", action="store")
|
|
||||||
parser.add_option("-v", "--verbose", action="store_true",
|
|
||||||
dest="verbose", default=False,
|
|
||||||
help="detailed output")
|
|
||||||
parser.add_option("-d", "--debug", action="store_true", default=True)
|
|
||||||
parser.add_option("-n", "--dry-run", action="store_true",
|
|
||||||
default = "do not perform any action, just show what\
|
|
||||||
would be done")
|
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
|
||||||
|
|
||||||
if len(args) > 1:
|
|
||||||
print usage
|
|
||||||
raise ArgError, "pisi-index error takes at most one argument"
|
|
||||||
elif len(args) == 1:
|
|
||||||
repo_dir = args[0]
|
|
||||||
else:
|
|
||||||
repo_dir = '.'
|
|
||||||
|
|
||||||
ui.info('* Building index of PISI files under ' + repo_dir + '\n')
|
|
||||||
|
|
||||||
index = Index()
|
|
||||||
index.index(repo_dir)
|
|
||||||
index.write('pisi-index.xml')
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
+11
-2
@@ -3,8 +3,17 @@
|
|||||||
from pisi.index import Index
|
from pisi.index import Index
|
||||||
from pisi.ui import ui
|
from pisi.ui import ui
|
||||||
|
|
||||||
def updateindex(indexfile):
|
def index(repo_dir = '.'):
|
||||||
ui.info('* Updating index from index file: ' + indexfile + '\n')
|
ui.info('* Building index of PISI files under ' + repo_dir + '\n')
|
||||||
|
|
||||||
|
index = Index()
|
||||||
|
index.index(repo_dir)
|
||||||
|
index.write('pisi-index.xml')
|
||||||
|
|
||||||
|
ui.info('* Index file written')
|
||||||
|
|
||||||
|
def updatedb(indexfile):
|
||||||
|
ui.info('* Updating DB from index file: ' + indexfile + '\n')
|
||||||
|
|
||||||
index = Index()
|
index = Index()
|
||||||
index.read(indexfile)
|
index.read(indexfile)
|
||||||
|
|||||||
Reference in New Issue
Block a user