def validateFile(file): """ If a file document contains the DB_INFO_KEY, check if it is in a database assetstore. If so, check that the data in DB_INFO_KEY is valid. Note that this won't check files without the DB_INFO_KEY, even if they are in the database assetstore to allow files to be created and then have database information added to them. :param file: the file document. """ if DB_INFO_KEY not in file or 'assetstoreId' not in file: return None assetstore = Assetstore().load(file['assetstoreId']) if assetstore.get('type') != AssetstoreType.DATABASE: # This can happen if the file was a database_assetstore file and then # is replaced, for instance, by uploading a new file. if DB_INFO_KEY in file: del file[DB_INFO_KEY] return None if not file[DB_INFO_KEY].get('table'): raise ValidationException( 'File database information entry must have a non-blank table ' 'value.') if not assetstore['database'].get('uri') and not file[DB_INFO_KEY].get( 'uri'): raise ValidationException( 'File database information must have a non-blank uri value on an ' 'assetstore that doesn\'t specify a single database.')
def validateFile(file): """ If a file document contains the DB_INFO_KEY, check if it is in a database assetstore. If so, check that the data in DB_INFO_KEY is valid. Note that this won't check files without the DB_INFO_KEY, even if they are in the database assetstore to allow files to be created and then have database information added to them. :param file: the file document. """ if DB_INFO_KEY not in file or 'assetstoreId' not in file: return None assetstore = Assetstore().load(file['assetstoreId']) if assetstore.get('type') != AssetstoreType.DATABASE: # This can happen if the file was a database_assetstore file and then # is replaced, for instance, by uploading a new file. if DB_INFO_KEY in file: del file[DB_INFO_KEY] return None if not file[DB_INFO_KEY].get('table'): raise ValidationException( 'File database information entry must have a non-blank table ' 'value.') if not assetstore['database'].get('uri') and not file[DB_INFO_KEY].get('uri'): raise ValidationException( 'File database information must have a non-blank uri value on an ' 'assetstore that doesn\'t specify a single database.')
def getDbInfoForFile(file, assetstore=None): """ Given a file document, get the necessary information to connect to a database. :param file: the file document. :param assetstore: the assetstore document, or None to get it from the file information. :return: the dbinfo dictionary or None if the file is not in a database assetstore. """ if DB_INFO_KEY not in file or 'assetstoreId' not in file: return None if assetstore is None: assetstore = Assetstore().load(file['assetstoreId']) if assetstore.get('type') != AssetstoreType.DATABASE: return None if assetstore['database'].get('dbtype') == DB_ASSETSTORE_USER_TYPE: uri = file[DB_INFO_KEY]['uri'] else: uri = assetstore['database']['uri'] dbinfo = { 'uri': uri, 'table': file[DB_INFO_KEY]['table'], 'collection': file[DB_INFO_KEY]['table'] } for key in ('database', 'schema'): if key in file[DB_INFO_KEY]: dbinfo[key] = file[DB_INFO_KEY][key] return dbinfo
def _finalize_upload(self, upload, assetstore=None): if assetstore is None: assetstore = Assetstore().load(upload["assetstoreId"]) if str(upload["parentId"]).startswith("wtlocal:"): path, root_id = self.path_from_id(upload["parentId"]) root = Folder().load(root_id, force=True) # TODO make it obsolete else: root = Folder().load(upload["parentId"], force=True) path = pathlib.Path(root["fsPath"]) abspath = path / upload["name"] shutil.move(upload["tempFile"], abspath.as_posix()) abspath.chmod(assetstore.get("perms", DEFAULT_PERMS)) return self.vFile(abspath, root)