def get_parser():
	"""Return an argument parser for this module."""
	parser = argparse.ArgumentParser(parents=[ndb.get_parser()],
	description=__doc__)

	parser.add_argument('service_id_file', type=argparse.FileType('r'), nargs='?', default=DEFAULT_INFILE,
				help="File that contains a list of service names - one per line. Will read from stdin by default.")
	parser.add_argument('--scans', '--scans-per-sec', '-s', nargs='?', default=DEFAULT_SCANS, const=DEFAULT_SCANS, type=int,
				help="How many scans to run per second. Default: %(default)s.")
	parser.add_argument('--timeout', '--wait', '-w', nargs='?', default=DEFAULT_WAIT, const=DEFAULT_WAIT, type=int,
				help="Maximum number of seconds each scan will wait (asychronously) for results before giving up. Default: %(default)s.")
	parser.add_argument('--sni', action='store_true', default=False,
				help="use Server Name Indication. See section 3.1 of http://www.ietf.org/rfc/rfc4366.txt.\
				Default: \'%(default)s\'")
	parser.add_argument('--logfile', action='store_true', default=False,
				help="Log to a file on disk rather than standard out.\
				A rotating set of {0} logs will be used, each capturing up to {1} bytes.\
				File will written to {2}\
				Default: \'%(default)s\'".format(
					notary_logs.LOGGING_BACKUP_COUNT + 1,
					notary_logs.LOGGING_MAXBYTES,
					notary_logs.get_log_file(LOGFILE)))
	loggroup = parser.add_mutually_exclusive_group()
	loggroup.add_argument('--verbose', '-v', default=False, action='store_true',
				help="Verbose mode. Print more info about each scan.")
	loggroup.add_argument('--quiet', '-q', default=False, action='store_true',
				help="Quiet mode. Only print system-critical problems.")
	return parser
Пример #2
0
def get_parser():
	"""Return an argument parser for this module."""
	parser = argparse.ArgumentParser(parents=[ndb.get_parser()],
	description=__doc__,
	epilog="This module can be used to generate a list of all services considered 'live' or 'dead'.")

	parser.add_argument('output_file', type=argparse.FileType('w'), nargs='?', default=DEFAULT_OUTFILE,
				help="File to write data to. Use '-' to write to stdout. Writing to stdout is the default if no file is given.")
	listgroup = parser.add_mutually_exclusive_group()
	listgroup.add_argument('--all', '-a', action='store_true', default=False,
				help="List all services. This is the default if no action is specified.")
	listgroup.add_argument('--newer', '--newest', '--new', metavar=DAYS_META_NAME, type=int, nargs='?', default=None, const=DEFAULT_DAYS,
				help="Only list services with an observation newer than '%s' days. Default: %s." % (DAYS_META_NAME, DEFAULT_DAYS))
	listgroup.add_argument('--older', '--oldest', '--old', metavar=DAYS_META_NAME, type=int, nargs='?', default=None, const=DEFAULT_DAYS,
				help="Only list services with a MOST RECENT observation that is older than than '%s' days. Default: %s." % (DAYS_META_NAME, DEFAULT_DAYS))
	return parser
Print a list of service names from a network notary database, one per line.
Data can be filtered based on the last time the notary successfully observed
a key from each service.
"""

import time
import argparse

from notary_db import ndb


DAYS_META_NAME = 'Days'
DEFAULT_DAYS = 10
DEFAULT_OUTFILE = "-"

parser = argparse.ArgumentParser(parents=[ndb.get_parser()],
description=__doc__,
epilog="This module can be used to generate a list of all services considered 'live' or 'dead'.")

parser.add_argument('output_file', type=argparse.FileType('w'), nargs='?', default=DEFAULT_OUTFILE,
			help="File to write data to. Use '-' to write to stdout. Writing to stdout is the default if no file is given.")
listgroup = parser.add_mutually_exclusive_group()
listgroup.add_argument('--all', '-a', action='store_true', default=False,
			help="List all services. This is the default if no action is specified.")
listgroup.add_argument('--newer', '--newest', '--new', metavar=DAYS_META_NAME, type=int, nargs='?', default=None, const=DEFAULT_DAYS,
			help="Only list services with an observation newer than '%s' days. Default: %s." % (DAYS_META_NAME, DEFAULT_DAYS))
listgroup.add_argument('--older', '--oldest', '--old', metavar=DAYS_META_NAME, type=int, nargs='?', default=None, const=DEFAULT_DAYS,
			help="Only list services with a MOST RECENT observation that is older than than '%s' days. Default: %s." % (DAYS_META_NAME, DEFAULT_DAYS))

args = parser.parse_args()
Пример #4
0
	service_count = len(services)
	if (service_count > 0):
		print("Found {0} services. Adding to database.".format(service_count))
		ndb.insert_bulk_services(services.keys())
	else:
		print("No services found.")

	if not args.services_only:
		print("Found %s observations. Adding to database." % len(observations))
		#TODO: need to get the service_ids after services are inserted
		for (service, key, start, end) in observations:
			# NOTE! this is a special case use of _insert_observation() -
			# we only call this because database records are assumed to be valid already,
			# but won't necessarily be inserted in chronological order.
			# you should use report_observation() during normal use.
			ndb._insert_observation(service, key, start, end)


parser = argparse.ArgumentParser(parents=[ndb.get_parser()], description=__doc__,
	formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('input_file', type=argparse.FileType('r'), nargs='?', default=DEFAULT_INFILE,
			help="File to read from. Use '-' to read from stdin (which is the default).")
parser.add_argument('--services-only', '-s', action='store_true', default=False,
			help="Only import services, not observations.")

args = parser.parse_args()
# pass ndb the args so it can use any relevant ones from its own parser
ndb = ndb(args)
import_records(args.input_file)

Пример #5
0
    else:
        print "No services found."

    if not args.services_only:
        print "Found %s observations. Adding to database." % len(observations)
        #TODO: need to get the service_ids after services are inserted
        for (service, key, start, end) in observations:
            # NOTE! this is a special case use of _insert_observation() -
            # we only call this because database records are assumed to be valid already,
            # but won't necessarily be inserted in chronological order.
            # you should use report_observation() during normal use.
            ndb._insert_observation(service, key, start, end)


parser = argparse.ArgumentParser(
    parents=[ndb.get_parser()],
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
    'input_file',
    type=argparse.FileType('r'),
    nargs='?',
    default=DEFAULT_INFILE,
    help="File to read from. Use '-' to read from stdin (which is the default)."
)
parser.add_argument('--services-only',
                    '-s',
                    action='store_true',
                    default=False,
                    help="Only import services, not observations.")
Пример #6
0
    """Print output in a simple tuple format, one record per line. This makes it easy to import the data somewhere else."""

    # note: lines starting with '#' should be ignored by the importer.

    output = [
    ]  # use list appending for better performance than string concatenation
    output.append("# Export of network notary Observations from %s" %
                  args.dbname)
    output.append("# %s\n" % time.ctime())

    for (service, key, start, end) in obs:
        output_file.write("({0}, {1}, {2}, {3})".format(
            service, key, start, end))


parser = argparse.ArgumentParser(parents=[ndb.get_parser()],
                                 description=__doc__)
parser.add_argument(
    'output_file',
    type=argparse.FileType('w'),
    nargs='?',
    default=DEFAULT_OUTFILE,
    help=
    "File to write data to. Use '-' to write to stdout. Writing to stdout is the default."
)
formats = parser.add_mutually_exclusive_group()
formats.add_argument('--tuples',
                     '--tup',
                     action='store_true',
                     help=print_tuples.__doc__ + " This is the default.")
formats.add_argument('--long',