Package conary :: Module command
[hide private]
[frames] | no frames]

Source Code for Module conary.command

  1  # 
  2  # Copyright (c) 2006-2008 rPath, Inc. 
  3  # 
  4  # This program is distributed under the terms of the Common Public License, 
  5  # version 1.0. A copy of this license should have been distributed with this 
  6  # source file in a file called LICENSE. If it is not present, the license 
  7  # is always available at http://www.rpath.com/permanent/licenses/CPL-1.0. 
  8  # 
  9  # This program is distributed in the hope that it will be useful, but 
 10  # without any warranty; without even the implied warranty of merchantability 
 11  # or fitness for a particular purpose. See the Common Public License for 
 12  # full details. 
 13  # 
 14   
 15  import os, sys, optparse 
 16   
 17  from conary.conaryclient import cmdline 
 18  from conary.lib import options, log 
 19  from conary import state, versions 
 20   
 21  (NO_PARAM,  ONE_PARAM)  = (options.NO_PARAM, options.ONE_PARAM) 
 22  (OPT_PARAM, MULT_PARAM) = (options.OPT_PARAM, options.MULT_PARAM) 
 23   
24 -class ConaryCommand(options.AbstractCommand):
25 docs = {'build-label' : (options.VERBOSE_HELP, 26 'Use build label LABEL as default search' 27 ' loc', 'LABEL'), 28 'components' : (options.VERBOSE_HELP, 29 'Do not hide components'), 30 'config' : (options.VERBOSE_HELP, 31 'Set config KEY to VALUE', '"KEY VALUE"'), 32 'config-file' : (options.VERBOSE_HELP, 33 'Read PATH config file', 'PATH'), 34 'context' : (options.VERBOSE_HELP, 35 'Set the current context'), 36 'exclude-troves' : (options.VERBOSE_HELP, 37 'Do not install troves matching REGEXP', 38 'REGEXP'), 39 'install-label' : (options.VERBOSE_HELP, 40 'Set the install label', 'LABEL'), 41 'interactive' : (options.VERBOSE_HELP, 42 'ask questions before performing actions ' 43 'that change system or repository state'), 44 'flavors' : (options.VERBOSE_HELP, 45 'Display complete flavors where applicable'), 46 'full-versions' : (options.VERBOSE_HELP, 47 'Always display complete version strings'), 48 'labels' : (options.VERBOSE_HELP, 49 'Always display labels for versions'), 50 'profile' : optparse.SUPPRESS_HELP, 51 'lsprof' : optparse.SUPPRESS_HELP, 52 'pubring' : (options.VERBOSE_HELP, ''), 53 'skip-default-config': (options.VERBOSE_HELP, 54 "Don't read default configs"), 55 'quiet' : (options.VERBOSE_HELP, 56 'do not display extra information when ' 57 'running'), 58 'root' : (options.VERBOSE_HELP, 59 'use conary database at location ROOT'), 60 'trust-threshold' : (options.VERBOSE_HELP, 61 'Set trust threshold', 'INT') 62 } 63
64 - def addParameters(self, argDef):
65 d = {} 66 d['config'] = '-c', MULT_PARAM 67 d['config-file'] = MULT_PARAM 68 d['context'] = ONE_PARAM 69 d['install-label'] = MULT_PARAM 70 d['profile'] = NO_PARAM 71 d['lsprof'] = NO_PARAM 72 d['skip-default-config'] = NO_PARAM 73 argDef[self.defaultGroup] = d
74
75 - def addConfigOptions(self, cfgMap, argDef):
76 cfgMap['build-label'] = 'buildLabel', ONE_PARAM, 77 cfgMap['pubring'] = 'pubRing', ONE_PARAM 78 cfgMap['quiet'] = 'quiet', NO_PARAM, 79 cfgMap['root'] = 'root', ONE_PARAM, '-r' 80 cfgMap['flavors'] = 'fullFlavors', NO_PARAM 81 cfgMap['full-versions'] = 'fullVersions', NO_PARAM 82 cfgMap['interactive'] = 'interactive', NO_PARAM, 83 options.AbstractCommand.addConfigOptions(self, cfgMap, argDef)
84
85 - def setContext(self, cfg, argSet):
86 cmdline.setContext(cfg, argSet.pop('context', None), 87 searchCurrentDir=True)
88
89 - def processConfigOptions(self, cfg, cfgMap, argSet):
90 self.setContext(cfg, argSet) 91 92 options.AbstractCommand.processConfigOptions(self, cfg, cfgMap, argSet) 93 l = [] 94 for labelStr in argSet.get('install-label', []): 95 l.append(versions.Label(labelStr)) 96 if l: 97 cfg.installLabelPath = l 98 del argSet['install-label'] 99 100 for k,v in cfg.environment.items(): 101 if v == '': 102 cfg.environment.pop(k) 103 os.environ.pop(k, None) 104 continue 105 os.environ[k] = v
106
107 -class ConfigCommand(ConaryCommand):
108 commands = ['config'] 109 help = 'Display the current configuration' 110 docs = {'show-contexts' : 'display contexts as well as current config', 111 'show-passwords' : 'do not mask passwords'} 112 commandGroup = 'Information Display' 113
114 - def addParameters(self, argDef):
115 ConaryCommand.addParameters(self, argDef) 116 argDef["show-contexts"] = NO_PARAM 117 argDef["show-passwords"] = NO_PARAM 118 argDef["show-files"] = NO_PARAM
119
120 - def runCommand(self, cfg, argSet, args, **kwargs):
121 showPasswords = argSet.pop('show-passwords', False) 122 showContexts = argSet.pop('show-contexts', False) 123 showLineOrigins = argSet.pop('show-files', False) 124 try: 125 prettyPrint = sys.stdout.isatty() 126 except AttributeError: 127 prettyPrint = False 128 cfg.setDisplayOptions(hidePasswords=not showPasswords, 129 showContexts=showContexts, 130 prettyPrint=prettyPrint, 131 showLineOrigins=showLineOrigins) 132 if argSet: return self.usage() 133 if (len(args) > 2): 134 return self.usage() 135 else: 136 cfg.display()
137
138 -class HelpCommand(options.AbstractCommand):
139 commands = ['help'] 140 help = 'Display help information' 141 commandGroup = 'Information Display' 142
143 - def runCommand(self, cfg, argSet, args, **kwargs):
144 if len(args) == 3: 145 command = args[2] 146 commands = self.mainHandler._supportedCommands 147 if not command in commands: 148 print "%s: no such command: '%s'" % (self.mainHandler.name, 149 command) 150 sys.exit(1) 151 commands[command].usage() 152 elif len(args) == 2: 153 self.mainHandler.usage(showAll=True) 154 return 0 155 else: 156 print "%s: too many arguments: '%s'" % (self.mainHandler.name, 157 ' '.join(args[2:])) 158 sys.exit(1)
159
160 -class MainHandler(options.MainHandler):
161 commandList = [ ConfigCommand, HelpCommand ]
162