Exemplo n.º 1
0
def main():
    arguments = parse_args()
    filename, extension = arguments.input.rsplit('.', 1)
    temp_file = f'{filename}_temp.png'

    try:
        quantitize_image(filename, extension, arguments.colors)
        imagick_output = generate_histogram(temp_file)
        delete_file(temp_file)
    except:
        print(
            'Something went wrong with ImageMagick, is it installed correctly? Its version needs to be at least 7.0.9'
        )
    else:
        output_lines = imagick_output.split('\n')
        parsed_colors = [parse_line(line) for line in output_lines]
        sorted_colors = sorted(parsed_colors,
                               key=lambda l: int(l['frequency']),
                               reverse=True)

        image = generate_palette(sorted_colors, arguments.values,
                                 arguments.percentage)

        try:
            output, extension = arguments.output.rsplit('.', 1)
            image.save(f'{output}.{extension}')
        except OSError as oserror:
            print(
                f'Couldn\'t save the image for some reason\n{oserror.strerror}'
            )
Exemplo n.º 2
0
def main():
    parser_stdout_filepath = 'parser.stdout'

    options, args = parse_args()
    if len(args) != 1:
        sys.stderr.write("Please provide (only) one file to parse.")
        sys.exit(1)

    output_filepath = get_output_filepath(args)
    if os.path.isfile(output_filepath):
        # You can't parse a file with the same name twice, unless you
        # remove the parser output file first.
        os.remove(output_filepath)

    # re-route the print/stdout output of the parser to a file
    old_stdout = sys.stdout
    sys.stdout = open(parser_stdout_filepath, "w")
    try:
        results = feng_main(options, args)
        assert len(results) == 1 and isinstance(results[0], ParentedTree), \
            ("Expected one parse tree as a result, but got: {0}.\n"
             "Parser STDOUT was:\n{1}").format(
                results, get_parser_stdout(parser_stdout_filepath))
    finally:
        sys.stdout.close()
        sys.stdout = old_stdout

    parse_tree = results[0].__repr__() + "\n"
    sys.stdout.write(parse_tree)
    return parse_tree
Exemplo n.º 3
0
def main():
    log.startLogging(sys.stdout)

    opt = parse_args()

    control = Control(opt['control_port'], opt['tls_conf'])
    control.start_listen()

    from twisted.internet import reactor

    reactor.run()
Exemplo n.º 4
0
def main():
    log.startLogging(sys.stdout)

    opt = parse_args()

    control = Controller(opt['domain'], opt['host'], opt['control_port'],
                         opt['tls_conf'], opt['local_port'],
                         opt['tunnel_port'])
    control.connection()

    from twisted.internet import reactor

    reactor.run()
Exemplo n.º 5
0
def main():
    try:
        args = parse_args()
        setup_logging(args.quiet_mode)
        scrap(args)

    except KeyboardInterrupt as e:
        logging.error("KeyboardInterrupt")
        sys.exit(1)

    except Exception as e:
        logging.error(e, exc_info=True)
        sys.exit(1)
Exemplo n.º 6
0
def main():
    try:
        filepath, graph, color, timer, logic = parse_args()
        if timer:
            start = time.time()
        g = parse_file(filepath)
        solve(g, logic)
        if graph:
            g.print_graph()
        g.print_results(color)
        if timer:
            end = time.time()
            time_taken = '%s' % float('%.3g' % (end - start))
            print("time taken: {} seconds".format(time_taken))
    except:
        pass
Exemplo n.º 7
0
def parse_and_run_arguments(arguments=None):
    """
    Parse and run the arguments
    :param arguments: an arguments list or None to parse all
    """
    from datetime import datetime

    from parse import parse_args

    # parse command line arguments
    arguments = parse_args(arguments)
    command = arguments.command
    logging.debug("CIS started at: " + datetime.now().strftime("%Y-%m-%d %H:%M"))
    logging.debug("Running command: " + command)
    logging.debug("With the following arguments: " + str(arguments))

    # execute command
    cmd = commands[command]
    cmd(arguments)
Exemplo n.º 8
0
import traceback
import socket
import sys

from collections import defaultdict

# for SEGFAULT debugging
import neptune_mp_server
import sys
import os

sys.path.append('.')

# parse args
import parse
args = parse.parse_args()
for arg in vars(args):
    if getattr(args, arg) == "None":
        setattr(args, arg, None)


def eprint(*args, **kwargs):
    sys.stderr.write(','.join(args))


cluster, my_job_name, my_task_index = tf_server_from_slurm(
    ps_number=args.ps, port_number=args.tf_port)
if args.eval_node:
    cluster['worker'] = cluster['worker'][:-1]
if args.record_node:
    cluster['worker'] = cluster['worker'][:-1]
Exemplo n.º 9
0
        if i == 0:
            i += 1
            continue
        line_str = json.loads(line)
        for key in line_str:
            if key == "InsertTime":
                time = line_str[key].replace(
                    line_str[key].split('T')[0] + "T",
                    "").replace('.' + line_str[key].split('.')[-1], "")
                results[role][key].append(time)
                continue
            results[role][key].append(line_str[key])


if __name__ == "__main__":
    input_path, output_path = parse_args(sys.argv)
    result_file = os.path.join(output_path, result_file)

    files = os.listdir(input_path)
    print("Files:", files)
    for file in files:
        if not (file in valid_files): continue
        print(file)
        role = file.replace(".txt", "")
        results[role] = {}
        if not os.path.isdir(file):
            define_result(input_path, file, role)
            collect_result(input_path, file, role)
        duration = 0
        for duration_time in results[role]["DurationInMilliseconds"]:
            duration += duration_time
Exemplo n.º 10
0
import urllib3
import bs4
from bs4 import BeautifulSoup
import sys
import get
import parse
import utils

manager = urllib3.PoolManager()
str_time_deb = parse.get_time_flag(sys.argv, 1)
str_time_fin = parse.get_time_flag(sys.argv, 0)
urls = parse.parse_args(sys.argv, str_time_deb, str_time_fin)
for url in urls:
    ressource = manager.request('GET', url)
    contenu = ressource.data
    soupe = BeautifulSoup(contenu, 'html.parser')
    name = get.cinema(soupe)
    print('')
    print('-----------', name, '------------')
    print('')
    titles = soupe.find_all('h2', {'class': 'meta-title'})
    hours = soupe.find_all('div', {'class': 'hours'})
    real = soupe.find_all('div',
                          {'class': 'meta-body-item meta-body-direction'})
    length = soupe.find_all('div', {'class': 'meta-body-item meta-body-info'})
    nb_entries = min(len(titles), len(real), len(hours), len(length))
    for i in range(nb_entries):
        str_title = get.title(titles[i])
        str_real = get.real(real[i])
        str_length = get.length(length[i])
        str_hours = get.hours(hours[i])