Adds a model to the repo (not initially visible)
        Args:
            model: the model to be added. If the model
            has no filename, a name is invented
        Returns: the filename of the model added to the repo
164142
def update_model_in_repo_based_on_filename(self, model):
        
        if model._tx_filename is None:
            for fn in self.all_models.filename_to_model:
                if self.all_models.filename_to_model[fn] == model:
                    return fn
            i = 0
            while self.all_models.has_model("anonymous{}".format(i)):
                i += 1
            myfilename = "anonymous{}".format(i)
            self.all_models.filename_to_model[myfilename] = model
        else:
            myfilename = model._tx_filename
            if (not self.all_models.has_model(myfilename)):
                self.all_models.filename_to_model[myfilename] = model
        return myfilename
264666
def _attach_to_model(self, model):
        
        if not issubclass(model, ModelWithDynamicFieldMixin):
            raise ImplementationError(
                'The "%s" model does not inherit from ModelWithDynamicFieldMixin '
                'so the "%s" DynamicField cannot be attached to it' % (
                model.__name__, self.name))

        super(DynamicFieldMixin, self)._attach_to_model(model)

        if self.dynamic_version_of is not None:
            return

        if hasattr(model, self.name):
            return

        setattr(model, self.name, self)
173080
def use_model(self, model_name):
        
        # Check against exclude list.
        if self.exclude_models:
            for model_pattern in self.exclude_models:
                model_pattern = '^%s$' % model_pattern.replace('*', '.*')
                if re.search(model_pattern, model_name):
                    return False
        # Check against exclude list.
        elif self.include_models:
            for model_pattern in self.include_models:
                model_pattern = '^%s$' % model_pattern.replace('*', '.*')
                if re.search(model_pattern, model_name):
                    return True
        # Return `True` if `include_models` is falsey, otherwise return `False`.
        return not self.include_models
1119331
def build_model_name(cls, name='modelName', output_name='output'):
        
        obj = cls(name)
        obj.exporter = 'generate_model_name'
        obj.output_name = output_name
        return obj
169271
function(model, options) {
            model = this._prepareModel(model, options);
            this.add(model, options);
            return model;
        }
147954
async def get_model(self, model):
        
        uuids = await self.model_uuids()
        if model in uuids:
            uuid = uuids[model]
        else:
            uuid = model

        from juju.model import Model
        model = Model()
        kwargs = self.connection().connect_params()
        kwargs['uuid'] = uuid
        await model._connect_direct(**kwargs)
        return model
1221606
def register_with_model(self, name, model):
        ''''''
        if self.name:
            raise FieldError('Field %s is already registered\
 with a model' % self)
        self.name = name
        self.attname = self.get_attname()
        self.model = model
        meta = model._meta
        self.meta = meta
        meta.dfields[name] = self
        meta.fields.append(self)
        if not self.primary_key:
            self.add_to_fields()
        else:
            model._meta.pk = self
415906
def hashmodel(model, library=None):
    ''''''
    library = library or 'python-stdnet'
    meta = model._meta
    sha = hashlib.sha1(to_bytes('{0}({1})'.format(library, meta)))
    hash = sha.hexdigest()[:8]
    meta.hash = hash
    if hash in _model_dict:
        raise KeyError('Model "{0}" already in hash table.\
 Rename your model or the module containing the model.'.format(meta))
    _model_dict[hash] = model
485692
def add_camera_make_model(self, make, model):
        ''' '''
        self._ef['0th'][piexif.ImageIFD.Make] = make
        self._ef['0th'][piexif.ImageIFD.Model] = model
1332684
def save_model(self, fname):
        
        if self.model is None:
            self.make_model()

        with open(fname, 'wb') as fh:
            fh.write(self.model.encode('utf-8'))
1082115
def _clean_file_name(self, model_instance, filename):
        
        available_name = self.storage.get_available_name(
            self.generate_filename(model_instance, filename))
        return os.path.basename(available_name)
118970
def _get_model_name(self, modeldata):
        
        if 'change_url' in modeldata:
            return modeldata['change_url'].strip('/').split('/')[-1]   # /foo/admin/appname/modelname
        elif 'add_url' in modeldata:
            return modeldata['add_url'].strip('/').split('/')[-2]      # /foo/admin/appname/modelname/add
        else:
            raise ValueError("Missing attributes in modeldata to find the model name!")
1222438
def get_field_model(name, model=None):
    
    if '.' in name:
        m, name = name.split('.')
        model = get_model(m)

    if model:
        return getattr(model, name, None), model
    else:
        return None, None
966754
def add_model(self, metric_value, model_id):
        
        if self.verbose:
            logger.info("Saving model.")

        # Update best_model text file
        ret = {"model_id": model_id, "metric_value": metric_value}
        self.history.append(ret)
        if model_id == self.get_best_model_id():
            file = open(os.path.join(self.path, "best_model.txt"), "w")
            file.write("best model: " + str(model_id))
            file.close()
        return ret
759865
def load_model(modelname, add_sentencizer=False):
    
    loading_start = time.time()
    nlp = spacy.load(modelname)
    if add_sentencizer:
        nlp.add_pipe(nlp.create_pipe('sentencizer'))
    loading_end = time.time()
    loading_time = loading_end - loading_start
    if add_sentencizer:
        return nlp, loading_time, modelname + '_sentencizer'
    return nlp, loading_time, modelname
825903
def follow_model(self, model):
        
        if model:
          self.models_by_name[model.__name__.lower()] = model
          signals.post_save.connect(create_or_update, sender=model)
          signals.post_delete.connect(self.remove_orphans, sender=model)
369614
def observe_model(self, model):
        
        self.__registered_models.add(model)
        return super(ExtendedController, self).observe_model(model)