choose an existing model
963090
def select_model(self, name):
        
        if name not in self._parent:
            raise KeyError('model "{}" not present'.format(name))
        self._current_model_group = name
744777
function update (model, choice, value) {
  var copy = {};
  for (var v in model) copy[v] = model[v];
  copy[choice] = value;
  return copy;
}
150543
def ModelOption(model):
    
    yngkpmatch = re.compile('^YNGKP_M[{0}]$'.format(''.join([m[1 : ] for m in yngkp_modelvariants])))
    if yngkpmatch.search(model):
        return model
    elif len(model) > 6 and model[ : 6] == 'ExpCM_':
        fname = model[6 : ]
        if os.path.isfile(fname):
            return ('ExpCM', fname)
        else:
            raise ValueError("ExpCM_ must be followed by the name of an existing file. You specified the following, which is not an existing file: %s" % fname)
    else:
        raise ValueError("Invalid model")
113395
function () {
                var model;
                try {
                    model = this["__model__"] || (this["__model__"] = this.patio.getModel(this._model, this.parent.db));
                } catch (e) {
                    model = this["__model__"] = this.patio.getModel(this.name, this.parent.db);
                }
                return model;
            }
48009
function(model, options) {
      model = this._prepareModel(model, options);
      this.add(model, _.extend({at: 0}, options));
      return model;
    }
964697
def import_model(self, source):
        """"""
        if not hasattr(source, 'read'):  # Not a File-like object
            with open(self._resolve_source(source), 'r') as f:
                return self._import(f)
        else:
            return self._import(source)
59426
def select_modeltypes(self, *models: ModelTypesArg) -> 'Selection':
        
        self.nodes = devicetools.Nodes()
        self.elements = self.search_modeltypes(*models).elements
        return self
123658
def get_model(self):
        

        if self.maplesat and self.status == True:
            model = pysolvers.maplesat_model(self.maplesat)
            return model if model != None else []
295017
def _model_exists_step(self, model, should_exist):
    

    model = get_model(model)
    data = guess_types(self.hashes)

    queryset = model.objects

    try:
        existence_check = _TEST_MODEL[model]
    except KeyError:
        existence_check = test_existence

    failed = 0
    try:
        for hash_ in data:
            match = existence_check(queryset, hash_)

            if should_exist:
                assert match, \
                    "%s does not exist: %s" % (model.__name__, hash_)
            else:
                assert not match, \
                    "%s exists: %s" % (model.__name__, hash_)

    except AssertionError as exc:
        print(exc)
        failed += 1

    if failed:
        print("Rows in DB are:")
        for existing_model in queryset.all():
            _dump_model(existing_model,
                        attrs=[k[1:]
                               for k in data[0].keys()
                               if k.startswith('@')])

        if should_exist:
            raise AssertionError("%i rows missing" % failed)
        else:
            raise AssertionError("%i rows found" % failed)
1238077
def find_model(self, constructor, constraints=None, *, columns=None, table_name=None,
                 order_by=None):
    """"""
    return self._find_model(constructor, table_name or constructor.table_name, constraints,
                            columns=columns, order_by=order_by)
1300929
function(err, model) {
                    if (err) {
                        return _fn(err);
                    }
                    if (!model) {
                        return _fn('No model (' + name + ') returned from `adapter.registerModel`');
                    }
                    mycro.models[name] = model;
                    _fn();
                }
829278
function(mod, data) {
        if (!Model || !Model[mod]) {
          debug("can't find model : " + mod);
          return;
        }

        return (new Model[mod](data));
      }
1308765
function(models, options) {
      var i, args, length, model, existing, needsSort;
      var at = options && options.at;
      var sort = ((options && options.sort) == null ? true : options.sort);
      models = _.isArray(models) ? models.slice() : [models];

      // Turn bare objects into model references, and prevent invalid models
      // from being added.
      for (i = models.length - 1; i >= 0; i--) {
        if(!(model = this._prepareModel(models[i], options))) {
          this.trigger("error", this, models[i], options);
          models.splice(i, 1);
          continue;
        }
        models[i] = model;

        existing = model.id != null && this._byId[model.id];
        // If a duplicate is found, prevent it from being added and
        // optionally merge it into the existing model.
        if (existing || this._byCid[model.cid]) {
          if (options && options.merge && existing) {
            existing.set(model.attributes, options);
            needsSort = sort;
          }
          models.splice(i, 1);
          continue;
        }

        // Listen to added models' events, and index models for lookup by
        // `id` and by `cid`.
        model.on('all', this._onModelEvent, this);
        this._byCid[model.cid] = model;
        if (model.id != null) this._byId[model.id] = model;
      }

      // See if sorting is needed, update `length` and splice in new models.
      if (models.length) needsSort = sort;
      this.length += models.length;
      args = [at != null ? at : this.models.length, 0];
      push.apply(args, models);
      splice.apply(this.models, args);

      // Sort the collection if appropriate.
      if (needsSort && this.comparator && at == null) this.sort({silent: true});

      if (options && options.silent) return this;

      // Trigger `add` events.
      while (model = models.shift()) {
        model.trigger('add', model, this, options);
      }

      return this;
    }
708689
@Override
    public ModelNode cloneModel()
    {
        int len = mSubModels.length;
        ModelNode[] newModels = new ModelNode[len];
        for (int i = 0; i < len; ++i) {
            newModels[i] = mSubModels[i].cloneModel();
        }
        return new ChoiceModel(newModels);
    }
393853
def patched_model():
    """"""

    patched = ('__reduce__', '__getstate__', '__setstate__')
    originals = {}
    for patch in patched:
        try:
            originals[patch] = getattr(models.Model, patch)
        except:
            pass

    try:
        # Patch various parts of the model
        models.Model.__reduce__ = _reduce
        try:
            del models.Model.__getstate__
        except:
            pass
        try:
            del models.Model.__setstate__
        except:  # pragma: no cover
            pass

        yield

    finally:
        # Restore the model
        for patch in patched:
            try:
                setattr(models.Model, patch, originals[patch])
            except KeyError:
                try:
                    delattr(models.Model, patch)
                except AttributeError:
                    pass
1298697
def register_model(ctx, model, type, trait,
                   manufacturer, product_name, description):
    
    session, api_url, project_id = build_client_from_context(ctx)
    model_base_url = '/'.join([api_url, 'deviceModels'])
    model_url = '/'.join([model_base_url, model])
    payload = {
        'device_model_id': model,
        'project_id': project_id,
        'device_type': 'action.devices.types.' + type,
    }
    if trait:
        payload['traits'] = trait
    if manufacturer:
        payload.setdefault('manifest', {})['manufacturer'] = manufacturer
    if product_name:
        payload.setdefault('manifest', {})['productName'] = product_name
    if description:
        payload.setdefault('manifest', {})['deviceDescription'] = description
    logging.debug(json.dumps(payload))
    r = session.get(model_url)
    logging.debug(r.text)
    if r.status_code == 200:
        click.echo('Updating existing device model: %s' % model)
        r = session.put(model_url, data=json.dumps(payload))
    elif r.status_code in (400, 403, 404):
        click.echo('Creating new device model')
        r = session.post(model_base_url, data=json.dumps(payload))
    else:
        raise failed_request_exception('Failed to check existing device model',
                                       r)
    if r.status_code != 200:
        raise failed_request_exception('Failed to register model', r)
    click.echo('Model %s successfully registered' % model)
791575
def find_or_create(self, constructor, props, *, comp=None):
    
    model = self.find_model(constructor, comp or props)
    if model is None:
      model = constructor(**props)
      self.insert_model(model)
    return model