Beispiel #1
0
def convert_cmdline():
    logging.basicConfig()
    parser = argparse.ArgumentParser(
        description='Convert an Open511 document to another format.')
    parser.add_argument('-f',
                        '--format',
                        type=str,
                        help='Target format: ' +
                        ', '.join(f.name for f in FORMATS_LIST))
    parser.add_argument(
        'source',
        metavar='DOC',
        type=str,
        help='Document to validate: path, URL, or - to read from stdin')
    arguments = parser.parse_args()
    obj, obj_type = load_path(arguments.source)
    if arguments.format:
        output_format = arguments.format
    else:
        output_format = 'xml' if obj_type == 'json' else 'json'
    result = open511_convert(obj, output_format, serialize=True)
    stdout = sys.stdout
    if hasattr(stdout, 'detach'):
        stdout = stdout.detach()
    stdout.write(result)
    sys.stdout.write("\n")
Beispiel #2
0
	def _compare(self, input_filename, output_filename):
		input_filename = os.path.join(os.path.dirname(__file__), 'fixtures', input_filename)
		output_filename = os.path.join(os.path.dirname(__file__), 'fixtures', output_filename)
		converted, _ = load_path(input_filename)
		converted = json.loads(json.dumps(converted)) # Run it through JSON to normalize

		with open(output_filename) as f:
			correct_json = json.load(f)
		self.assertEqual(converted, correct_json)
Beispiel #3
0
def validate_cmdline():
    parser = argparse.ArgumentParser(description='Validate an Open511 document.')
    parser.add_argument('source', metavar='DOC', type=str,
        help='Document to validate: path, URL, or - to read from stdin')
    arguments = parser.parse_args()
    obj, obj_type = load_path(arguments.source)
    if obj_type == 'json':
        obj = json_doc_to_xml(obj, custom_namespace='http://validator.open511.org/custom-field')
    try:
        validate(obj)
    except Open511ValidationError as e:
        sys.stderr.write(unicode(e))
        sys.stderr.write("\n")
        sys.exit(1)
Beispiel #4
0
def validate_cmdline():
    parser = argparse.ArgumentParser(description='Validate an Open511 document.')
    parser.add_argument('source', metavar='DOC', type=str,
        help='Document to validate: path, URL, or - to read from stdin')
    arguments = parser.parse_args()
    obj, obj_type = load_path(arguments.source)
    if obj_type == 'json':
        obj = json_doc_to_xml(obj, custom_namespace='http://validator.open511.org/custom-field')
    try:
        validate(obj)
    except Open511ValidationError as e:
        sys.stderr.write(unicode(e))
        sys.stderr.write("\n")
        sys.exit(1)
Beispiel #5
0
def convert_cmdline():
    logging.basicConfig()
    parser = argparse.ArgumentParser(description='Convert an Open511 document to another format.')
    parser.add_argument('-f', '--format', type=str,
        help='Target format: ' + ', '.join(f.name for f in FORMATS_LIST))
    parser.add_argument('source', metavar='DOC', type=str,
        help='Document to validate: path, URL, or - to read from stdin')
    arguments = parser.parse_args()
    obj, obj_type = load_path(arguments.source)
    if arguments.format:
        output_format = arguments.format
    else:
        output_format = 'xml' if obj_type == 'json' else 'json'
    result = open511_convert(obj, output_format, serialize=True)
    stdout = sys.stdout
    if hasattr(stdout, 'detach'):
        stdout = stdout.detach()
    stdout.write(result)
    sys.stdout.write("\n")
Beispiel #6
0
def cmdline():
    logging.basicConfig()

    parser = argparse.ArgumentParser(description='Synchronize an Open511 feed to a MASAS hub')
    parser.add_argument('--source', metavar='DOC', type=str,
        required=True,
        help='Open511 document: path, URL, or - to read from stdin')
    parser.add_argument('--masas-secret', metavar='SECRET', type=str,
        required=True, help="Secret token for authentication with MASAS hub")
    parser.add_argument('--masas-author', metavar='URL', type=str,
        required=True, help="URL for the authenticated MASAS user")
    parser.add_argument('--masas-hub', metavar='URL', type=str,
        default='https://sandbox2.masas-sics.ca/hub/feed',
        help='URL to the MASAS Hub feed (default: https://sandbox2.masas-sics.ca/hub/feed)')
    parser.add_argument('--timezone', metavar='TZ', type=str,
        help='Name of the default timezone for these events.'
        ' If not provided, will be downloaded from the linked jurisdiction.')
    arguments = parser.parse_args()

    doc, doc_format = load_path(arguments.source)

    sync_masas(doc, arguments.masas_secret, arguments.masas_author, arguments.masas_hub, timezone=arguments.timezone)