Kaydet (Commit) e02f78d3 authored tarafından Barış Metin's avatar Barış Metin

- auth nanesi için birşeyler

- pisi-cli'i refactor ettim.

ortalığa biraz temizlik gerekecek, yapacağız tabii biz de gerekeni :)
üst 45d63f2a
......@@ -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]
for a in args:
print "helping about command", a
def install(options, args):
if not args:
help(options, "install")
for arg in args:
installhelper.install(arg)
def build(options, args):
if not args:
help(options, "build")
for arg in args:
buildhelper.build(arg)
def updateindex(options, args):
"""Update the repos db with the given index file (pisi-index.xml)"""
if len(args) != 1:
help(options, "updateindex")
indexfile = 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
class PisiCLI(object):
def __init__(self):
parser = OptionParser(usage=usage,version="%prog " + pisi.__version__)
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
try:
self.cmd = args[0]
self.args = args[1:]
self.options = options
except IndexError:
print usage
sys.exit(1)
self.commands = {
"help": self.help,
"install": self.install,
"build": self.build,
"updateindex": self.updateindex
}
# FIX: her komut için ayrı help
def help(self, command=""):
if not self.args:
print usage
return
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 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)
......
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment