Python terminaltables.DoubleTable() Examples
The following are 13
code examples of terminaltables.DoubleTable().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
terminaltables
, or try the search function
.
Example #1
Source File: example1.py From terminaltables with MIT License | 6 votes |
def main(): """Main function.""" title = 'Jetta SportWagen' # AsciiTable. table_instance = AsciiTable(TABLE_DATA, title) table_instance.justify_columns[2] = 'right' print(table_instance.table) print() # SingleTable. table_instance = SingleTable(TABLE_DATA, title) table_instance.justify_columns[2] = 'right' print(table_instance.table) print() # DoubleTable. table_instance = DoubleTable(TABLE_DATA, title) table_instance.justify_columns[2] = 'right' print(table_instance.table) print()
Example #2
Source File: base_handler.py From shellen with MIT License | 6 votes |
def get_table(self, arch, pattern, colored=False, verbose=False): ''' This function is used in sys command (when user want to find a specific syscall) :param Architecture for syscall table; :param Searching pattern; :param Flag for verbose output :return Return a printable table of matched syscalls ''' rawtable = self.search(arch, pattern) if len(rawtable) == 0: return None used_hd = self.__fetch_used_headers(rawtable, verbose) table = [self.__make_colored_row(used_hd, 'yellow,bold', upper=True) if colored else used_hd] for command in rawtable: cur_tb_field = [] for hd in used_hd: value = command[hd] cur_tb_field.append(self.__make_colored_field(value, hd, verbose=verbose)) table.append(cur_tb_field) return DoubleTable(table)
Example #3
Source File: charts.py From Scripting-and-Web-Scraping with MIT License | 5 votes |
def make_table(result): table_data = [['S.No', 'Name', 'Rating']] for s_no,res in enumerate(result,1): row = [] row.extend((Color('{autoyellow}' + str(s_no) + '.' + '{/autoyellow}'), Color('{autogreen}' + res[0] + '{/autogreen}'), Color('{autoyellow}' + res[1] + '{/autoyellow}'))) table_data.append(row) table_instance = DoubleTable(table_data) table_instance.inner_row_border = True print(table_instance.table) print()
Example #4
Source File: cricket_calender.py From Scripting-and-Web-Scraping with MIT License | 5 votes |
def make_table(team1,team2=''): data=scrape() table_data=[['Match','Series','Date','Month','Time']] for i in data[:]: row=[] if team1.strip(' ') in i.get('desc') and team2.strip(' ') in i.get('desc') : row.extend((Color('{autoyellow}'+i.get('desc')+'{/autoyellow}'),Color('{autocyan}'+i.get('srs')[5:]+'{/autocyan}'),Color('{autored}'+i.get('ddt')+'{/autored}'),Color('{autogreen}'+i.get('mnth_yr')+'{/autogreen}'),Color('{autoyellow}'+i.get('tm')+'{/autoyellow}'))) table_data.append(row) table_instance = DoubleTable(table_data) table_instance.inner_row_border = True print(table_instance.table) print()
Example #5
Source File: tgmeetup.py From TGmeetup with MIT License | 5 votes |
def print_result(result): tableData = [] tableHead = ["Title(name)", "City", "Link / Meetup / Date"] tableData.append(tableHead) prevTitle = None for row in result: name = "(" + row[0] + ")" title = colored(row[1], 'green') city = colored(row[2], 'cyan') try: info = row[3:] except BaseException: info = None if len(info) == 0: tableData.append([title, city, '']) tableData.append([name, "", '']) else: meetup = info[0] date = info[1] link = info[2] date = colored(date, 'yellow') if title == prevTitle: tableData.append(['', '', date]) tableData.append([name, '', meetup]) tableData.append(['', '', link]) else: tableData.append([title, city, date]) tableData.append([name, '', meetup]) tableData.append(['', '', link]) prevTitle = title print(DoubleTable(tableData).table)
Example #6
Source File: fetcher.py From shellen with MIT License | 5 votes |
def fetch_table(self, pattern, os='linux', arch=X86_32, count=0): cprint('\n<magenta,bold>[*]</> Connecting to shell-storm.org...') rowtable = self.fetch(pattern, os, arch, count, True) return DoubleTable(rowtable)
Example #7
Source File: baseexc.py From shellen with MIT License | 5 votes |
def archs(self): filtered = [] table = [] archs = sorted(list(self.executor.get_archs())) cur = [archs[0]] loc_max = MN_INF for pos in range(1, len(archs)): if self.__is_similar(archs[pos], archs[pos-1]): cur.append(archs[pos]) else: loc_max = max(loc_max, len(cur)) filtered.append(['<cyan>{}</>'.format(x) for x in cur]) cur = [archs[pos]] filtered.append(['<cyan>{}</>'.format(x) for x in cur]) loc_max = max(loc_max, len(cur)) table.append(['\r'] * len(filtered)) for i in range(loc_max): cur_row = [] for j in range(len(filtered)): cur_row.append('' if i >= len(filtered[j]) else make_colors(filtered[j][i])) table.append(cur_row) rtable = DoubleTable(table) rtable.inner_heading_row_border = False return rtable.table
Example #8
Source File: test_double_table.py From terminaltables with MIT License | 4 votes |
def test_single_line(): """Test single-lined cells.""" table_data = [ ['Name', 'Color', 'Type'], ['Avocado', 'green', 'nut'], ['Tomato', 'red', 'fruit'], ['Lettuce', 'green', 'vegetable'], ['Watermelon', 'green'], [], ] table = DoubleTable(table_data, 'Example') table.inner_footing_row_border = True table.justify_columns[0] = 'left' table.justify_columns[1] = 'center' table.justify_columns[2] = 'right' actual = table.table expected = ( u'\u2554Example\u2550\u2550\u2550\u2550\u2550\u2566\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2566\u2550\u2550' u'\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\n' u'\u2551 Name \u2551 Color \u2551 Type \u2551\n' u'\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256c\u2550\u2550\u2550\u2550' u'\u2550\u2550\u2550\u256c\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563\n' u'\u2551 Avocado \u2551 green \u2551 nut \u2551\n' u'\u2551 Tomato \u2551 red \u2551 fruit \u2551\n' u'\u2551 Lettuce \u2551 green \u2551 vegetable \u2551\n' u'\u2551 Watermelon \u2551 green \u2551 \u2551\n' u'\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256c\u2550\u2550\u2550\u2550' u'\u2550\u2550\u2550\u256c\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563\n' u'\u2551 \u2551 \u2551 \u2551\n' u'\u255a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2569\u2550\u2550\u2550\u2550' u'\u2550\u2550\u2550\u2569\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255d' ) assert actual == expected
Example #9
Source File: test_double_table.py From terminaltables with MIT License | 4 votes |
def test_windows_screenshot(tmpdir): """Test on Windows in a new console window. Take a screenshot to verify it works. :param tmpdir: pytest fixture. """ script = tmpdir.join('script.py') command = [sys.executable, str(script)] screenshot = PROJECT_ROOT.join('test_double_table.png') if screenshot.check(): screenshot.remove() # Generate script. script_template = dedent(u"""\ from __future__ import print_function import os, time from colorclass import Color, Windows from terminaltables import DoubleTable Windows.enable(auto_colors=True) stop_after = time.time() + 20 table_data = [ [Color('{b}Name{/b}'), Color('{b}Color{/b}'), Color('{b}Misc{/b}')], ['Avocado', Color('{autogreen}green{/fg}'), 100], ['Tomato', Color('{autored}red{/fg}'), 0.5], ['Lettuce', Color('{autogreen}green{/fg}'), None], ] print(DoubleTable(table_data).table) print('Waiting for screenshot_until_match()...') while not os.path.exists(r'%s') and time.time() < stop_after: time.sleep(0.5) """) script_contents = script_template % str(screenshot) script.write(script_contents.encode('utf-8'), mode='wb') # Setup expected. sub_images = [str(p) for p in HERE.listdir('sub_double_*.bmp')] assert sub_images # Run. with RunNewConsole(command) as gen: screenshot_until_match(str(screenshot), 15, sub_images, 1, gen)
Example #10
Source File: hdphmm.py From Bayesian-HMM with MIT License | 4 votes |
def print_fit_parameters(self): """ Prints a copy of the current state counts. Used for convenient checking in a command line environment. For dictionaries containing the raw values, use the `n_*` attributes. :return: """ # create copies to avoid editing n_initial = copy.deepcopy(self.n_initial) n_emission = copy.deepcopy(self.n_emission) n_transition = copy.deepcopy(self.n_transition) # make nested lists for clean printing initial = [[str(s)] + [str(n_initial[s])] for s in self.states] initial.insert(0, ["S_i", "Y_0"]) emissions = [ [str(s)] + [str(n_emission[s][e]) for e in self.emissions] for s in self.states ] emissions.insert(0, ["S_i \\ E_i"] + list(map(str, self.emissions))) transitions = [ [str(s1)] + [str(n_transition[s1][s2]) for s2 in self.states] for s1 in self.states ] transitions.insert(0, ["S_i \\ S_j"] + list(map(lambda x: str(x), self.states))) # format tables ti = terminaltables.DoubleTable(initial, "Starting state counts") te = terminaltables.DoubleTable(emissions, "Emission counts") tt = terminaltables.DoubleTable(transitions, "Transition counts") ti.padding_left = 1 ti.padding_right = 1 te.padding_left = 1 te.padding_right = 1 tt.padding_left = 1 tt.padding_right = 1 ti.justify_columns[0] = "right" te.justify_columns[0] = "right" tt.justify_columns[0] = "right" # print tables print("\n") print(ti.table) print("\n") print(te.table) print("\n") print(tt.table) print("\n") # return None
Example #11
Source File: hdphmm.py From Bayesian-HMM with MIT License | 4 votes |
def print_probabilities(self): """ Prints a copy of the current probabilities. Used for convenient checking in a command line environment. For dictionaries containing the raw values, use the `p_*` attributes. :return: """ # create copies to avoid editing p_initial = copy.deepcopy(self.p_initial) p_emission = copy.deepcopy(self.p_emission) p_transition = copy.deepcopy(self.p_transition) # convert to nested lists for clean printing p_initial = [[str(s)] + [str(round(p_initial[s], 3))] for s in self.states] p_emission = [ [str(s)] + [str(round(p_emission[s][e], 3)) for e in self.emissions] for s in self.states ] p_transition = [ [str(s1)] + [str(round(p_transition[s1][s2], 3)) for s2 in self.states] for s1 in self.states ] p_initial.insert(0, ["S_i", "Y_0"]) p_emission.insert(0, ["S_i \\ E_j"] + [str(e) for e in self.emissions]) p_transition.insert(0, ["S_i \\ E_j"] + [str(s) for s in self.states]) # format tables ti = terminaltables.DoubleTable(p_initial, "Starting state probabilities") te = terminaltables.DoubleTable(p_emission, "Emission probabilities") tt = terminaltables.DoubleTable(p_transition, "Transition probabilities") te.padding_left = 1 te.padding_right = 1 tt.padding_left = 1 tt.padding_right = 1 te.justify_columns[0] = "right" tt.justify_columns[0] = "right" # print tables print("\n") print(ti.table) print("\n") print(te.table) print("\n") print(tt.table) print("\n") # return None
Example #12
Source File: s3_permissions.py From Miscellany with BSD 3-Clause "New" or "Revised" License | 4 votes |
def analyze_bucket(bucket): client = boto3.client('s3') bucket_acl = client.get_bucket_acl(Bucket=bucket) permission = [] for grants in bucket_acl['Grants']: if ('URI' in grants['Grantee']) and ('AllUser' in grants['Grantee']['URI']): permission.append(grants['Permission']) globalListAccess = 'NO' globalWriteAccess = 'NO' points=0 if len(permission) >= 1: if len(permission) == 1: if permission[0] == 'READ': globalListAccess = 'YES' points+=1 if permission[0] == 'WRITE': globalWriteAccess = 'YES' points+=1 if len(permission) > 1: if permission[0] == 'READ': globalListAccess = 'YES' points+=1 if permission[0] == 'WRITE': globalWriteAccess = 'YES' points+=1 if permission[1] == 'READ': globalListAccess = 'YES' points+=1 if permission[1] == 'WRITE': globalWriteAccess = 'YES' points+=1 if globalListAccess == 'YES' or globalWriteAccess == 'YES': table_data = [ ['BucketName', 'GlobalListAccess', 'GlobalWriteAccess'], [bucket, globalListAccess, globalWriteAccess], ] table = DoubleTable(table_data) table.inner_row_border = True print(table.table) api.Metric.send( metric="bucket.exposed", host="aws.s3.bucket." + bucket, points=points, #0=ok, 1=read exposed, 2=write exposed tags=["aws","s3","s3permissions"] )
Example #13
Source File: DockerManager.py From Kathara with GNU General Public License v3.0 | 4 votes |
def get_lab_info(self, lab_hash=None, machine_name=None, all_users=False): user_name = utils.get_current_user_name() if not all_users else None machines = self.docker_machine.get_machines_by_filters(lab_hash=lab_hash, machine_name=machine_name, user=user_name ) if not machines: if not lab_hash: raise Exception("No machines running.") else: raise Exception("Lab is not started.") machines = sorted(machines, key=lambda x: x.name) machine_streams = {} for machine in machines: machine_streams[machine] = machine.stats(stream=True, decode=True) table_header = ["LAB HASH", "USER", "MACHINE NAME", "STATUS", "CPU %", "MEM USAGE / LIMIT", "MEM %", "NET I/O"] stats_table = DoubleTable([]) stats_table.inner_row_border = True while True: machines_data = [ table_header ] for (machine, machine_stats) in machine_streams.items(): try: result = next(machine_stats) except StopIteration: continue stats = self._get_aggregate_machine_info(result) machines_data.append([machine.labels['lab_hash'], machine.labels['user'], machine.labels["name"], machine.status, stats["cpu_usage"], stats["mem_usage"], stats["mem_percent"], stats["net_usage"] ]) stats_table.table_data = machines_data yield "TIMESTAMP: %s" % datetime.now() + "\n\n" + stats_table.table