human
Complete this python program:
def create_missing_perms():
assistant
#Here is the Python program you requested.

    """Creates missing perms for datasources, schemas and metrics
    """
    logging.info(u'Fetching    a    set    of    all    perms    to    lookup    which    ones    are    missing')
    all_pvs = set()
    for pv in sm.get_session.query(sm.permissionview_model).all():
        if (pv.permission and pv.view_menu):
            all_pvs.add((pv.permission.name, pv.view_menu.name))
    def merge_pv(view_menu, perm):
        u"Create    permission    view    menu    only    if    it    doesn't    exist"
        if (view_menu and perm and ((view_menu, perm) not in all_pvs)):
            merge_perm(sm, view_menu, perm)
    logging.info(u'Creating    missing    datasource    permissions.')
    datasources = ConnectorRegistry.get_all_datasources(db.session)
    for datasource in datasources:
        merge_pv(u'datasource_access', datasource.get_perm())
        merge_pv(u'schema_access', datasource.schema_perm)
    logging.info(u'Creating    missing    database    permissions.')
    databases = db.session.query(models.Database).all()
    for database in databases:
        merge_pv(u'database_access', database.perm)
    logging.info(u'Creating    missing    metrics    permissions')
    metrics = []
    for datasource_class in ConnectorRegistry.sources.values():
        metrics += list(db.session.query(datasource_class.metric_class).all())
    for metric in metrics:
        if metric.is_restricted:
            merge_pv(u'metric_access', metric.perm)