def cmd_view(self, computer_id, detail=None): """View an specific info from the specified computer """ if not detail: show_help() computer = Computer.get_by(id=computer_id) if not computer: print >> sys.stderr, "Specified computer not found in the database." sys.exit(1) details_map = { 'packages' : 'current_packages', 'update-candidates' : 'update_candidates', 'repositories' : 'repositories', 'tasks' : 'tasks' } try: read_table = getattr(computer, details_map[detail]) except: show_help() output = "Reading %s from computer %s" % (detail, repr(computer)) for i in read_table: # FIXME: define __repr__ in each db table class # and use some formatting feature like: # fill = 45 - len(package.name) # fill_blank = " " * fill # print package.name + fill_blank + package.version output += repr(i) return output
def __set_task(self, computer, task_type, *details): output = '' if len(details) == 0: show_help() computer = Computer.get_by(id=computer_id) details = " ".join(details) output += "Found %s in the database. Requesting %s of %s" % \ (repr(computer), task_type, details) Tasks(computer=computer, action=task_type, details=details) session.flush() return output
def test_install(self): # we need objects from the other tests objectstore.flush() target_pkgs = ['install_a', 'install_b'] CLI.cmd_forceinstall(1, *target_pkgs) assert RPC.get_tasks([UNIQ, TOKEN]) == [('forceinstall', 'install_a install_b')] assert CLI.cmd_list() == '1\tmoinmoin\tLinux\n' assert CLI.cmd_view(1, 'packages') == \ 'Reading packages from computer <Computer moinmoin(1)>' m = Computer.get_by(id=1) installed = CurrentPackages(computer=m, name='gcc', version='1.1') installed = CurrentPackages(computer=m, name='znes', version='4.1') objectstore.flush() # this just a dumb debug. # FIXME: use a proper __repr__ on the CurrPackages class log.debug(CLI.cmd_view(1, 'packages'))