- auth nanesi için birşeyler
- pisi-cli'i refactor ettim. ortalığa biraz temizlik gerekecek, yapacağız tabii biz de gerekeni :)
This commit is contained in:
@@ -7,74 +7,81 @@ from optparse import OptionParser
|
|||||||
import pisi
|
import pisi
|
||||||
from pisi.cli import buildhelper, installhelper, indexhelper
|
from pisi.cli import buildhelper, installhelper, indexhelper
|
||||||
|
|
||||||
usage = """
|
usage = """%prog COMMAND [ARGUMENTS] [options]
|
||||||
Detaylı help içeriği. Komutların teker teker açıklamaları vs...
|
|
||||||
usage: %prog [options] package-name.pspec
|
Where commands are bla bla...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def help(options, args):
|
class PisiCLI(object):
|
||||||
if not args:
|
def __init__(self):
|
||||||
print usage
|
parser = OptionParser(usage=usage,version="%prog " + pisi.__version__)
|
||||||
return
|
|
||||||
elif isinstance(args, str):
|
|
||||||
args = [args]
|
|
||||||
|
|
||||||
for a in args:
|
parser.add_option("-D", "--destdir", action="store")
|
||||||
print "helping about command", a
|
parser.add_option("-U", "--username", action="store")
|
||||||
|
parser.add_option("-P", "--password", 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=False,
|
||||||
|
help = "do not perform any action, just show what\
|
||||||
|
would be done")
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
self.parser = parser
|
||||||
|
|
||||||
def install(options, args):
|
try:
|
||||||
if not args:
|
self.cmd = args[0]
|
||||||
help(options, "install")
|
self.args = args[1:]
|
||||||
for arg in args:
|
self.options = options
|
||||||
installhelper.install(arg)
|
except IndexError:
|
||||||
|
print usage
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def build(options, args):
|
self.commands = {
|
||||||
if not args:
|
"help": self.help,
|
||||||
help(options, "build")
|
"install": self.install,
|
||||||
for arg in args:
|
"build": self.build,
|
||||||
buildhelper.build(arg)
|
"updateindex": self.updateindex
|
||||||
|
}
|
||||||
|
|
||||||
def updateindex(options, args):
|
# FIX: her komut için ayrı help
|
||||||
"""Update the repos db with the given index file (pisi-index.xml)"""
|
def help(self, command=""):
|
||||||
if len(args) != 1:
|
if not self.args:
|
||||||
help(options, "updateindex")
|
print usage
|
||||||
|
return
|
||||||
|
|
||||||
indexfile = args[0]
|
self.parser.print_help()
|
||||||
indexhelper.updateindex(indexfile)
|
|
||||||
|
def install(self):
|
||||||
|
if not self.args:
|
||||||
|
self.help("install")
|
||||||
|
for arg in self.args:
|
||||||
|
installhelper.install(arg)
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
if not self.args:
|
||||||
|
self.help("build")
|
||||||
|
|
||||||
|
username = self.options.username
|
||||||
|
password = self.options.password
|
||||||
|
for arg in self.args:
|
||||||
|
buildhelper.build(arg, username, password)
|
||||||
|
|
||||||
|
def updateindex(self):
|
||||||
|
"""Update the repos db with the given index file (pisi-index.xml)"""
|
||||||
|
if len(self.args) != 1:
|
||||||
|
self.help("updateindex")
|
||||||
|
|
||||||
|
indexfile = self.args[0]
|
||||||
|
indexhelper.updateindex(indexfile)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def run(self):
|
||||||
parser = OptionParser(usage=usage,version="%prog " + pisi.__version__)
|
for key in self.commands.keys():
|
||||||
|
if key == self.cmd:
|
||||||
parser.add_option("-D", "--destdir", action="store")
|
self.commands[key]()
|
||||||
parser.add_option("-v", "--verbose", action="store_true",
|
break
|
||||||
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=False,
|
|
||||||
help = "do not perform any action, just show what\
|
|
||||||
would be done")
|
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
|
||||||
|
|
||||||
try:
|
|
||||||
cmd = args[0]
|
|
||||||
args = args[1:]
|
|
||||||
except IndexError:
|
|
||||||
print usage
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
commands = {
|
|
||||||
"help": help,
|
|
||||||
"install": install,
|
|
||||||
"build": build,
|
|
||||||
"updateindex": updateindex
|
|
||||||
}
|
|
||||||
|
|
||||||
for key in commands.keys():
|
|
||||||
if key == cmd:
|
|
||||||
commands[key](options, args)
|
|
||||||
break
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
cli = PisiCLI()
|
||||||
|
cli.run()
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ from pisi.purl import PUrl
|
|||||||
from pisi.fetcher import fetchUrl
|
from pisi.fetcher import fetchUrl
|
||||||
|
|
||||||
class RemoteSource(object):
|
class RemoteSource(object):
|
||||||
def __init__(self, url):
|
def __init__(self, url, username, password):
|
||||||
self.url = url
|
self.url = url
|
||||||
|
self.username = username
|
||||||
|
self.password = password
|
||||||
self.location = dirname(self.url.uri)
|
self.location = dirname(self.url.uri)
|
||||||
|
|
||||||
pkgname = basename(dirname(self.url.path()))
|
pkgname = basename(dirname(self.url.path()))
|
||||||
@@ -50,14 +52,16 @@ class RemoteSource(object):
|
|||||||
def fetchFile(self, uri, appendDest=""):
|
def fetchFile(self, uri, appendDest=""):
|
||||||
ui.info("Fetching %s\n" % uri)
|
ui.info("Fetching %s\n" % uri)
|
||||||
dest = join(self.dest, appendDest)
|
dest = join(self.dest, appendDest)
|
||||||
fetchUrl(uri, dest)
|
fetchUrl(uri, dest,
|
||||||
|
username=self.username,
|
||||||
|
password=self.password)
|
||||||
|
|
||||||
|
|
||||||
def build(pspecfile):
|
def build(pspecfile, username=None, password=None):
|
||||||
# What we need to do first is create a context with our specfile
|
# What we need to do first is create a context with our specfile
|
||||||
url = PUrl(pspecfile)
|
url = PUrl(pspecfile)
|
||||||
if url.isRemoteFile():
|
if url.isRemoteFile():
|
||||||
rs = RemoteSource(url)
|
rs = RemoteSource(url, username, password)
|
||||||
ctx = rs.ctx
|
ctx = rs.ctx
|
||||||
else:
|
else:
|
||||||
ctx = BuildContext(url.uri)
|
ctx = BuildContext(url.uri)
|
||||||
|
|||||||
+3
-1
@@ -24,9 +24,11 @@ def displayProgress(pd):
|
|||||||
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
||||||
ui.info(out)
|
ui.info(out)
|
||||||
|
|
||||||
def fetchUrl(url, dest, percentHook=None):
|
def fetchUrl(url, dest, username=None, password=None, percentHook=None):
|
||||||
fetch = Fetcher(url, dest)
|
fetch = Fetcher(url, dest)
|
||||||
fetch.percentHook = percentHook
|
fetch.percentHook = percentHook
|
||||||
|
if username and password:
|
||||||
|
fetch.setAuthInfo(username, password)
|
||||||
fetch.fetch()
|
fetch.fetch()
|
||||||
if percentHook:
|
if percentHook:
|
||||||
ui.info('\n')
|
ui.info('\n')
|
||||||
|
|||||||
Reference in New Issue
Block a user