irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

deploy_schemas_locally.py
Go to the documentation of this file.
1 import inspect
2 import json
3 import optparse
4 import os
5 import sys
6 
7 
8 SCHEMA_VERSION = '3'
9 
11  return os.path.dirname(os.path.abspath(
12  inspect.stack()[0][1]))
13 
14 def makedirs_catch_preexisting(*args, **kwargs):
15  try:
16  os.makedirs(*args, **kwargs)
17  except OSError as e:
18  if e[0] != 17: # 17 == File exists
19  raise
20 
21 def is_schema_template(filename):
22  return filename.endswith('.json') and not filename.startswith('sample')
23 
24 def update_schema_dict(schema_dict, url_base_with_version, filename):
25  schema_dict['id'] = '{url_base_with_version}/{filename}#'.format(**vars())
26 
27 def main(template_directory, output_directory_base, url_base):
28  url_base_with_version = '{0}/v{1}'.format(url_base, SCHEMA_VERSION)
29  output_directory_with_version = os.path.join(output_directory_base, 'v' + SCHEMA_VERSION)
30  makedirs_catch_preexisting(output_directory_with_version)
31  for dirpath, _, filenames in os.walk(template_directory):
32  for filename in filenames:
33  if is_schema_template(filename):
34  with open(os.path.join(dirpath, filename)) as f:
35  schema_dict = json.load(f)
36  update_schema_dict(schema_dict, url_base_with_version, filename)
37  with open(os.path.join(output_directory_with_version, filename), 'w') as f:
38  json.dump(schema_dict, f, indent=4, sort_keys=True)
39 
40 if __name__ == '__main__':
41  usage = '''\
42 Usage: python %prog --output_directory_base <path to desired deployment directory> [options]
43 
44  Deploys packaged schemas to <output_directory_base>.
45 
46  Sets "id" field of deployed schemas appropriately based on <url_base>.
47 
48  Example usage:
49 
50  python %prog --output_directory_base /tmp/irods_schemas
51 
52  This will create, if necessary, /tmp/irods_schemas and /tmp/irods_schemas/v{SCHEMA_VERSION}, then populate the latter with copies of the schema files currently found in {SCHEMAS_DIR}. The schema copies will have their "id" fields updated to reflect their new locations (e.g. "server_config.json" will have "id" field "file:///tmp/irods_schemas/v{SCHEMA_VERSION}/server_config.json#".
53 
54  To have an iRODS installation validate its configuration files against this local deployment, set the iRODS "schema_validation_base_uri" (found in "/etc/irods/server_config.json" or fed into the prompt during setup) to "file:///tmp/irods_schemas".
55 
56  Make sure that the Linux account running iRODS has read access to the deployed schemas.
57 '''.format(SCHEMA_VERSION=SCHEMA_VERSION, SCHEMAS_DIR=os.path.join(get_script_directory(), 'schemas'))
58 
59  parser = optparse.OptionParser(usage=usage)
60  parser.add_option('--output_directory_base', help=optparse.SUPPRESS_HELP)
61  parser.add_option('--template_directory', metavar='<path to alternate schema templates>')
62  parser.add_option('--url_base', metavar='<alternate url base for "id" field>', help='Useful for creating web deployments')
63  options, _ = parser.parse_args()
64 
65  if not options.output_directory_base:
66  parser.print_help()
67  sys.exit(1)
68  options.output_directory_base = os.path.abspath(options.output_directory_base)
69 
70  if not options.template_directory:
71  options.template_directory = os.path.join(get_script_directory(), 'schemas')
72 
73  if not options.url_base:
74  options.url_base = 'file://' + options.output_directory_base
75 
76  options.url_base = options.url_base.rstrip('/')
77 
78  main(options.template_directory, options.output_directory_base, options.url_base)
deploy_schemas_locally.main
def main(template_directory, output_directory_base, url_base)
Definition: deploy_schemas_locally.py:27
deploy_schemas_locally.makedirs_catch_preexisting
def makedirs_catch_preexisting(*args, **kwargs)
Definition: deploy_schemas_locally.py:14
deploy_schemas_locally.get_script_directory
def get_script_directory()
Definition: deploy_schemas_locally.py:10
deploy_schemas_locally.update_schema_dict
def update_schema_dict(schema_dict, url_base_with_version, filename)
Definition: deploy_schemas_locally.py:24
deploy_schemas_locally.is_schema_template
def is_schema_template(filename)
Definition: deploy_schemas_locally.py:21