Exemplo n.º 1
0
def ping(ip):

    try:
        if ip == 'NA':
            return True

        check = False
        packet_Tx = 1
        pass_rate = 51

        my_plat = p_system().lower()
        if my_plat == 'win32' or my_plat == 'windows':
            count_type = 'n'
        else:
            count_type = 'c'

        raw = _cmdline("ping -%s %s %s" % (count_type, packet_Tx, ip))

        if my_plat == 'win32' or my_plat == 'windows':
            raw = raw.split('%')[0]
            raw = raw.split(' ')[-1]
            loss_rate = float(raw[1:])
        else:
            raw = raw.split('%')[0]
            loss_rate = float(raw.split(' ')[-1])

        packet_Rx = 100 - loss_rate

        if packet_Rx >= pass_rate:
            return True
        return False
    except Exception as e:
        return True
Exemplo n.º 2
0
#!/usr/local/bin/python2.7
#### @martysama0134 start scripts ####
### TODO fix -s -w for srvr and not only channels
from subprocess import check_output as sp_co, call as sp_call, CalledProcessError as sp_CalledProcessError
from os import getcwd as os_getcwd, chdir as os_chdir

from platform import system as p_system
v_system = p_system()

class M2TYPE:
	SERVER, DB, AUTH, CHANFOLDER, CHANNEL, CORE = xrange(6)
	NOCHAN = 0

def fShell(szCmd, bRet=False):
	try:
		if bRet:
			return sp_co(szCmd, shell=True)[:-1]	# remove final \n
		else:
			return sp_call(szCmd, shell=True)
	except sp_CalledProcessError:
		return -1

def keyCheck(dict, key, elem={}):
	try:
		dict[key]
	except KeyError:
		dict[key]=elem

proclist={}
whichlist={"serv":[], "chan":[]}
def staInit():
Exemplo n.º 3
0
def clear_console():
    if p_system() == 'Windows':
        os_system('cls')
    else:
        os_system('clear')
Exemplo n.º 4
0
def main(year: int, puzzle: int, all_puzzles: bool, cache: bool) -> None:
    src_path = dirname(abspath(__file__))
    year_path = abspath(join(src_path, f'years/{year}'))
    root_path = abspath(join(src_path, '../'))

    settings_path = join(year_path, 'settings.json')
    settings_default_path = join(src_path, 'settings.default.json')
    output_table_path = join(root_path, './docs/output_table.md')

    if isfile(settings_path):
        with open(settings_path, 'r') as s:
            settings = loads(''.join(s.readlines()))
    else:
        copy(settings_default_path, settings_path)
        print(f'\nPlease fill in {settings_path} first!')
        exit(1)

    session = settings['session']

    puzzles_to_run = [puzzle]

    if all_puzzles is True:
        puzzles_to_run = [day for day in range(1, min(puzzle + 1, 26))]

    puzzle_outputs = [
        [
            '#',
            'Part 1',
            'Part 1 Time',
            'Part 2',
            'Part 2 Time',
            'Tests',
            'Tests Time',
        ],
    ]
    puzzles = load_year(year)

    for day in [f'{d:02d}' for d in puzzles_to_run]:
        puzzle_class = f'Puzzle{day}'

        if puzzle_class in puzzles:
            print(f'Attempting to execute AoC puzzle {day}...: ',
                  end='',
                  flush=True)

            start_time = time()
            try:
                puzzle_instance = puzzles[puzzle_class](year, day, session)
                puzzle_instance.execute(cache)

                puzzle_outputs.append(puzzle_instance.results)
                end_time = f'{((time() - start_time) * 1000):.3f}'
                print(
                    f'{BOLD}{GREEN} Successful{RESET} in {BOLD}{PURPLE}{end_time} ms{RESET}'
                )

            except ConnectionError:
                print(f'{BOLD}{GREEN} Failed {RESET}')
            except Exception:
                print(f'{BOLD}{GREEN} Failed {RESET}')
                print_exc()
                print()
        else:
            template = base_template.format(day)
            puzzle_dir = join(year_path, f'{day}')
            puzzle_solution = join(year_path, f'{day}/solution.py')

            puzzle_path = Path(puzzle_dir)
            puzzle_path.mkdir()

            with open(puzzle_solution, 'w') as f:
                f.writelines(template)

            print(f'\nClass for day {day} created. Happy Coding!!\n')
            exit(1)

    if len(puzzle_outputs) > 1:
        table = tabulate(
            puzzle_outputs,
            headers='firstrow',
            tablefmt='pretty',
            numalign='left',
            stralign='left',
        )

        if all_puzzles is True:
            if p_system() != 'Windows':
                o_system('clear')

        print(table)

        with open(join(root_path, output_table_path), 'w') as f:
            f.writelines(
                tabulate(
                    puzzle_outputs,
                    headers='firstrow',
                    tablefmt='html',
                    numalign='left',
                    stralign='left',
                ), )