Exemplo n.º 1
0
def main(args):
    parser = optparse.OptionParser(usage="%prog [options] <model_path> [another_model_path...]",
                                   version=xtuml.version.complete_string,
                                   formatter=optparse.TitledHelpFormatter())
    
    parser.set_description(__doc__.strip())
    
    parser.add_option("-r", "-R", dest="rel_ids", type='int', metavar="<number>",
                      help="limit consistency check to one or more associations",
                      action="append", default=[])

    parser.add_option("-k", dest="kinds", type='string', metavar="<key letter>",
                      help="limit check for uniqueness constraint violations to one or more classes",
                      action="append", default=[])
    
    parser.add_option("-g", "--globals", dest="globals",
                      help="add builtin global data types automatically, e.g. boolean, integer and real",
                      action="store_true", default=False)
                      
    parser.add_option("-v", "--verbosity", dest='verbosity', action="count",
                      help="increase debug logging level", default=1)
    
    (opts, args) = parser.parse_args(args)
    if len(args) == 0:
        parser.print_help()
        sys.exit(1)
        
    levels = {
              0: logging.ERROR,
              1: logging.WARNING,
              2: logging.INFO,
              3: logging.DEBUG,
    }
    logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG))
    
    loader = ooaofooa.Loader(load_globals=opts.globals)
    for filename in args:
        loader.filename_input(filename)

    m = loader.build_metamodel()
    
    error = 0
    for rel_id in opts.rel_ids:
        error += xtuml.check_association_integrity(m, rel_id)
    
    if not opts.rel_ids:
        error += xtuml.check_association_integrity(m)

    for kind in opts.kinds:
        error += xtuml.check_uniqueness_constraint(m, kind)
    
    if not opts.kinds:
        error += xtuml.check_uniqueness_constraint(m)
    
    return error
Exemplo n.º 2
0
    def is_consistent(self):
        '''
        Check the metamodel for integrity violations.
        '''
        if xtuml.check_association_integrity(self):
            return False

        return xtuml.check_uniqueness_constraint(self) == 0
Exemplo n.º 3
0
 def is_consistent(self):
     '''
     Check the metamodel for integrity violations.
     '''
     if xtuml.check_association_integrity(self):
         return False
     
     return xtuml.check_uniqueness_constraint(self) == 0
Exemplo n.º 4
0
def main():
    parser = optparse.OptionParser(usage="bridgepoint.consistency_check [options] file_or_path file_or_path ...", 
                                   version=xtuml.version.complete_string, 
                                   formatter=optparse.TitledHelpFormatter())
    
    parser.add_option("-r", dest="r", type='int', metavar="<number>", 
                      help="limit consistency check to one or more associations", 
                      action="append", default=[])
    
    parser.add_option("-v", "--verbosity", dest='verbosity', action="count", 
                      help="increase debug logging level", default=1)
    
    (opts, args) = parser.parse_args()
    if len(args) == 0:
        parser.print_help()
        sys.exit(1)
        
    levels = {
              0: logging.ERROR,
              1: logging.WARNING,
              2: logging.INFO,
              3: logging.DEBUG,
    }
    logging.basicConfig(level=levels.get(opts.verbosity, logging.DEBUG))
    
    loader = ooaofooa.Loader()
    for filename in args:
        loader.filename_input(filename)

    m = loader.build_metamodel()
    
    error = False
    for rel_id in opts.r:
        error |= xtuml.check_association_integrity(m, rel_id)
    
    if not opts.r:
        error |= xtuml.check_association_integrity(m)

    sys.exit(error)
Exemplo n.º 5
0
def main(argv=None):
    loglevel = logging.INFO
    database_filename = 'mcdbms.gen'
    enable_persistance = True
    dump_sql_file = ''
    force_overwrite = False
    emit_when = 'change'
    diff_filename = None
    inputs = list()
    includes = ['.']
    check_integrity = False
    argv = argv or sys.argv
    quiet_insert_mismatch = False
    
    i = 1
    while i < len(argv):
        if argv[i] == '-arch':
            i += 1
            inputs.append((argv[i], 'arc'))

        elif argv[i] == '-import':
            i += 1
            inputs.append((argv[i], 'sql'))

        elif argv[i] == '-include':
            i += 1
            includes.append(argv[i])

        elif argv[i] == '-emit':
            i += 1
            emit_when = argv[i]
    
        elif argv[i] == '-f':
            i += 1
            database_filename = argv[i]

        elif argv[i] == '-force':
            force_overwrite = True

        elif argv[i] == '-integrity':
            check_integrity = True
            
        elif argv[i] == '-diff':
            i += 1
            diff_filename = argv[i]
            
        elif argv[i] == '-nopersist':
            enable_persistance = False
            
        elif argv[i] == '-dumpsql':
            i += 1
            dump_sql_file = argv[i]

        elif argv[i] == '-v':
            i += 1
            loglevel = logging.DEBUG
            
        elif argv[i] == '-qim':
            quiet_insert_mismatch = True
            
        elif argv[i] == '-version':
            print(rsl.version.complete_string)
            sys.exit(0)
            
        elif argv[i] == '-h':
            print(complete_usage % argv[0])
            sys.exit(0)
            
        elif argv[i] in ['//', '-ignore_rest']:
            break

        # ignore these options
        elif argv[i] in ['-lVHs', '-lSCs', '-l2b', '-l2s', '-l3b', '-l3s',
                             '-q', '-l']:
            pass
            
        # ignore these options (which expects a following value)
        elif argv[i] in ['-d', '-priority', '-e', '-t', '-#']:
            i += 1
            
        else:
            print("PARSE ERROR: Argument: %s" % argv[i])
            print("Couldn't find match for argument")
            print(brief_usage % (argv[0], argv[0]))
            sys.exit(1)
            
        i += 1
        
    logging.basicConfig(stream=sys.stdout, level=loglevel)
    
    id_generator = xtuml.IntegerGenerator()
    metamodel = xtuml.MetaModel(id_generator)
    loader = xtuml.ModelLoader()
    
    if quiet_insert_mismatch:
        load_logger = logging.getLogger(xtuml.load.__name__)
        load_logger.setLevel(logging.ERROR)

    if diff_filename:
        with open(diff_filename, 'w') as f:
            f.write(' '.join(argv))
            f.write('\n')
            
    if enable_persistance and os.path.isfile(database_filename):
        loader.filename_input(database_filename)
        
    for filename, kind in inputs:
        if kind == 'sql':
            loader.filename_input(filename)
            
        elif kind == 'arc':
            loader.populate(metamodel)
            rt = rsl.Runtime(metamodel, emit_when, force_overwrite, diff_filename)
            ast = rsl.parse_file(filename)
            rsl.evaluate(rt, ast, includes)
            loader = xtuml.ModelLoader()
            
        else:
            #should not happen
            print("Unknown %s is of unknown kind '%s', skipping it" % (filename, kind))

    errors = 0
    if check_integrity:
        errors += xtuml.check_association_integrity(metamodel)
        errors += xtuml.check_uniqueness_constraint(metamodel)
        
    if enable_persistance:
        xtuml.persist_database(metamodel, database_filename)

    if dump_sql_file != '':
        xtuml.persist_instances(metamodel, dump_sql_file)

    return errors
Exemplo n.º 6
0
def main(argv=None):
    loglevel = logging.INFO
    database_filename = 'mcdbms.gen'
    enable_persistance = True
    dump_sql_file = ''
    force_overwrite = False
    emit_when = 'change'
    diff_filename = None
    inputs = list()
    includes = ['.']
    check_integrity = False
    argv = argv or sys.argv
    quiet_insert_mismatch = False

    i = 1
    while i < len(argv):
        if argv[i] == '-arch':
            i += 1
            inputs.append((argv[i], 'arc'))

        elif argv[i] == '-import':
            i += 1
            inputs.append((argv[i], 'sql'))

        elif argv[i] == '-include':
            i += 1
            includes.append(argv[i])

        elif argv[i] == '-emit':
            i += 1
            emit_when = argv[i]

        elif argv[i] == '-f':
            i += 1
            database_filename = argv[i]

        elif argv[i] == '-force':
            force_overwrite = True

        elif argv[i] == '-integrity':
            check_integrity = True

        elif argv[i] == '-diff':
            i += 1
            diff_filename = argv[i]

        elif argv[i] == '-nopersist':
            enable_persistance = False

        elif argv[i] == '-dumpsql':
            i += 1
            dump_sql_file = argv[i]

        elif argv[i] == '-v':
            i += 1
            loglevel = logging.DEBUG

        elif argv[i] == '-qim':
            quiet_insert_mismatch = True

        elif argv[i] == '-version':
            print(rsl.version.complete_string)
            sys.exit(0)

        elif argv[i] == '-h':
            print(complete_usage % argv[0])
            sys.exit(0)

        elif argv[i] in ['//', '-ignore_rest']:
            break

        # ignore these options
        elif argv[i] in [
                '-lVHs', '-lSCs', '-l2b', '-l2s', '-l3b', '-l3s', '-q', '-l'
        ]:
            pass

        # ignore these options (which expects a following value)
        elif argv[i] in ['-d', '-priority', '-e', '-t', '-#']:
            i += 1

        else:
            print("PARSE ERROR: Argument: %s" % argv[i])
            print("Couldn't find match for argument")
            print(brief_usage % (argv[0], argv[0]))
            sys.exit(1)

        i += 1

    logging.basicConfig(stream=sys.stdout, level=loglevel)

    id_generator = xtuml.IntegerGenerator()
    metamodel = xtuml.MetaModel(id_generator)
    loader = xtuml.ModelLoader()

    if quiet_insert_mismatch:
        load_logger = logging.getLogger(xtuml.load.__name__)
        load_logger.setLevel(logging.ERROR)

    if diff_filename:
        with open(diff_filename, 'w') as f:
            f.write(' '.join(argv))
            f.write('\n')

    if enable_persistance and os.path.isfile(database_filename):
        loader.filename_input(database_filename)

    for filename, kind in inputs:
        if kind == 'sql':
            loader.filename_input(filename)

        elif kind == 'arc':
            loader.populate(metamodel)
            rt = rsl.Runtime(metamodel, emit_when, force_overwrite,
                             diff_filename)
            ast = rsl.parse_file(filename)
            rsl.evaluate(rt, ast, includes)
            loader = xtuml.ModelLoader()

        else:
            #should not happen
            print("Unknown %s is of unknown kind '%s', skipping it" %
                  (filename, kind))

    errors = 0
    if check_integrity:
        errors += xtuml.check_association_integrity(metamodel)
        errors += xtuml.check_uniqueness_constraint(metamodel)

    if enable_persistance:
        xtuml.persist_database(metamodel, database_filename)

    if dump_sql_file != '':
        xtuml.persist_instances(metamodel, dump_sql_file)

    return errors