from __future__ import absolute_import, division
import libtbx.load_env

def ispyb_json(json_out):
  from xia2.Interfaces.ISPyB.ISPyBXmlHandler import ISPyBXmlHandler
  import os
  assert os.path.exists('xia2.json')
  assert os.path.exists('xia2.txt')
  command_line = ''
  for record in open('xia2.txt'):
    if record.startswith('Command line:'):
      command_line = record.replace('Command line:', '').strip()
  from xia2.Schema.XProject import XProject
  xinfo = XProject.from_json(filename='xia2.json')
  crystals = xinfo.get_crystals()
  assert len(crystals) == 1
  crystal = next(crystals.itervalues())
  ISPyBXmlHandler.add_xcrystal(crystal)
  import json
  json.dump(ISPyBXmlHandler.json_object(command_line=command_line),
            open(json_out, 'w'))

if __name__ == '__main__':
  import sys
  if len(sys.argv) >= 2:
    ispyb_json(sys.argv[1])
  else:
    ispyb_json('ispyb.json')

@@ -46,55 +46,26 @@
 ion%0A
-import libtbx.load_env%0A%0Adef ispyb_json(json_out
+%0Adef ispyb_object(
 ):%0A 
@@ -621,32 +621,15 @@
 )%0A  
-import json%0A  json.dump(
+return 
 ISPy
@@ -682,21 +682,77 @@
 ine)
-,%0A           
+%0A%0Adef ispyb_json(json_out):%0A  import json%0A  json.dump(ispyb_object(),
  ope
@@ -767,16 +767,26 @@
 ut, 'w')
+, indent=2
 )%0A%0Aif __

split ispyb object generation from jsonification