def setUp(self):
        self.opts = Object()
        self.opts.system_name = get_default_sysname()
        self.opts.force = True
        self.opts.objectdoc = True
        self.opts.read_from_yaml_file = True
        self.opts.dryrun = True

        self.mog = MessageObjectGenerator(
            system_name=self.opts.system_name,
            read_from_yaml_file=self.opts.read_from_yaml_file)
class MessageModelGenerateTest(PyonTestCase):

    def setUp(self):
        self.opts = Object()
        self.opts.system_name = get_default_sysname()
        self.opts.force = True
        self.opts.objectdoc = True
        self.opts.read_from_yaml_file = True
        self.opts.dryrun = True

        self.mog = MessageObjectGenerator(system_name=self.opts.system_name, read_from_yaml_file=self.opts.read_from_yaml_file)

    def test_object_gen(self):
        try:
            self.mog.generate(self.opts)
        except:
            self.fail("message_model_generator failed")
    def setUp(self):
        self.opts = Object()
        self.opts.system_name = get_default_sysname()
        self.opts.force = True
        self.opts.objectdoc = True
        self.opts.read_from_yaml_file = True
        self.opts.dryrun = True

        self.mog = MessageObjectGenerator(system_name=self.opts.system_name, read_from_yaml_file=self.opts.read_from_yaml_file)
class MessageModelGenerateTest(PyonTestCase):
    def setUp(self):
        self.opts = Object()
        self.opts.system_name = get_default_sysname()
        self.opts.force = True
        self.opts.objectdoc = True
        self.opts.read_from_yaml_file = True
        self.opts.dryrun = True

        self.mog = MessageObjectGenerator(
            system_name=self.opts.system_name,
            read_from_yaml_file=self.opts.read_from_yaml_file)

    def test_object_gen(self):
        try:
            self.mog.generate(self.opts)
        except:
            self.fail("message_model_generator failed")
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-f',
        '--force',
        action='store_true',
        help='Do not do MD5 comparisons, always generate new files')
    parser.add_argument('-d',
                        '--dryrun',
                        action='store_true',
                        help='Do not generate new files, just print status and'
                        ' exit with 1 if changes need to be made')
    parser.add_argument('-sd',
                        '--servicedoc',
                        action='store_true',
                        help='Generate HTML service doc inclusion files')
    parser.add_argument('-od',
                        '--objectdoc',
                        action='store_true',
                        help='Generate HTML object doc files')
    parser.add_argument('-s', '--sysname', action='store', help='System name')
    parser.add_argument(
        '-ry',
        '--read_from_yaml_file',
        action='store_true',
        help='Read configuration from YAML files instead of datastore - Default'
    )
    parser.add_argument('-rd',
                        '--read_from_datastore',
                        action='store_true',
                        help='Read configuration from datastore.')
    parser.add_argument('-c',
                        '--no_check',
                        action='store_true',
                        help='Do not check import all source modules')
    opts = parser.parse_args()

    print "generate_interfaces: SciON interface generator with options:", str(
        opts)

    print "generate_interfaces: Create directories and cleaning up..."
    opts.system_name = opts.sysname or get_default_sysname()

    from pyon.core import bootstrap
    bootstrap.testing = False

    opts.force = True
    if not opts.read_from_datastore and not opts.read_from_yaml_file:
        opts.read_from_yaml_file = True
    elif opts.read_from_datastore:
        opts.read_from_yaml_file = False
    #print "Forcing --force, we keep changing generate_interfaces!"

    model_object = ObjectModelGenerator(
        system_name=opts.system_name,
        read_from_yaml_file=opts.read_from_yaml_file)

    message_object = MessageObjectGenerator(
        system_name=opts.system_name,
        read_from_yaml_file=opts.read_from_yaml_file)

    service_object = ServiceObjectGenerator(
        system_name=opts.system_name,
        read_from_yaml_file=opts.read_from_yaml_file)

    if os.getcwd().endswith('scripts'):
        sys.exit('This script needs to be run from the pyon root.')
    # Create dir
    service_dir, interface_dir = 'obj/services', 'interface'
    if not os.path.exists(interface_dir):
        os.makedirs(interface_dir)
    # Clear old generated files
    files = os.listdir(interface_dir)
    for file in fnmatch.filter(files, '*.pyc'):
        os.unlink(os.path.join(interface_dir, file))
    for file in fnmatch.filter(files, '*.html'):
        os.unlink(os.path.join(interface_dir, file))
    open(os.path.join(interface_dir, '__init__.py'), 'w').close()

    # Generate objects
    print "generate_interfaces: Generating object interfaces from object definitions..."
    model_object.generate(opts)

    print "generate_interfaces: Generating message interfaces from service definitions..."
    message_object.generate(opts)

    print "generate_interfaces: Generating service interfaces from service definitions..."
    exitcode = service_object.generate(opts)

    #print "generate_interfaces: Completed with exit code:", exitcode
    sys.exit(exitcode)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', '--force', action='store_true',
                        help='Do not do MD5 comparisons, always generate new files')
    parser.add_argument('-d', '--dryrun', action='store_true',
                        help='Do not generate new files, just print status and'
                             ' exit with 1 if changes need to be made')
    parser.add_argument('-sd', '--servicedoc', action='store_true',
                        help='Generate HTML service doc inclusion files')
    parser.add_argument('-od', '--objectdoc', action='store_true',
                        help='Generate HTML object doc files')
    parser.add_argument('-s', '--sysname', action='store', help='System name')
    parser.add_argument('-ry', '--read_from_yaml_file', action='store_true',
                        help='Read configuration from YAML files instead of datastore - Default')
    parser.add_argument('-rd', '--read_from_datastore', action='store_true',
                        help='Read configuration from datastore.')
    parser.add_argument('-c', '--no_check', action='store_true',
                        help='Do not check import all source modules')
    opts = parser.parse_args()

    print "generate_interfaces: SciON interface generator with options:" , str(opts)

    print "generate_interfaces: Create directories and cleaning up..."
    opts.system_name = opts.sysname or get_default_sysname()

    from pyon.core import bootstrap
    bootstrap.testing = False

    opts.force = True
    if not opts.read_from_datastore and not opts.read_from_yaml_file:
        opts.read_from_yaml_file = True
    elif opts.read_from_datastore:
        opts.read_from_yaml_file = False
    #print "Forcing --force, we keep changing generate_interfaces!"

    model_object = ObjectModelGenerator(system_name=opts.system_name,
                        read_from_yaml_file=opts.read_from_yaml_file)

    message_object = MessageObjectGenerator(system_name=opts.system_name,
                        read_from_yaml_file=opts.read_from_yaml_file)

    service_object = ServiceObjectGenerator(system_name=opts.system_name,
                        read_from_yaml_file=opts.read_from_yaml_file)

    if os.getcwd().endswith('scripts'):
        sys.exit('This script needs to be run from the pyon root.')
    # Create dir
    service_dir, interface_dir = 'obj/services', 'interface'
    if not os.path.exists(interface_dir):
        os.makedirs(interface_dir)
    # Clear old generated files
    files = os.listdir(interface_dir)
    for file in fnmatch.filter(files, '*.pyc'):
        os.unlink(os.path.join(interface_dir, file))
    for file in fnmatch.filter(files, '*.html'):
        os.unlink(os.path.join(interface_dir, file))
    open(os.path.join(interface_dir, '__init__.py'), 'w').close()

    # Generate objects
    print "generate_interfaces: Generating object interfaces from object definitions..."
    model_object.generate(opts)

    print "generate_interfaces: Generating message interfaces from service definitions..."
    message_object.generate(opts)

    print "generate_interfaces: Generating service interfaces from service definitions..."
    exitcode = service_object.generate(opts)

    #print "generate_interfaces: Completed with exit code:", exitcode
    sys.exit(exitcode)