- 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
|
||||
from pisi.cli import buildhelper, installhelper, indexhelper
|
||||
|
||||
usage = """
|
||||
Detaylı help içeriği. Komutların teker teker açıklamaları vs...
|
||||
usage: %prog [options] package-name.pspec
|
||||
usage = """%prog COMMAND [ARGUMENTS] [options]
|
||||
|
||||
Where commands are bla bla...
|
||||
"""
|
||||
|
||||
def help(options, args):
|
||||
if not args:
|
||||
print usage
|
||||
return
|
||||
elif isinstance(args, str):
|
||||
args = [args]
|
||||
class PisiCLI(object):
|
||||
def __init__(self):
|
||||
parser = OptionParser(usage=usage,version="%prog " + pisi.__version__)
|
||||
|
||||
for a in args:
|
||||
print "helping about command", a
|
||||
parser.add_option("-D", "--destdir", action="store")
|
||||
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):
|
||||
if not args:
|
||||
help(options, "install")
|
||||
for arg in args:
|
||||
installhelper.install(arg)
|
||||
try:
|
||||
self.cmd = args[0]
|
||||
self.args = args[1:]
|
||||
self.options = options
|
||||
except IndexError:
|
||||
print usage
|
||||
sys.exit(1)
|
||||
|
||||
def build(options, args):
|
||||
if not args:
|
||||
help(options, "build")
|
||||
for arg in args:
|
||||
buildhelper.build(arg)
|
||||
self.commands = {
|
||||
"help": self.help,
|
||||
"install": self.install,
|
||||
"build": self.build,
|
||||
"updateindex": self.updateindex
|
||||
}
|
||||
|
||||
def updateindex(options, args):
|
||||
"""Update the repos db with the given index file (pisi-index.xml)"""
|
||||
if len(args) != 1:
|
||||
help(options, "updateindex")
|
||||
# FIX: her komut için ayrı help
|
||||
def help(self, command=""):
|
||||
if not self.args:
|
||||
print usage
|
||||
return
|
||||
|
||||
indexfile = args[0]
|
||||
indexhelper.updateindex(indexfile)
|
||||
self.parser.print_help()
|
||||
|
||||
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():
|
||||
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=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
|
||||
def run(self):
|
||||
for key in self.commands.keys():
|
||||
if key == self.cmd:
|
||||
self.commands[key]()
|
||||
break
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
cli = PisiCLI()
|
||||
cli.run()
|
||||
|
||||
@@ -11,8 +11,10 @@ from pisi.purl import PUrl
|
||||
from pisi.fetcher import fetchUrl
|
||||
|
||||
class RemoteSource(object):
|
||||
def __init__(self, url):
|
||||
def __init__(self, url, username, password):
|
||||
self.url = url
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.location = dirname(self.url.uri)
|
||||
|
||||
pkgname = basename(dirname(self.url.path()))
|
||||
@@ -50,14 +52,16 @@ class RemoteSource(object):
|
||||
def fetchFile(self, uri, appendDest=""):
|
||||
ui.info("Fetching %s\n" % uri)
|
||||
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
|
||||
url = PUrl(pspecfile)
|
||||
if url.isRemoteFile():
|
||||
rs = RemoteSource(url)
|
||||
rs = RemoteSource(url, username, password)
|
||||
ctx = rs.ctx
|
||||
else:
|
||||
ctx = BuildContext(url.uri)
|
||||
|
||||
+3
-1
@@ -24,9 +24,11 @@ def displayProgress(pd):
|
||||
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
||||
ui.info(out)
|
||||
|
||||
def fetchUrl(url, dest, percentHook=None):
|
||||
def fetchUrl(url, dest, username=None, password=None, percentHook=None):
|
||||
fetch = Fetcher(url, dest)
|
||||
fetch.percentHook = percentHook
|
||||
if username and password:
|
||||
fetch.setAuthInfo(username, password)
|
||||
fetch.fetch()
|
||||
if percentHook:
|
||||
ui.info('\n')
|
||||
|
||||
Reference in New Issue
Block a user