Example #1
0
 def compare(self, a, b, coloured_lines):
     diff = super().compare(a, b)
     colours = {' ': 'grey', '+': 'red', '-': 'green', '?': 'yellow'}
     if not coloured_lines:
         return [colored(line, colours[line[0]]) for line in diff]
     coloured_diff = []
     line_nb = -1
     for line in diff:
         line_nb += line[0] in ' +'
         if line[0] == ' ':
             coloured_diff.extend(colored(''.join(snippet), colour)
                                      for snippet, colour in
                                             coloured_lines[line_nb]
                                 )
         else:
             coloured_diff.append(colored(line, colours[line[0]]))
     return coloured_diff
Example #2
0
File: core.py Project: alttch/pptop
def colored(text, color=None, on_color=None, attrs=None):
    try:
        if not config['display'].get('colors'):
            return str(text)
        else:
            return termcolor.colored(str(text),
                                     color=color,
                                     on_color=on_color,
                                     attrs=attrs)
    except:
        return str(text)
Example #3
0
 def get_interactive_prompt(self):
     if self.current_section:
         s = '/'.join(self.current_section)
         if neotermcolor:
             s = neotermcolor.colored(s,
                                      color='yellow',
                                      attrs='bold',
                                      readline_safe=True)
         ps = '[{}]{}'.format(s, self.ps)
     else:
         ps = self.ps
     return ps
Example #4
0
File: gcli.py Project: alttch/eva3
 def colored(self,
             text,
             color=None,
             on_color=None,
             attrs=None,
             rlsafe=False):
     if not self.can_colorize():
         return str(text)
     return neotermcolor.colored(text,
                                 color=color,
                                 on_color=on_color,
                                 attrs=attrs,
                                 readline_safe=rlsafe)
Example #5
0
from pathlib import Path

dir_runtime = Path(a.dir) / 'runtime'
dir_etc = Path(a.dir) / 'etc'
dir_bin = Path(a.dir) / 'bin'

if not dir_runtime.is_dir():
    raise RuntimeError(f'{dir_runtime} is not a directory!')

if not dir_etc.is_dir():
    raise RuntimeError(f'{dir_etc} is not a directory!')

check = a.MODE == 'check'

print(
    colored('{} CONFIGS'.format('CHECKING' if check else 'IMPORTING'),
            color='yellow'))
print()

eva_dir = a.dir

sys.path.insert(0, (Path(__file__).absolute().parents[1] / 'lib').as_posix())

if not check:
    import eva.registry


# embed classes to run standalone
class ConfigFile():
    """
    A helper to manage .ini files
Example #6
0
            pbar = tqdm(total=infile.stat().st_size, unit='b')
            while True:
                buf = fh.read(CHSIZE)
                if buf:
                    ebuf = pubkey.encrypt(
                        buf,
                        padding.OAEP(
                            mgf=padding.MGF1(algorithm=hashes.SHA256()),
                            algorithm=hashes.SHA256(),
                            label=None))
                    of.write(ebuf)
                    pbar.update(CHSIZE)
                else:
                    pbar.close()
                    break
except:
    outfile.unlink()
    raise

print()
print(f'Support request file created: ' +
      neotermcolor.colored(outfile, color='green', attrs='bold'))
print()
print('Please send the above file to your support engineer.')
if pubkey.key_size >= 4096:
    print(
        dedent("""
    The file is encrypted with 8192-bit RSA key, so any public communcation
    channel can be used.
    """))
Example #7
0
 def print_repeat_title(self, command, interval):
     import datetime
     t = datetime.datetime.now().strftime('%Y-%m-%d %T')
     if neotermcolor:
         command = neotermcolor.colored(command, color='yellow')
     print('{}  {}  (interval {} sec)'.format(t, command, interval))
Example #8
0
cprint('Starting. Please do not perform any API calls during core benchmark',
       '@warning')

code, result = api_call('test_phi', {
    'i': 'eva_benchmark_vr',
    'c': 'start_benchmark'
})

if result.get('output') != 'OK':
    print('Unable to register benchmark core handlers')
    sys.exit(2)

params['i'] = 'eva_benchmark_vs'

print('Executing {} iterations...'.format(
    neotermcolor.colored(iterations, color='cyan', attrs='bold')))

for a in range(0, iterations):
    params['c'] = '1000=' + str(a + 101)
    p = a / iterations * 100
    if p and p == int(p):
        cprint(f'\r{p:.0f}%', '@counter', end=' ' * 2, flush=True)
    code, result = api_call('test_phi', params)
    if code != 0:
        cprint('FAILED', '@error')
        sys.exit(4)

cprint('\r100%', '@counter', end=' ', flush=True)

time.sleep(1)