* fix: util is not really the place for such UI attractions
* more i18n in pisi.cli
This commit is contained in:
@@ -54,11 +54,11 @@ class CLI(UI):
|
|||||||
|
|
||||||
def warning(self,msg):
|
def warning(self,msg):
|
||||||
#self.output('Warning: ' + msg + '\n')
|
#self.output('Warning: ' + msg + '\n')
|
||||||
self.output(colorize('Warning:' + msg + '\n', 'purple'))
|
self.output(colorize(_('Warning: ') + msg + '\n', 'purple'))
|
||||||
|
|
||||||
def error(self,msg):
|
def error(self,msg):
|
||||||
#self.output('Error:' + msg + '\n')
|
#self.output('Error:' + msg + '\n')
|
||||||
self.output(colorize('Error: ' + msg + '\n', 'red'))
|
self.output(colorize(_('Error: ') + msg + '\n', 'red'))
|
||||||
|
|
||||||
def action(self,msg):
|
def action(self,msg):
|
||||||
#TODO: this seems quite redundant?
|
#TODO: this seems quite redundant?
|
||||||
@@ -82,14 +82,13 @@ class CLI(UI):
|
|||||||
if ctx.config.options and ctx.config.options.yes_all:
|
if ctx.config.options and ctx.config.options.yes_all:
|
||||||
return True
|
return True
|
||||||
while True:
|
while True:
|
||||||
s = raw_input(msg + colorize('(yes/no)', 'red'))
|
s = raw_input(msg + colorize(_('(yes/no)'), 'red'))
|
||||||
if s.startswith('y') or s.startswith('Y'):
|
if s.startswith(_('y')) or s.startswith(_('Y')):
|
||||||
return True
|
return True
|
||||||
if s.startswith('n') or s.startswith('N'):
|
if s.startswith(_('n')) or s.startswith(_('N')):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def display_progress(self, pd):
|
def display_progress(self, pd):
|
||||||
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
||||||
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
||||||
self.output(out)
|
self.output(out)
|
||||||
|
|
||||||
|
|||||||
+45
-40
@@ -13,13 +13,17 @@
|
|||||||
import sys
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
|
_ = __trans.ugettext
|
||||||
|
|
||||||
import pisi
|
import pisi
|
||||||
import pisi.cli
|
import pisi.cli
|
||||||
import pisi.context as ctx
|
import pisi.context as ctx
|
||||||
from pisi.uri import URI
|
from pisi.uri import URI
|
||||||
|
|
||||||
class Command(object):
|
class Command(object):
|
||||||
"""generic help string for any command"""
|
_("""generic help string for any command""")
|
||||||
|
|
||||||
# class variables
|
# class variables
|
||||||
|
|
||||||
@@ -41,7 +45,7 @@ class Command(object):
|
|||||||
return Command.cmd_dict[cmd]()
|
return Command.cmd_dict[cmd]()
|
||||||
|
|
||||||
if fail:
|
if fail:
|
||||||
print "Unrecognized command: ", cmd
|
print _("Unrecognized command: "), cmd
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@@ -67,19 +71,19 @@ class Command(object):
|
|||||||
p = self.parser
|
p = self.parser
|
||||||
p.add_option("-D", "--destdir", action="store")
|
p.add_option("-D", "--destdir", action="store")
|
||||||
p.add_option("", "--yes-all", action="store_true",
|
p.add_option("", "--yes-all", action="store_true",
|
||||||
default=False, help = "assume yes in all yes/no queries")
|
default=False, help = _("assume yes in all yes/no queries"))
|
||||||
p.add_option("-u", "--username", action="store")
|
p.add_option("-u", "--username", action="store")
|
||||||
p.add_option("-p", "--password", action="store")
|
p.add_option("-p", "--password", action="store")
|
||||||
p.add_option("-P", action="store_true", dest="getpass", default=False,
|
p.add_option("-P", action="store_true", dest="getpass", default=False,
|
||||||
help="Get password from the command line")
|
help=_("get password from the command line"))
|
||||||
p.add_option("-v", "--verbose", action="store_true",
|
p.add_option("-v", "--verbose", action="store_true",
|
||||||
dest="verbose", default=False,
|
dest="verbose", default=False,
|
||||||
help="detailed output")
|
help=_("detailed output"))
|
||||||
p.add_option("-d", "--debug", action="store_true",
|
p.add_option("-d", "--debug", action="store_true",
|
||||||
default=True, help="show debugging information")
|
default=True, help=_("show debugging information"))
|
||||||
p.add_option("-n", "--dry-run", action="store_true", default=False,
|
p.add_option("-n", "--dry-run", action="store_true", default=False,
|
||||||
help = "do not perform any action, just show what\
|
help = _("do not perform any action, just show what\
|
||||||
would be done")
|
would be done"))
|
||||||
return p
|
return p
|
||||||
|
|
||||||
def options(self):
|
def options(self):
|
||||||
@@ -105,7 +109,7 @@ class Command(object):
|
|||||||
|
|
||||||
if username and self.options.getpass:
|
if username and self.options.getpass:
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
password = getpass("Password: ")
|
password = getpass(_("Password: "))
|
||||||
self.authInfo = (username, password)
|
self.authInfo = (username, password)
|
||||||
else:
|
else:
|
||||||
self.authInfo = None
|
self.authInfo = None
|
||||||
@@ -141,7 +145,7 @@ class Command(object):
|
|||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
"""exit program"""
|
"""exit program"""
|
||||||
print 'Program terminated abnormally.'
|
print _('Program terminated abnormally.')
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
||||||
@@ -151,11 +155,11 @@ class autocommand(type):
|
|||||||
Command.cmd.append(cls)
|
Command.cmd.append(cls)
|
||||||
name = getattr(cls, 'name', None)
|
name = getattr(cls, 'name', None)
|
||||||
if name is None:
|
if name is None:
|
||||||
raise pisi.cli.Error('command lacks name')
|
raise pisi.cli.Error(_('command lacks name'))
|
||||||
longname, shortname = name
|
longname, shortname = name
|
||||||
def add_cmd(cmd):
|
def add_cmd(cmd):
|
||||||
if Command.cmd_dict.has_key(cmd):
|
if Command.cmd_dict.has_key(cmd):
|
||||||
raise pisi.cli.Error('duplicate command %s' % cmd)
|
raise pisi.cli.Error(_('duplicate command %s') % cmd)
|
||||||
else:
|
else:
|
||||||
Command.cmd_dict[cmd] = cls
|
Command.cmd_dict[cmd] = cls
|
||||||
add_cmd(longname)
|
add_cmd(longname)
|
||||||
@@ -237,7 +241,7 @@ conflicts relations starting from given packages.
|
|||||||
def buildno_opts(self):
|
def buildno_opts(self):
|
||||||
self.parser.add_option("", "--ignore-build-no", action="store_true",
|
self.parser.add_option("", "--ignore-build-no", action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="do not take build no into account.")
|
help=_("do not take build no into account."))
|
||||||
|
|
||||||
|
|
||||||
class Build(Command):
|
class Build(Command):
|
||||||
@@ -258,7 +262,7 @@ fetch all necessary files and build the package for you.
|
|||||||
def options(self):
|
def options(self):
|
||||||
buildno_opts(self)
|
buildno_opts(self)
|
||||||
self.parser.add_option("-O", "--output-dir", action="store", default=".",
|
self.parser.add_option("-O", "--output-dir", action="store", default=".",
|
||||||
help="output directory for produced packages")
|
help=_("output directory for produced packages"))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if not self.args:
|
if not self.args:
|
||||||
@@ -281,10 +285,10 @@ class PackageOp(Command):
|
|||||||
def options(self):
|
def options(self):
|
||||||
p = self.parser
|
p = self.parser
|
||||||
p.add_option("-B", "--ignore-comar", action="store_true",
|
p.add_option("-B", "--ignore-comar", action="store_true",
|
||||||
default=False, help="bypass comar configuration agent")
|
default=False, help=_("bypass comar configuration agent"))
|
||||||
p.add_option("", "--ignore-dependency", action="store_true",
|
p.add_option("", "--ignore-dependency", action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="do not take dependency information into account")
|
help=_("do not take dependency information into account"))
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
super(PackageOp, self).init(True)
|
super(PackageOp, self).init(True)
|
||||||
@@ -439,10 +443,10 @@ Usage: info <package1> <package2> ... <packagen>
|
|||||||
def options(self):
|
def options(self):
|
||||||
self.parser.add_option("-f", "--files", action="store_true",
|
self.parser.add_option("-f", "--files", action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Show a list of package files.")
|
help=_("show a list of package files."))
|
||||||
self.parser.add_option("-F", "--files-path", action="store_true",
|
self.parser.add_option("-F", "--files-path", action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Show only paths.")
|
help=_("Show only paths."))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if not self.args:
|
if not self.args:
|
||||||
@@ -469,7 +473,7 @@ Usage: info <package1> <package2> ... <packagen>
|
|||||||
else:
|
else:
|
||||||
print fileinfo.path
|
print fileinfo.path
|
||||||
else:
|
else:
|
||||||
print 'File information not available'
|
print _('File information not available')
|
||||||
|
|
||||||
|
|
||||||
class Index(Command):
|
class Index(Command):
|
||||||
@@ -492,7 +496,7 @@ source and binary packages.
|
|||||||
def options(self):
|
def options(self):
|
||||||
self.parser.add_option("-a", "--absolute-uris", action="store_true",
|
self.parser.add_option("-a", "--absolute-uris", action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="store absolute links for indexed files.")
|
help=_("store absolute links for indexed files."))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
@@ -501,10 +505,10 @@ source and binary packages.
|
|||||||
if len(self.args)==1:
|
if len(self.args)==1:
|
||||||
index(self.args[0])
|
index(self.args[0])
|
||||||
elif len(self.args)==0:
|
elif len(self.args)==0:
|
||||||
print 'Indexing current directory.'
|
print _('Indexing current directory.')
|
||||||
index()
|
index()
|
||||||
else:
|
else:
|
||||||
print 'Indexing only a single directory supported.'
|
print _('Indexing only a single directory supported.')
|
||||||
return
|
return
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|
||||||
@@ -534,8 +538,8 @@ Usage: list-installed
|
|||||||
list = ctx.installdb.list_installed()
|
list = ctx.installdb.list_installed()
|
||||||
list.sort()
|
list.sort()
|
||||||
if self.options.install_info:
|
if self.options.install_info:
|
||||||
print 'Package Name |St| Version| Rel.| Build| Distro| Date'
|
print _('Package Name |St| Version| Rel.| Build| Distro| Date')
|
||||||
print '========================================================================'
|
print '========================================================================'
|
||||||
for pkg in list:
|
for pkg in list:
|
||||||
package = pisi.packagedb.inst_packagedb.get_package(pkg)
|
package = pisi.packagedb.inst_packagedb.get_package(pkg)
|
||||||
inst_info = ctx.installdb.get_info(pkg)
|
inst_info = ctx.installdb.get_info(pkg)
|
||||||
@@ -678,7 +682,7 @@ Gives a brief list of PiSi components published in the repository.
|
|||||||
else:
|
else:
|
||||||
# print for all repos
|
# print for all repos
|
||||||
for repo in ctx.repodb.list():
|
for repo in ctx.repodb.list():
|
||||||
ctx.ui.info("Repository : %s\n" % repo)
|
ctx.ui.info(_("Repository : %s\n") % repo)
|
||||||
self.print_packages(repo)
|
self.print_packages(repo)
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|
||||||
@@ -713,7 +717,7 @@ Usage: list-upgrades [ <repo1> <repo2> ... repon ]
|
|||||||
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")
|
||||||
self.parser.add_option("-i", "--install-info", action="store_true",
|
self.parser.add_option("-i", "--install-info", action="store_true",
|
||||||
default=False, help="show detailed install info")
|
default=False, help=_("show detailed install info"))
|
||||||
buildno_opts(self)
|
buildno_opts(self)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -721,8 +725,8 @@ Usage: list-upgrades [ <repo1> <repo2> ... repon ]
|
|||||||
list = pisi.api.list_upgradable()
|
list = pisi.api.list_upgradable()
|
||||||
list.sort()
|
list.sort()
|
||||||
if self.options.install_info:
|
if self.options.install_info:
|
||||||
print 'Package Name |St| Version| Rel.| Build| Distro| Date'
|
print _('Package Name |St| Version| Rel.| Build| Distro| Date')
|
||||||
print '========================================================================'
|
print '========================================================================'
|
||||||
for pkg in list:
|
for pkg in list:
|
||||||
package = pisi.packagedb.inst_packagedb.get_package(pkg)
|
package = pisi.packagedb.inst_packagedb.get_package(pkg)
|
||||||
inst_info = ctx.installdb.get_info(pkg)
|
inst_info = ctx.installdb.get_info(pkg)
|
||||||
@@ -757,12 +761,12 @@ class ListPending(Command):
|
|||||||
self.finalize()
|
self.finalize()
|
||||||
|
|
||||||
|
|
||||||
class SearchAvailable(Command):
|
class Search(Command):
|
||||||
"""Search in available packages
|
"""Search packages
|
||||||
|
|
||||||
Usage: search-available <search pattern>
|
Usage: search <search pattern>
|
||||||
|
|
||||||
FIXME: this is bogus
|
#FIXME: fill this later
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -770,7 +774,7 @@ FIXME: this is bogus
|
|||||||
# Partial build commands
|
# Partial build commands
|
||||||
|
|
||||||
class BuildUntil(Build):
|
class BuildUntil(Build):
|
||||||
"""Run the build process partially
|
_("""Run the build process partially
|
||||||
|
|
||||||
Usage: -sStateName build-until <pspec file>
|
Usage: -sStateName build-until <pspec file>
|
||||||
|
|
||||||
@@ -780,7 +784,7 @@ 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
|
||||||
for you.
|
for you.
|
||||||
"""
|
""")
|
||||||
__metaclass__ = autocommand
|
__metaclass__ = autocommand
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -909,12 +913,13 @@ TODO: desc.
|
|||||||
|
|
||||||
|
|
||||||
class BuildPackage(Build):
|
class BuildPackage(Build):
|
||||||
"""Setup the source
|
_("""Setup the source
|
||||||
|
|
||||||
Usage: build-build <pspec file>
|
Usage: build-build <pspec file>
|
||||||
|
|
||||||
TODO: desc.
|
TODO: desc.
|
||||||
"""
|
""")
|
||||||
|
|
||||||
__metaclass__ = autocommand
|
__metaclass__ = autocommand
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -932,14 +937,14 @@ TODO: desc.
|
|||||||
pisi.api.build_until(arg, "buildpackages", self.authInfo)
|
pisi.api.build_until(arg, "buildpackages", self.authInfo)
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|
||||||
usage_text1 = """%prog [options] <command> [arguments]
|
usage_text1 = _("""%prog [options] <command> [arguments]
|
||||||
|
|
||||||
where <command> is one of:
|
where <command> is one of:
|
||||||
|
|
||||||
"""
|
""")
|
||||||
|
|
||||||
usage_text2 = """
|
usage_text2 = _("""
|
||||||
Use \"%prog help <command>\" for help on a specific command.
|
Use \"%prog help <command>\" for help on a specific command.
|
||||||
"""
|
""")
|
||||||
|
|
||||||
usage_text = (usage_text1 + Command.commands_string() + usage_text2)
|
usage_text = (usage_text1 + Command.commands_string() + usage_text2)
|
||||||
|
|||||||
+8
-4
@@ -13,6 +13,10 @@
|
|||||||
import sys
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
|
_ = __trans.ugettext
|
||||||
|
|
||||||
import pisi
|
import pisi
|
||||||
from pisi.uri import URI
|
from pisi.uri import URI
|
||||||
from pisi.cli.commands import *
|
from pisi.cli.commands import *
|
||||||
@@ -44,7 +48,7 @@ class PreParser(OptionParser):
|
|||||||
arg = rargs[0]
|
arg = rargs[0]
|
||||||
def option():
|
def option():
|
||||||
if not self.allow_interspersed_args and first_arg:
|
if not self.allow_interspersed_args and first_arg:
|
||||||
self.error('Options must precede non-option arguments')
|
self.error_(('Options must precede non-option arguments'))
|
||||||
del rargs[0]
|
del rargs[0]
|
||||||
return
|
return
|
||||||
# We handle bare "--" explicitly, and bare "-" is handled by the
|
# We handle bare "--" explicitly, and bare "-" is handled by the
|
||||||
@@ -76,16 +80,16 @@ class PisiCLI(object):
|
|||||||
try:
|
try:
|
||||||
args = self.parser.parse_args()
|
args = self.parser.parse_args()
|
||||||
if len(args)==0: # more explicit than using IndexError
|
if len(args)==0: # more explicit than using IndexError
|
||||||
print 'No command given'
|
print _('No command given')
|
||||||
self.die()
|
self.die()
|
||||||
cmd_name = args[0]
|
cmd_name = args[0]
|
||||||
except ParserError:
|
except ParserError:
|
||||||
print 'Command line parsing error'
|
print _('Command line parsing error')
|
||||||
self.die()
|
self.die()
|
||||||
|
|
||||||
self.command = Command.get_command(cmd_name)
|
self.command = Command.get_command(cmd_name)
|
||||||
if not self.command:
|
if not self.command:
|
||||||
print "Unrecognized command: ", cmd
|
print _("Unrecognized command: "), cmd
|
||||||
self.die()
|
self.die()
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
|
|||||||
@@ -131,6 +131,9 @@ def run_batch(cmd):
|
|||||||
|
|
||||||
def xterm_title(message):
|
def xterm_title(message):
|
||||||
"""sets message as a console window's title"""
|
"""sets message as a console window's title"""
|
||||||
|
return
|
||||||
|
#TODO: the last thing needed in util probably
|
||||||
|
#this is going to be moved to pisi.cli later
|
||||||
if os.environ.has_key("TERM") and sys.stderr.isatty():
|
if os.environ.has_key("TERM") and sys.stderr.isatty():
|
||||||
terminalType = os.environ["TERM"]
|
terminalType = os.environ["TERM"]
|
||||||
for term in ["xterm", "Eterm", "aterm", "rxvt", "screen", "kterm", "rxvt-unicode"]:
|
for term in ["xterm", "Eterm", "aterm", "rxvt", "screen", "kterm", "rxvt-unicode"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user