/usr/share/pyshared/atheist/plugins/alias.py is in atheist 0.20110402-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # -*- mode:python; coding:utf-8; tab-width:4 -*-
import optparse
import atheist
from atheist.gvar import Log
class AliasValueError(Exception): pass
class Alias(atheist.Plugin):
@classmethod
def get_options(cls, config, parser):
def alias_is_right(value):
for opt in [x for x in value.split() if x.startswith('--')]:
if not opt in valid_options:
Log.error("[alias] '%s' is not a valid option" % opt)
return False
return True
if not hasattr(config, 'alias'):
return []
valid_options = [x._long_opts[0] for x in parser.option_list]
retval = []
for key,value in config.alias.items():
if alias_is_right(value):
retval.append(optparse.Option(
'--%s' % key, action='store_true',
help="User alias for '%s'" % value))
return retval
@classmethod
def config(cls, config, parser):
def configure_alias(key, value):
if not hasattr(config, key) or not getattr(config, key):
return
Log.info("Applying alias '%s': %s", key, value)
parser_opts,_ = parser.parse_args(value.split())
alias_opts = [x for x in value.split() if x.startswith('--')]
for name in alias_opts:
attr_name = parser.get_option(name).dest
value = getattr(parser_opts, attr_name)
setattr(config, attr_name, value)
if not hasattr(config, 'alias'):
return
for key,value in config.alias.items():
configure_alias(key, value)
|