Exemple #1
0
    def test_signal_argument(self):
        args = cli.parse_arguments(['--template', 'test.template', '--signal', 'target-container', 'HUP'])

        self.assertEqual(args.signal, [['target-container', 'HUP']])

        args = cli.parse_arguments(['--template', 'test.template',
                                    '--signal', 'target-container', 'HUP',
                                    '--signal', 'second-container', 'INT'])

        self.assertEqual(args.signal, [['target-container', 'HUP'], ['second-container', 'INT']])
Exemple #2
0
    def test_restart_argument(self):
        args = cli.parse_arguments(['--template', 'test.template', '--restart', 'target-container'])

        self.assertEqual(args.restart, ['target-container'])

        args = cli.parse_arguments(['--template', 'test.template',
                                    '--restart', 'target-container',
                                    '--restart', 'second-container'])

        self.assertEqual(args.restart, ['target-container', 'second-container'])
Exemple #3
0
def main():
    args = parse_arguments()

    if args.getmousepos:
        utils.getjoinposn()
    elif args.updatepass is not None:
        utils.update_pass(args.updatepass)
    elif args.append is not None:
        utils.append(args.append)
    elif args.changepass is not None:
        utils.change_pass(args.changepass)
    else:
        config = configparser.ConfigParser()
        config.read("data.ini")
        joinposn = config["VALUES"]["join"].split(", ")
        try:
            joinposn = [int(x) for x in joinposn]
        except ValueError:
            # fmt: off
            print("Oops, it looks like you haven't"
                  "set the positon of join button.")
            # fmt: on

        subject = utils.get_subject() if args.subject is None else args.subject
        zoom_id, zoom_pass = utils.get_credentials(subject)
        utils.auto_type(zoom_id, zoom_pass, joinposn)
def test_command(mock_args):
    parse_arguments()
    mock_args().add_argument.assert_called()
    mock_args().add_argument.assert_any_call(
        "-l",
        "--link",
        type=str,
        help="URL link to Wikipedia page",
    )
    mock_args().add_argument.assert_any_call(
        "-d",
        "--directory",
        type=str,
        help="Name of directory where file will be save",
    )
    mock_args().add_argument.assert_any_call(
        "-n",
        "--number-of-links",
        type=int,
        help="The number of url links that will be queued for processing",
    )
    mock_args().add_argument.assert_any_call(
        "-mw", "--max-workers", type=int, help="The humber of work threads"
    )
    mock_args().add_argument.assert_any_call(
        "-ll",
        "--logging-level",
        type=str,
        default="INFO",
        help="level for logging module",
    )
    mock_args().add_argument.assert_any_call(
        "-c",
        "--config",
        type=str,
        default="../etc/config.ini",
        help="config file for config parser",
    )
    mock_args().parse_args.assert_called_once()
Exemple #5
0
    def test_prints_help(self):
        import sys
        sys_stdout = sys.stdout

        try:
            class _CapturingOutput(object):
                def __init__(self):
                    self.data = ''

                def write(self, data):
                    self.data += data

            sys.stdout = _CapturingOutput()

            try:
                cli.parse_arguments(['--help'])

            except SystemExit as ex:
                self.assertEqual(0, ex.code)

            self.assertIn('Template generator based on Docker runtime information', sys.stdout.data)

        finally:
            sys.stdout = sys_stdout
                html = self.url_downloader(self.url_link)
                urls = links_extractor(html)
                for link in urls:
                    self.queue.put(link)
                with ThreadPoolExecutor(
                        max_workers=self.max_workers) as executor:
                    for thread in range(self.max_workers):
                        executor.submit(self.worker)
                # add url and last modified date to database
                save_url_links_to_database(db, self.fetched_links, logger)
                self.fetched_links.clear()
            time.sleep(int(config["sync"]["timeout"]))


if __name__ == "__main__":
    args = parse_arguments()
    config = ConfigParser()
    config.read(args.config)

    if os.path.exists(DEFAULT_CONFIG_PATH):
        with open(DEFAULT_CONFIG_PATH, "rt") as f:
            logger_config = json.load(f)
            logger_config["loggers"]["main"]["level"] = args.logging_level
        logging.config.dictConfig(logger_config)
    else:
        logging.basicConfig(level=logging.INFO)

    logger = logging.getLogger("main")

    max_workers = int(args.max_workers
                      or config["file_handler"]["max_workers"])
Exemple #7
0

def tdiff(t1, t2):
    # calculates the diff of t1 and t2
    # t1 and t2 are datetime.datetime objects
    # diff is a timedelta
    diff = t1 - t2
    return abs(diff.total_seconds())


if __name__ == '__main__':
    # When the script is executed or invoked via python -m,
    # parse command-line arguments and setup the logger
    # args/log _must_ exist at a module level when not invoking
    # at the command line.
    this.app_args = parse_arguments(defaults)
    check_args(app_args)
    this.log = setup_logger(app_args)

    stats_q = Queue()  # Statistics Queue - might not be necessary
    form_q = Queue()  # Queue for sending forms to the FormCrawler
    this.stop = multiprocessing.Event()  # Event to handle kill signalling
    items = stats_q, form_q, stop  # Application control items

    try:
        app = PokeyCrawl(*items)
        app.init_stats(Stats())
        app.prep_workers()
        color_log('[!] Preparations complete, crawl commencing', Color.MSG,
                  'info')
        app.execute(True)
Exemple #8
0
    def test_parse_arguments(self):
        args = cli.parse_arguments(['--template', 'test.template', '--target', '/etc/target.file'])

        self.assertEqual(args.template, 'test.template')
        self.assertEqual(args.target, '/etc/target.file')
Exemple #9
0
    def test_parse_arguments_defaults(self):
        args = cli.parse_arguments(['--template', 'test.template'])

        self.assertEqual(args.template, 'test.template')
        self.assertIsNone(args.target, None)
Exemple #10
0
    fmt = '%Y-%m-%d::%T:%z'
    return timestamp.strftime(fmt)

def tdiff(t1,t2):
    # calculates the diff of t1 and t2
    # t1 and t2 are datetime.datetime objects
    # diff is a timedelta
    diff = t1-t2
    return abs(diff.total_seconds())

if __name__=='__main__':
    # When the script is executed or invoked via python -m,
    # parse command-line arguments and setup the logger
    # args/log _must_ exist at a module level when not invoking
    # at the command line.
    this.app_args = parse_arguments(defaults)
    check_args(app_args)
    this.log = setup_logger(app_args)

    stats_q = Queue() # Statistics Queue - might not be necessary
    form_q = Queue() # Queue for sending forms to the FormCrawler
    this.stop = multiprocessing.Event() # Event to handle kill signalling
    items = stats_q,form_q,stop # Application control items

    try:
        app = PokeyCrawl(*items)
        app.init_stats(Stats())
        app.prep_workers()
        color_log('[!] Preparations complete, crawl commencing',Color.MSG,'info')
        app.execute(True)
        color_log('[!] Application Executed',Color.MSG,'info')