def _run(self): args = self.args if not args: if self.help: self.showHelp() return 0 else: cmd = 'show' else: cmd = args[0] args = args[1:] if cmd not in self.commands: raise InvocationError("No such command: %s" % cmd) elif self.help: print >> self.stderr, getattr(self, cmd + '_usage') return 0 storage.beginTransaction(self) try: getattr(self, cmd)(args) except: storage.abortTransaction(self) raise else: if self.dry_run: storage.abortTransaction(self) else: storage.commitTransaction(self)
def check(self, args): if args: raise InvocationError("'check' command doesn't take arguments") for module in self.iterModules(): print >> self.stderr, "Verifying", module.name, print >> self.stderr, "is at", module.currentVersion module.checkFiles()
def incr(self, args): if len(args) != 1: raise InvocationError("Must specify *one* part name to increment") for module in self.iterModules(): print >> self.stderr, "Incrementing", module.name, print >> self.stderr, "from", module.currentVersion, module.incrVersion(args[0]) print >> self.stderr, "to", module.currentVersion
def _run(self): if len(self.argv)<3: raise InvocationError("missing argument(s)") storage.beginTransaction(self) user = self.Users.newItem() user.loginId, user.password = self.argv[1:3] user.fullName = ' '.join(self.argv[3:]) or user.loginId storage.commitTransaction(self)
def _run(self): if len(self.argv)<2: raise InvocationError("missing argument(s)") storage.beginTransaction(self) cat = self.Categories.newItem() cat.pathName = self.argv[1] cat.title = ' '.join(self.argv[2:]) or cat.pathName storage.commitTransaction(self)
def set(self, args): if not args or [arg for arg in args if '=' not in arg]: raise InvocationError( "'set' requires 'name=value' arguments for each part" " you want to set.") items = [arg.split('=', 1) for arg in args] for module in self.iterModules(): print >> self.stderr, "Updating", module.name, print >> self.stderr, "from", module.currentVersion, module.setVersion(items) print >> self.stderr, "to", module.currentVersion
def _run(self): args = self.parsed_args if len(args) > 1: raise InvocationError('too many arguments') cprt = 'Type "copyright", "credits" or "license" for more information.' help = 'Type "help" or "help(n2)" for help.' self.banner = 'PEAK N2 (Python %s on %s)\n%s\n%s' % (sys.version.split( None, 1)[0], sys.platform, cprt, help) self.idict['n2'] = self exec 'from peak.api import *' in self.idict exec 'import pdb' in self.idict for cmd in ('cd', 'ls'): self.idict[cmd] = getattr(self, 'py_' + cmd) storage.begin(self) try: if args: c = naming.lookup(self, args[0]) else: c = naming.InitialContext(self) if self.adapt_to is not None: iface = importString(self.adapt_to) c = adapt(c, iface) self.py_anyway = True except: if self.force_py or self.py_anyway: c = None sys.excepthook(*sys.exc_info()) # XXX print >> self.stderr else: raise self.idict['c'] = self.idict['__c__'] = c self.idict['pwd'] = ` c ` self.handle(c) try: storage.abort(self) except: pass return 0
def find(self, name): if naming.URLMatch(name): ob = self.lookupComponent(name, NOT_FOUND) if ob is not NOT_FOUND: return ob try: name = str(PropertyName(name.replace(':', '.'))) except exceptions.InvalidName: raise InvocationError("Invalid format for argument %r" % name) for prefix in ('peak.api.', 'peak.', ''): try: return importString(prefix + name) except ImportError: pass for prefix in ('peak.running.shortcuts.', 'peak.help.'): ob = self.lookupComponent( PropertyName('peak.running.shortcuts.' + name), NOT_FOUND) if ob is not NOT_FOUND: return ob raise InvocationError("Can't find help on %r" % name)
def _run(self): if len(self.argv)<>3: raise InvocationError("missing or extra argument(s)") userId, categoryId = self.argv[1:] text = self.stdin.read() storage.beginTransaction(self) user = self.Users[userId] category = self.Categories[categoryId] category.post(user, text) storage.commitTransaction(self)
def show(self, args): if not args: format = None elif len(args) > 1: raise InvocationError("'show' command takes at most one format") else: format, = args for module in self.iterModules(): version = module.currentVersion if format: version = version[format] if self.verbose or not self.with_module: print >> self.stdout, module.name, version else: self.stdout.write(str(version))
def _run(self): if len(self.argv) > 1: for arg in self.argv[1:]: help(self.find(arg)) else: raise InvocationError("No name(s) specified")