def display(self): if not self.table: print 'empty' return for pairs in map(lambda *_: _, *take(list(self.table.iteritems()), by=5)): # 按5列表示 for pair in pairs: if pair: print '%s | %s' % (str(pair[0]).rjust(3), str(pair[1]).ljust(3)), print
def dispatch_command(memory, page_tables): cmd = raw_input('> ') if cmd[0] == 'h': print 'h(elp) -- print this text' print 'a(llocate) -- request for space allocation', 'type `a\' or `a proc_name size\'' print 'r(elease) -- release space', 'type `r\' or `r proc_name block0 block1 block2 ...\'' print 'd(isplay) -- display the content of the page table' print 'display (b)it map -- display the content of the bit map' elif cmd[0] == 'd': args = get_cmd(cmd, '%c &s') if not args: return (proc_names,) = args if not proc_names: proc_names = sorted(page_tables.keys()) for name in proc_names: if name not in page_tables: print '%s is not a process' % name else: print '--', name, '--', ' page | block' page_tables[name].display() elif cmd[0] == 'a': args = get_cmd(cmd, '%c %s %i', hint='proc_name size') if not args: return proc_name, size = args blocks = memory.allocate(size) print '%s allocated' % blocks if blocks: page_tables[proc_name].register(blocks) elif cmd[0] == 'r': args = get_cmd(cmd, '%c %s &i', hint='proc_name pages') if not args: return proc_name, pages = args if not pages: pages = page_tables[proc_name].table.keys() page_tables[proc_name].release(*pages) elif cmd[0] == 'b': print 'available blocks: %s' % memory.available_block_amount for line in take(memory.bit_map, by=8): print line else: print 'unrecognized command, type `h\' for help'
rx = re.compile('<regex>') def match(tags): for tag in tags: if rx.match(tag): return True pass stars = [star for star in stars if match(star['tags'])] #now, convert "tags" to a string def tagstostr(star): star['tags'] = ','.join(star['tags']) return star stars[:] = [tagstostr(star) for star in stars] if opts['--ALL']: pass elif opts['--all']: keys = ['full_name', 'html_url', 'description'] + keys elif not opts['--fields']: keys = ['full_name'] if opts['--tags'] and 'tags' not in keys: keys.append('tags') if opts['--description'] and 'description' not in keys: keys.append('description') stars = [take(star, keys) for star in stars] #tags for star in stars: for key in keys: print(star[key], end="\t") print("")