예제 #1
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    init_colorama()
    cli = CLI()
    cli.run_trainer()
예제 #2
0
def init():
    os.environ['version'] = get_version()

    init_colorama()
    description()

    build_parser()
    args = get_args()

    levels = ['NOTSET', 'WARN', 'INFO', 'DEBUG']
    level = os.getenv('LOG_LEVEL')
    if not level:
        level = levels[args.log] if args.log else 'NOTSET'
    # end if
    if level != 'NOTSET':
        os.environ['debug_mode'] = 'yes'
        logging.basicConfig(
            level=logging.getLevelName(level),
            format=Fore.CYAN + '%(asctime)s ' + Fore.RED + '[%(levelname)s] ' +
            Fore.YELLOW + '(%(name)s)\n' + Fore.WHITE + '%(message)s' +
            Fore.RESET,
        )
        debug_mode(level)
    # end if

    if args.suppress:
        input_suppression()
        print(args)
    # end if

    requests.urllib3.disable_warnings(
        requests.urllib3.exceptions.InsecureRequestWarning)
예제 #3
0
파일: log.py 프로젝트: ugur-kellecioglu/bot
def configure_logger():
    init_colorama()
    logger = logging.getLogger()  # root logger
    logger.setLevel(logging.DEBUG)

    # Formatters
    datefmt = r"[%m/%d %H:%M:%S]"
    console_fmt = "%(asctime)s %(levelname)8s | %(message)s (%(filename)s:%(lineno)d)"
    console_formatter = ColoredFormatter(fmt=console_fmt, datefmt=datefmt)
    crash_report_fmt = (
        "%(asctime)s %(levelname)8s | %(message)s (%(filename)s:%(lineno)d)")
    crash_report_formatter = logging.Formatter(fmt=crash_report_fmt,
                                               datefmt=datefmt)

    # Filters
    class FilterGramAddictOnly(logging.Filter):
        def filter(self, record: LogRecord):
            return record.name.startswith("GramAddict")

    # Console handler (limited colored log)
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.DEBUG)
    console_handler.setFormatter(console_formatter)
    console_handler.addFilter(FilterGramAddictOnly())

    # Crash report handler (full raw log)
    global log_stream
    log_stream = StringIO()
    crash_report_handler = logging.StreamHandler(log_stream)
    crash_report_handler.setLevel(logging.DEBUG)
    crash_report_handler.setFormatter(crash_report_formatter)
    crash_report_handler.addFilter(FilterGramAddictOnly())

    logger.addHandler(console_handler)
    logger.addHandler(crash_report_handler)
예제 #4
0
    def setUp(self):
        """
        Setups everything needed for the tests.
        """

        init_colorama(autoreset=True)

        PyFunceble.load_config()

        StdoutBase.setUp(self)

        self.green_ascii = "\n".join(
            [
                f"{Fore.GREEN}{x}{Fore.RESET}"
                for x in PyFunceble.ASCII_PYFUNCEBLE.split("\n")
            ]
        )
        self.red_ascii = "\n".join(
            [
                f"{Fore.RED}{x}{Fore.RESET}"
                for x in PyFunceble.ASCII_PYFUNCEBLE.split("\n")
            ]
        )
        self.home_ascii = "\n".join(
            [
                f"{Fore.YELLOW}{x}{Fore.RESET}"
                for x in PyFunceble.ASCII_PYFUNCEBLE.split("\n")
            ]
        )

        self.cli_core = CLI()
예제 #5
0
파일: petablint.py 프로젝트: cthoyt/PEtab
def main():
    args = parse_cli_args()
    init_colorama(autoreset=True)

    ch = logging.StreamHandler()
    if args.verbose:
        ch.setLevel(logging.DEBUG)
    else:
        ch.setLevel(logging.WARN)
    ch.setFormatter(LintFormatter())
    logging.basicConfig(level=logging.DEBUG, handlers=[ch])

    logger.debug('Looking for...')
    if args.sbml_file_name:
        logger.debug('\tSBML model: ' + args.sbml_file_name)
    if args.condition_file_name:
        logger.debug('\tCondition table: ' + args.condition_file_name)
    if args.measurement_file_name:
        logger.debug('\tMeasurement table: ' + args.measurement_file_name)
    if args.parameter_file_name:
        logger.debug('\tParameter table: ' + args.parameter_file_name)

    try:
        problem = petab.Problem.from_files(
            sbml_file=args.sbml_file_name,
            condition_file=args.condition_file_name,
            measurement_file=args.measurement_file_name,
            parameter_file=args.parameter_file_name)
    except FileNotFoundError as e:
        logger.error(e)
        sys.exit(1)

    ret = petab.lint.lint_problem(problem)
    sys.exit(ret)
예제 #6
0
def main():
    init_colorama()
    os.environ['version'] = get_version()
    description()
    build_parser()
    args = get_args()

    if args.log:
        os.environ['debug_mode'] = 'true'
        levels = [None, logging.WARN, logging.INFO, logging.DEBUG]
        logging.basicConfig(level=levels[args.log])
        debug_mode(args.log)
        print(args)

    requests.urllib3.disable_warnings(
        requests.urllib3.exceptions.InsecureRequestWarning)

    try:
        if args.test:
            run_tests()
        else:
            start_app(spiders)

    except Exception as err:
        if args.log == 3:
            raise err
예제 #7
0
파일: cli.py 프로젝트: lensvol/tokelor
def main(source_path, nl, bare):
    """
    Visualize Python token stream produced by tokenize module.
    """
    init_colorama()
    with open(source_path, "r", newline="") as source:
        display_tokens(source.read(), show_newlines=nl, bare=bare)
예제 #8
0
 def __init__(self, timestamp, level, source, event, message):
     self._timestamp = timestamp
     self._level = level
     self._source = source
     self._event = event
     self._message = message
     self.__validate_log()
     init_colorama()
예제 #9
0
def main():
    """Run PEtab validator"""
    args = parse_cli_args()
    init_colorama(autoreset=True)

    ch = logging.StreamHandler()
    if args.verbose:
        ch.setLevel(logging.DEBUG)
    else:
        ch.setLevel(logging.WARN)
    ch.setFormatter(LintFormatter())
    logging.basicConfig(level=logging.DEBUG, handlers=[ch])

    if args.yaml_file_name:
        from petab.yaml import validate
        from jsonschema.exceptions import ValidationError
        try:
            validate(args.yaml_file_name)
        except ValidationError as e:
            logger.error("Provided YAML file does not adhere to PEtab "
                         f"schema: {e}")
            sys.exit(1)

        if petab.is_composite_problem(args.yaml_file_name):
            # TODO: further checking:
            #  https://github.com/ICB-DCM/PEtab/issues/191
            #  problem = petab.CompositeProblem.from_yaml(args.yaml_file_name)
            return

        problem = petab.Problem.from_yaml(args.yaml_file_name)

    else:
        logger.debug('Looking for...')
        if args.sbml_file_name:
            logger.debug(f'\tSBML model: {args.sbml_file_name}')
        if args.condition_file_name:
            logger.debug(f'\tCondition table: {args.condition_file_name}')
        if args.observable_file_name:
            logger.debug(f'\tObservable table: {args.observable_file_name}')
        if args.measurement_file_name:
            logger.debug(f'\tMeasurement table: {args.measurement_file_name}')
        if args.parameter_file_name:
            logger.debug(f'\tParameter table: {args.parameter_file_name}')

        try:
            problem = petab.Problem.from_files(
                sbml_file=args.sbml_file_name,
                condition_file=args.condition_file_name,
                measurement_file=args.measurement_file_name,
                parameter_file=args.parameter_file_name,
                observable_files=args.observable_file_name)
        except FileNotFoundError as e:
            logger.error(e)
            sys.exit(1)

    ret = petab.lint.lint_problem(problem)
    sys.exit(ret)
예제 #10
0
def main():
    init_colorama()

    try:
        return run(sys.argv)
    except EspHomePreprocessorError as e:
        error(e)
        return 1
    except KeyboardInterrupt:
        return 1
예제 #11
0
 def setup_logging(self):
     if self.o.no_color:
         init_colorama(strip=True)
     log.setLevel(logging.DEBUG if self.o.verbose else logging.INFO)
     ch = logging.StreamHandler(sys.stdout)
     ch.setLevel(logging.DEBUG if self.o.verbose else logging.INFO)
     if not self.o.no_color:
         ch.setFormatter(util.ColorFormatter('%(levelname)s %(message)s'))
     else:
         ch.setFormatter(logging.Formatter('%(levelname)s %(message)s'))
     log.addHandler(ch)
예제 #12
0
def main():
    """Generate HDF5 file based on CLI options"""
    init_colorama(autoreset=True)

    args = parse_cli_args()

    petab_problem = petab.Problem.from_yaml(args.petab_yaml)
    amici_model = get_amici_model(model_name=args.model_name,
                                  model_dir=args.model_dir)
    h5gen = HDF5DataGenerator(petab_problem=petab_problem,
                              amici_model=amici_model)
    h5gen.generate_file(args.hdf5_file_name)
예제 #13
0
def configure():
    init_colorama()
    mode = sys.argv[1].lower() if len(sys.argv) > 1 else None

    if mode == '-v' or mode == '--verbose':
        os.environ['debug_mode'] = 'true'
        print(Fore.RED, Icons.SOUND, 'IN VERBOSE MODE', Fore.RESET)
        print('-' * 60)
        logging.basicConfig(level=logging.DEBUG)
    # end if
    requests.urllib3.disable_warnings(
        requests.urllib3.exceptions.InsecureRequestWarning)
예제 #14
0
def print_updates_to_console(updates: List["Update"]) -> None:
    init_colorama()
    for update in updates:
        print(f"{Style.BRIGHT}[{update.title}]{Style.RESET_ALL}\n")
        for image in update.images:
            print(
                MAGIC_IMAGE_LINE.format(
                    encoded_image=base64.b64encode(image).decode("ascii")
                )
            )
            print()
            if update.description:
                print(f"{Fore.LIGHTGREEN_EX}{update.description}{Style.RESET_ALL}\n")
예제 #15
0
def main():
    args = parse_args()
    if args.verbosity == 3:
        init_logging(logging.DEBUG)
    elif args.verbosity == 2:
        init_logging(logging.INFO)
    elif args.verbosity == 1:
        init_logging(logging.WARNING)
    elif args.verbosity == 0:
        init_logging(logging.ERROR)
    logger.debug(f"args: {args}")

    init_colorama(strip=not args.force_colors)
    if args.circus_cmd == "status":
        print(
            handle_status(
                circus_args=args.circus_args,
                dry_run=args.dry_run,
                allow_missing_systemd_unit=args.allow_missing_systemd_unit,
                verbose=args.verbosity > 1,
                circusctl_path=args.circusctl_path,
                get_systemd_status=args.get_systemd_status,
                short=args.short,
            ))
    else:
        circus_config_path = Path("/", "users", USER, "circus", HOST,
                                  "circus.ini")
        circusctl_cmd = _circus(
            circus_config_path,
            circus_args=[args.circus_cmd, *args.circus_args],
            dry_run=args.dry_run,
            circusctl_path=args.circusctl_path,
        )
        if args.verbosity > 1:
            circus_cmd_str = f"$ {shlex.join(circusctl_cmd.args)}"
        else:
            circus_cmd_str = args.circus_cmd
        if circusctl_cmd.returncode == 0:

            print(
                f"{Fore.GREEN}{USER}@{HOST}: Circus command '{circus_cmd_str}': SUCCESS{Style.RESET_ALL}"
            )
            for line in circusctl_cmd.stdout.splitlines():
                print(f"  {line}")
        else:
            print(
                f"{Fore.RED}{USER}@{HOST}: Circus command '{circus_cmd_str}': FAILED{Style.RESET_ALL}"
            )
            print(circusctl_cmd.stderr, file=sys.stderr)
예제 #16
0
def main():
    """Generate HDF5 file based on CLI options"""
    init_colorama(autoreset=True)
    coloredlogs.DEFAULT_LEVEL_STYLES['debug'] = dict(color='white',
                                                     faint='true')
    coloredlogs.install(level='DEBUG', logger=logger)

    args = parse_cli_args()

    petab_problem = petab.Problem.from_yaml(args.petab_yaml)
    amici_model = get_amici_model(model_name=args.model_name,
                                  model_dir=args.model_dir)
    h5gen = HDF5DataGenerator(petab_problem=petab_problem,
                              amici_model=amici_model)
    h5gen.generate_file(args.hdf5_file_name)
예제 #17
0
def run() -> None:
    init_colorama()
    try:
        opts = load_options(HELP)
        if opts['--version']:
            print(VERSION)
            return
        if opts['--help']:
            print(HELP)
            return
        prefs = load_prefs(PREFS_FILE)
        interpolated_opts = interpolate_variables(opts, prefs)
        sesh = get_session(interpolated_opts, prefs, PREFS_FILE)
        resp = send_request(sesh, prefs, interpolated_opts, PREFS_FILE)
        print_response(resp, prefs)
    except APIBuddyException as err:
        exit_with_exception(err)
예제 #18
0
def main():
    args = parse_cli_args()

    init_colorama(autoreset=True)

    # First check for valid PEtab
    pp = petab.Problem.from_files(sbml_file=args.sbml_file_name,
                                  condition_file=args.condition_file_name,
                                  measurement_file=args.measurement_file_name,
                                  parameter_file=args.parameter_file_name)
    petab.lint_problem(pp)

    import_model(args.sbml_file_name,
                 args.condition_file_name,
                 args.measurement_file_name,
                 model_output_dir=args.model_output_dir,
                 compile=args.compile,
                 verbose=True)
예제 #19
0
파일: log.py 프로젝트: ufo2011/bot
def configure_logger(debug, username):
    global g_session_id
    global g_log_file_name
    global g_logs_dir
    global g_file_handler
    global g_log_file_updated

    console_level = logging.DEBUG if debug else logging.INFO

    g_session_id = uuid4()
    g_logs_dir = "logs"
    if username:
        g_log_file_name = f"{username}.log"
        g_log_file_updated = True
    else:
        g_log_file_name = f"{g_session_id}.log"
        g_log_file_updated = False

    init_colorama()

    # Root logger
    root_logger = logging.getLogger()
    root_logger.setLevel(logging.DEBUG)

    # Console logger (limited but colored log)
    console_handler = logging.StreamHandler()
    console_handler.setLevel(console_level)
    console_handler.setFormatter(
        ColoredFormatter(
            fmt="%(asctime)s %(levelname)8s | %(message)s", datefmt="[%m/%d %H:%M:%S]"
        )
    )
    console_handler.addFilter(LoggerFilterGramAddictOnly())
    root_logger.addHandler(console_handler)

    # File logger (full raw log)
    if not os.path.exists(g_logs_dir):
        os.makedirs(g_logs_dir)
    g_file_handler = create_log_file_handler(f"{g_logs_dir}/{g_log_file_name}")
    root_logger.addHandler(g_file_handler)

    init_logger = logging.getLogger(__name__)
    init_logger.debug(f"Initial log file: {g_logs_dir}/{g_log_file_name}")
예제 #20
0
def main():
    parser = ArgumentParser()
    parser.add_argument('--name', type=str, default='')
    parser.add_argument('--bots', type=str, default='NRR')
    parser.add_argument('--no-color', action='store_true', default=False)
    args = parser.parse_args()

    global COLORING
    COLORING = not args.no_color
    if COLORING:
        init_colorama()

    bots = args.bots
    name = args.name

    if not name:
        name = io.dialog('Enter your name', lambda n: n.strip() != '')

    game = Game(Deck(standard_chars()), Deck(simple_districts()))
    game_controller = GameController(game)

    assert 1 <= len(bots) <= 3
    assert all(b in 'NR' for b in bots)

    player = game.add_player(name)
    game_controller.set_player_controller(player, TermPlayerController())

    game_controller.add_listener(TermGamePlayListener(player, game))

    bot_factory = {'R': RandomBotController, 'N': NaiveBotController}
    for i, b in enumerate(bots):
        bot = game.add_player('bot{}'.format(i + 1))
        game_controller.set_player_controller(bot, bot_factory[b]())

    while not game_controller.game_over:
        game_controller.play()

    print('\n----------------------\nGame over!\n')
    for player in game.players:
        print('{plr} scored {score}'.format(plr=player.name,
                                            score=rules.score(player, game)))
    print('Winner is {plr}'.format(plr=game_controller.winner.name))
 def __init__(self):
     init_colorama()
     self.talking='setup manager'
     self.step_title('Welcome to the PyOS software installer')
     check=self.ask('Do you want to proceed ? (y/n)')
     if check=='y':
         try:
             import panda3d
             self.step_title('The panda3d library is already installed')
         except:
             self.step_title('Oops, it looks like the panda3d library is not available on your machine')
             check2=self.ask('Do you want to install it ? Doing so will allow you to run the code directly from the python IDE (y/n)')
         check1=self.ask("Do you want to download the last stable release ? It is recommended to do so if you're not a developer (y/n)")
         if check1=='y':
             self.step_title('Download has started...')
             self.step_title('Please be patient, the download speed depends on your internet connection.\nFile size is approximately 500MB')
             urllib.request.urlretrieve(URL,CWD+'\\downloads\\update.zip')
             '''
             zipObject=ZipFile(CWD+'\\downloads\\update.zip','r')
             zipObject.extractall(path=CWD+'\\downloads\\update')
             '''
     else:
         sys.exit(0)
예제 #22
0
파일: __init__.py 프로젝트: sralloza/vcm
def download(nthreads=20,
             killer=True,
             status_server=True,
             discover_only=False):
    """

    Args:
        nthreads (int, optional): number of threads to use. Defaults to 20.
        killer (bool, optional): if True, an extra thread will be launched
            to detect key pressings, shuch as K for kill the app. Defaults to True.
        status_server (bool, optional): if true, a http server will be opened
            in port 80 to show the status of each thread. Defaults to True.
        discover_only (bool, optional): if true, it will only discover the subjects,
            without downloading anything. Defaults to False.
    """

    logger = logging.getLogger(__name__)
    logger.info(
        "Launching notify(nthreads=%r, killer=%s, status_server=%s, discover_only=%s)",
        nthreads,
        killer,
        status_server,
        discover_only,
    )

    init_colorama()

    queue = Queue()
    threads = start_workers(queue, nthreads, killer=killer)

    if status_server:
        runserver(queue, threads)

    with Connection():
        find_subjects(queue, discover_only=discover_only)
        logger.debug("Waiting for queue to empty")
        queue.join()
예제 #23
0
def start(root_folder=None, nthreads=None, timeout=None, no_killer=False):
    """Starts the app.

    Args:
        root_folder (str): folder where files will be downloaded.
        nthreads (int): number of threads to start.
        timeout (int): number of seconds before discarting TCP connection.
        no_killer (bool): desactivate Killer thread.
    """

    init_colorama()

    if not nthreads:
        nthreads = 50

    if root_folder:
        Options.set_root_folder(root_folder)

    if timeout:
        Options.set_timeout(timeout)

    initial_time = time.time()
    main_logger = logging.getLogger(__name__)
    main_logger.info('STARTING APP')
    main_logger.debug('Starting downloader')
    downloader = Downloader()
    main_logger.debug('Starting queue')
    queue = Queue()

    main_logger.debug('Launching subjects finder')
    find_subjects(downloader, queue, nthreads, no_killer)

    main_logger.debug('Waiting for queue to empty')
    queue.join()

    final_time = time.time() - initial_time
    main_logger.info('VCD executed in %s', seconds_to_str(final_time))
예제 #24
0
파일: wrappers.py 프로젝트: redodo/tortilla
        '    {text}\n',
        Style.RESET_ALL
    ])
}


#: The maximum length of a response displayed in a debug message
DEBUG_MAX_TEXT_LENGTH = 100


if os.name == 'nt' and run_from_ipython():
    # IPython stops working properly when it loses control of
    # `stdout` on Windows. In this case we won't enable Windows
    # color support and we'll strip out all colors from the debug
    # messages.
    init_colorama(wrap=False)
else:
    init_colorama()


class Client(object):
    """Wrapper around the most basic methods of the requests library."""

    def __init__(self, debug=False, cache=None, **kwargs):
        self.headers = Bunch()
        self.debug = debug
        self.cache = cache if cache else DictCache()
        self.cache = CacheWrapper(self.cache)
        self.session = requests.session()
        self._last_request_time = None
        self.defaults = kwargs
예제 #25
0
#! /usr/bin/env python3
import logging
from flask.ext.script import Manager, Command

from App.App import create_app
from commands.get_deps import GetDeps
from commands.dbutils import InitDB, UpdateDB, FixFont
from commands.run_tests import RunTests

from colorama import init as init_colorama
from colorama import Fore, Back, Style
init_colorama(autoreset=True)

from flask.ext.assets import ManageAssets

manager = Manager(create_app)
manager.add_option('-c', '--app-config', dest='config', required=False)
manager.add_command('get_deps', GetDeps())
manager.add_command("assets", ManageAssets())
manager.add_command('initdb', InitDB())
manager.add_command('updatedb', UpdateDB())
manager.add_command('fixfont', FixFont())
manager.add_command('test', RunTests)

if __name__ == '__main__':
    log_fmt = '[notMyType][%(levelname)s] %(lineno)d in %(funcName)s - %(message)s'
    logging.basicConfig(format=log_fmt,
                        level=logging.DEBUG)
    manager.run()
예제 #26
0
파일: cli.py 프로젝트: zorroroot/bscan
async def main(args: Optional[List[str]] = None) -> int:
    """Main entry point for `bscan`'s command-line interface.

    Args:
        args: Custom arguments to override ``sys.argv``.

    Returns:
        The exit code of the program.

    """
    try:
        init_colorama()

        if not good_py_version():
            print_w_d1('Running with Python version ', py_version_str(),
                       'but this program is only tested with Python 3.6')

        opts = get_parsed_args(args)
        print_i_d1('Initializing configuration from command-line arguments')
        mc = opts.max_concurrency
        try:
            mc = (20 if mc is None else int(mc))
            if mc < 1:
                raise ValueError
        except ValueError:
            raise BscanConfigError(
                'Invalid `--max-concurrency` positive integer value '
                'received: ' + str(mc))

        async with Sublemon(max_concurrency=mc) as subl:
            await write_db_value('sublemon', subl)
            await init_config(opts)

            print_color_info()

            if not opts.targets:
                print_e_d1('No targets specified; use `--help` to figure '
                           'out what you\'re doing')
                return 1

            # TODO: create a full list of targets from network address and
            #       --ping-sweep filtering
            targets = []
            _target_set: Set[str] = set()
            for candidate in opts.targets:
                if candidate in _target_set:
                    print_w_d1(
                        'Target ', candidate, ' has already been added as a '
                        'target; skipping another attempted addition')
                    continue
                elif is_valid_ip_host_addr(candidate):
                    pass
                elif is_valid_hostname(candidate):
                    pass
                elif is_valid_ip_net_addr(candidate):
                    print_w_d1(
                        'Network scanning not yet supported; '
                        'skipping network: ', candidate)
                    continue
                else:
                    print_e_d1('Unable to parse target ', candidate,
                               ', skipping it')
                    continue

                try:
                    create_dir_skeleton(candidate)
                except BscanForceSkipTarget as e:
                    print_e_d1(e.message)
                    print_e_d1(candidate, ': skipping this target')
                    continue

                targets.append(candidate)
                _target_set.add(candidate)

            if not targets:
                print_e_d1('No valid targets specified')
                return 1

            print_i_d1('Kicking off scans of ', len(targets), ' targets')
            tasks = [scan_target(target) for target in targets]
            if get_db_value('status-interval') > 0:
                tasks.append(status_update_poller())
            await asyncio.gather(*tasks)

            print_i_d1('Completed execution')
            return 0
    except BscanConfigError as e:
        print_e_d1('Configuration error: ', e.message)
        return 1
    except BscanForceSilentExit as e:
        return 1
    except BscanInternalError as e:
        print_e_d1('Internal error: ', e.message)
        return 1
    except BscanSubprocessError as e:
        print_e_d1('Error handling subprocess: ', e.message)
        return 1
    except BscanError as e:
        print_e_d1('This should not be reached!')
        return 1
    except Exception as e:
        print_e_d1('Received unexpected exception; re-raising it.',
                   file=sys.stderr)
        raise e
예제 #27
0
from colorama import Fore, Back, Style
from colorama import init as init_colorama
init_colorama()

stopState = False
prom = "dogrex> "
inpt = ""

print("Welcome to DogRex, the dog simulator!")


def starting():
    print("What thing do you want to make?")
    print("\n1. New game\n2. Exit\n")
    return input(prom)


if __name__ == "__main__":
    try:
        while stopState == False:
            if starting() == 1:
                print(
                    "For now, this game is in early access and you can't play for now..."
                )
                exit()
            else:
                print("Goodbye!")
                exit()
    except KeyboardInterrupt:
        print()
        print("Goodbye!")
예제 #28
0
파일: demo.py 프로젝트: Roadmaster/checkbox
def main():
    init_colorama()
    try:
        ExampleApp().start()
    finally:
        deinit_colorama()
예제 #29
0
#! /usr/bin/env python3
import logging
from flask.ext.script import Manager, Command

from App.App import create_app
from commands.get_deps import GetDeps
from commands.dbutils import InitDB, UpdateDB, FixFont
from commands.run_tests import RunTests

from colorama import init as init_colorama
from colorama import Fore, Back, Style
init_colorama(autoreset=True)

from flask.ext.assets import ManageAssets

manager = Manager(create_app)
manager.add_option('-c', '--app-config', dest='config', required=False)
manager.add_command('get_deps', GetDeps())
manager.add_command("assets", ManageAssets())
manager.add_command('initdb', InitDB())
manager.add_command('updatedb', UpdateDB())
manager.add_command('fixfont', FixFont())
manager.add_command('test', RunTests)

if __name__ == '__main__':
    log_fmt = '[notMyType][%(levelname)s] %(lineno)d in %(funcName)s - %(message)s'
    logging.basicConfig(format=log_fmt, level=logging.DEBUG)
    manager.run()
예제 #30
0
def main(argv=None):
	init_colorama()
	global DEBUG

	if argv is None:
		argv = sys.argv

	parser = OptionParser()
	parser.set_defaults(action=None)
	parser.add_option("--quiet", "-q", dest="debug", action="store_false", default=True, help="Suppress nice human-readable reporting")
	(options, urls) = parser.parse_args(args=argv)

	DEBUG = options.debug

	urls[:1] = []
	debug("Your input files are: ")
	for url in urls:
		debug("\t%s" % url)


	for url in urls:
		debug(red("-" * len("URL: %s"%url)))
		debug(red("URL: %s" % url))
		debug(red("-" * len("URL: %s"%url)))

		try:
			d = get_distiller(url)
		except:
			print "Don't know how to handle URL: %s" % url
			continue

		for doc in d.docs:
			if doc is None:
				continue
			debug(green("Adding to index: %(url)s" % doc))

			# Depending on the backend, the blob will either be str
			# or unicode:
			#   Gollum:  unicode
			#   RT:      str
			#   Map:     str
			#   Provsys: str
			#
			# We need to test for this because blindly encode()ing
			# the blob will result in errors if it's already a
			# UTF8 str.
			trimmed_blob = doc['blob'][:400]
			if type(trimmed_blob) is str:
				debug(blue("400 chars of blob: {0}".format(trimmed_blob)))
			else: # unicode
				debug(blue(u"400 chars of blob: {0}".format(trimmed_blob)))
			add_to_index(doc)
			debug(green("Success!"))
			debug("")

			debug(red("-------"))
			debug(red("Now reprinting the document we just indexed"))
			document_just_added = get_from_index(doc['url'])['_source']
			for key in sorted(document_just_added):
				if not isinstance(document_just_added[key], (str,unicode)):
					document_just_added[key] = str(document_just_added[key])
				debug(green(key.capitalize()))
				debug(u"\t{0}".format(document_just_added[key][:1000]).encode('utf8'))
			debug("")


	return 0
예제 #31
0
    logger.debug('Running script.')

    def err(ex):
        logger.warn(str(ex), exc_info=debug)

    script.on('line.error', err)
    script.on('action.error', err)
    script.dry_run = dry_run

    try:
        script.run()
    except StorageError as ex:
        if debug:
            logger.exception('Storage error running script: %s' % ex.args[0])
        else:
            click.echo('Storage error running script: %s' % ex.args[0])

        raise SystemExit(1)
    except (ScriptError, FixtureError) as ex:
        if debug:
            logger.exception('Runtime error with script: %s' % ex.args[0])
        else:
            click.echo('Runtime error with script: %s' % ex.args[0])

        raise SystemExit(1)


# Strip colors if stdout is redirected
init_colorama(strip=not sys.stdout.isatty())
예제 #32
0
파일: demo.py 프로젝트: Roadmaster/checkbox
def main():
    init_colorama()
    try:
        ExampleApp().start()
    finally:
        deinit_colorama()
예제 #33
0
def main(args=None):
    """Main entry point for `donatello`'s command-line interface.

    Args:
        args (List[str]): Custom arguments if you wish to override sys.argv.

    Returns:
        int: The exit code of the program.

    """
    try:
        init_colorama()
        opts = get_parsed_args(args)

        if opts.bad_chars is not None:
            bad_chars = _parse_bytes(opts.bad_chars, check_dups=True)
        else:
            bad_chars = b''
        bad_chars_as_ints = tuple(int(bc) for bc in bad_chars)

        if opts.max_factors is not None:
            max_factors = _parse_max_factors(opts.max_factors)
        else:
            max_factors = 2

        if opts.ops is not None:
            ops = _parse_ops(opts.ops)
        else:
            ops = IMPLEMENTED_OPS

        if opts.command not in (
                'factor',
                'encode',
        ):
            raise DonatelloConfigurationError(
                'must specify either `factor` or `encode`; `' + opts.command +
                '` is invalid')

        if opts.target == '-':
            # TODO: https://docs.python.org/3/library/fileinput.html
            pass
        else:
            target = opts.target

        if opts.command == 'factor':
            value = _parse_target_hex(target)
            print_i('Attempting to factor target value ', format_dword(value))

            for num_factors in range(2, max_factors + 1):
                factors = factor_by_byte(value,
                                         bad_chars_as_ints,
                                         usable_ops=ops,
                                         num_factors=num_factors)
                if factors is not None:
                    print_i('Found factorization!')
                    res = ['    0x00000000']
                    for f in factors:
                        res.append('{0: <3}'.format(f.operator) + ' ' +
                                   format_dword(f.operand))
                    print('\n'.join(res))
                    break
            else:
                print_e('Unable to find any factors')
        elif opts.command == 'encode':
            payload = _parse_bytes(target)
            print_i('Attempting to encode payload...')
            asm = encode_x86_32(payload, bad_chars, max_factors=max_factors)
            print_i('Successfully encoded payload!')
            print(asm)

        return 0
    except (DonatelloCannotEncodeError, DonatelloNoPossibleNopsError) as e:
        print_e('Failed to factor/encode the specified target: ', e)
        return 1
    except DonatelloConfigurationError as e:
        print_e('Configuration error: ', e)
        return 1
    except DonatelloNoPresentBadCharactersError:
        print_e('No bad characters present in the specified payload; ',
                'use the -f/--force flag to bypass this check')
        return 1
    except DonatelloError as e:
        print_e('This should not be reached! See below for error.')
        print_e(e)
        return 1
    except Exception as e:
        print_e('Received unexpected exception; re-raising it.')
        raise e
예제 #34
0
        for subdir in subdirs:
            terminfo_path = os.path.join(terminfo_dir, subdir, term)
            try:
                f = open(terminfo_path, 'rb')
                break
            except IOError as e:
                if e.errno != errno.ENOENT:
                    raise

    return f


if os.name == 'nt':
    from colorama import init as init_colorama, AnsiToWin32

    init_colorama(wrap=False)
    STREAM = AnsiToWin32(sys.stderr).stream
    SUPPORTS_COLOR = True
else:
    if os.getenv('FORCE_COLOR', None) == '1':
        SUPPORTS_COLOR = True
    else:
        f = get_terminfo_file()
        if f is not None:
            with f:
                # f is a valid terminfo; seek and read!
                magic_number = struct.unpack('<h', f.read(2))[0]

                if magic_number == 0x11A:
                    # the opened terminfo file is valid.
                    offset = 2 + 10  # magic number + size section (the next thing we read from)
예제 #35
0
파일: utils.py 프로젝트: eea/eea.eggmonkey
from colorama import Fore, init as init_colorama
import os

EGGMONKEY = Fore.RED + "EGGMONKEY: " + Fore.RESET
EXTERNAL = Fore.BLUE + "RUNNING: " + Fore.RESET

init_colorama()


class Error(Exception):
    """ EggMonkey runtime error """


def find_file(path, name):
    for root, _dirs, names in os.walk(path):
        if name in names:
            return os.path.join(root, name)

    raise ValueError("File not found: %s in %s" % (name, path))


def which(program):
    """Check if an executable exists"""

    def is_exe(fpath):
        return os.path.exists(fpath) and os.access(fpath, os.X_OK)

    fpath, _fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program