def upload(request): if request.method == 'POST': # If the form has been submitted... # ContactForm was defined in the previous section if request.FILES: form = UploadDataForm(request.POST, request.FILES) # A form bound to the POST data else: form = UploadDataForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass data = request.FILES['data_set_file'].read() my_f = tempfile.NamedTemporaryFile(delete=False) my_f.file.write(data) my_f.close() connect('lisa_project_db') list_key = None csv_object = CSV() csv_object.initialize(my_f.name, form.data['name'], form.data['description']) persist_csv(csv_object, list_key) return render_to_response( 'lisa_search/upload.html', {}, context_instance=RequestContext(request)) else: form = UploadDataForm() # An unbound form return render_to_response( 'lisa_search/upload.html', {'form':form}, context_instance=RequestContext(request))
def handle(self, *args, **options): ''' The SuryaWebPortal initialization method. ''' # Check if we have the right number of arguments if len(args) != 1: raise CommandError('Error insufficient params: use ./manage.py init -help for info') # Check if mongod, is running isMongod = False processes = os.popen('''ps axo "%c"''') for process in processes: if 'mongod' in process: isMongod = True if not isMongod: raise CommandError('Error please run mongod first') # Import mongoengine and connect to the database try: import mongoengine except: raise CommandError('Error importing from mongoengine. Please ensure that mongoengine is installed') # Drop the database SuryaDB (This Implies That we lose all the stored images as well) mongoengine.connect('SuryaDB', tz_aware=True) startdate = datetime(2013,4,10,0,0,0) dirpre = "data/WI_data/" res = SuryaUploadData.objects(Q(deploymentId="madison.wi.bc") & Q(serverDatetime__gte = startdate)) for up in res: fd = open(dirpre + json.loads(up.misc)['origfilename'], 'wb') fd.write(up.origFile.read()) fd.flush() fd.close()
def test_connect_uri_with_authsource(self): """Ensure that the connect() method works well with the option `authSource` in URI. This feature was introduced in MongoDB 2.4 and removed in 2.6 """ # Create users c = connect('mongoenginetest') c.admin.system.users.remove({}) c.admin.add_user('username2', 'password') # Authentication fails without "authSource" if IS_PYMONGO_3: test_conn = connect('mongoenginetest', alias='test1', host='mongodb://*****:*****@localhost/mongoenginetest') self.assertRaises(OperationFailure, test_conn.server_info) else: self.assertRaises( ConnectionError, connect, 'mongoenginetest', alias='test1', host='mongodb://*****:*****@localhost/mongoenginetest' ) self.assertRaises(ConnectionError, get_db, 'test1') # Authentication succeeds with "authSource" connect( 'mongoenginetest', alias='test2', host=('mongodb://*****:*****@localhost/' 'mongoenginetest?authSource=admin') ) # This will fail starting from MongoDB 2.6+ db = get_db('test2') self.assertTrue(isinstance(db, pymongo.database.Database)) self.assertEqual(db.name, 'mongoenginetest') # Clear all users c.admin.system.users.remove({})
def get(self, request, *args, **kwargs): """Shows logs of imports that happened as a result of a git import""" course_id = kwargs.get('course_id') if course_id: course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) # Set mongodb defaults even if it isn't defined in settings mongo_db = { 'host': 'localhost', 'user': '', 'password': '', 'db': 'xlog', } # Allow overrides if hasattr(settings, 'MONGODB_LOG'): for config_item in ['host', 'user', 'password', 'db', ]: mongo_db[config_item] = settings.MONGODB_LOG.get( config_item, mongo_db[config_item]) mongouri = 'mongodb://{user}:{password}@{host}/{db}'.format(**mongo_db) error_msg = '' try: if mongo_db['user'] and mongo_db['password']: mdb = mongoengine.connect(mongo_db['db'], host=mongouri) else: mdb = mongoengine.connect(mongo_db['db'], host=mongo_db['host']) except mongoengine.connection.ConnectionError: log.exception('Unable to connect to mongodb to save log, ' 'please check MONGODB_LOG settings.') if course_id is None: # Require staff if not going to specific course if not request.user.is_staff: raise Http404 cilset = CourseImportLog.objects.all().order_by('-created') else: try: course = get_course_by_id(course_id) except Exception: # pylint: disable=broad-except log.info('Cannot find course {0}'.format(course_id)) raise Http404 # Allow only course team, instructors, and staff if not (request.user.is_staff or CourseInstructorRole(course.id).has_user(request.user) or CourseStaffRole(course.id).has_user(request.user)): raise Http404 log.debug('course_id={0}'.format(course_id)) cilset = CourseImportLog.objects.filter(course_id=course_id).order_by('-created') log.debug('cilset length={0}'.format(len(cilset))) mdb.disconnect() context = {'cilset': cilset, 'course_id': course_id.to_deprecated_string() if course_id else None, 'error_msg': error_msg} return render_to_response(self.template_name, context)
def test_gitlog_pagination_out_of_range_invalid(self): """ Make sure the pagination behaves properly when the requested page is out of range. """ self._setstaff_login() mongoengine.connect(TEST_MONGODB_LOG['db']) for _ in xrange(15): CourseImportLog( course_id=CourseKey.from_string("test/test/test"), location="location", import_log="import_log", git_log="git_log", repo_dir="repo_dir", created=datetime.now() ).save() for page, expected in [(-1, 1), (1, 1), (2, 2), (30, 2), ('abc', 1)]: response = self.client.get( '{}?page={}'.format( reverse('gitlogs'), page ) ) self.assertIn( 'Page {} of 2'.format(expected), response.content ) CourseImportLog.objects.delete()
def test_disconnect(self): """Ensure that the disconnect() method works properly """ conn1 = connect('mongoenginetest') mongoengine.connection.disconnect() conn2 = connect('mongoenginetest') self.assertTrue(conn1 is not conn2)
def test_connect_uri_without_db(self): """Ensure connect() method works properly with uri's without database_name """ c = connect(db='mongoenginetest', alias='admin') c.admin.system.users.remove({}) c.mongoenginetest.system.users.remove({}) c.admin.add_user("admin", "password") c.admin.authenticate("admin", "password") c.mongoenginetest.add_user("username", "password") if not IS_PYMONGO_3: self.assertRaises(ConnectionError, connect, "testdb_uri_bad", host='mongodb://*****:*****@localhost') connect("mongoenginetest", host='mongodb://localhost/') conn = get_connection() self.assertTrue(isinstance(conn, pymongo.mongo_client.MongoClient)) db = get_db() self.assertTrue(isinstance(db, pymongo.database.Database)) self.assertEqual(db.name, 'mongoenginetest') c.admin.system.users.remove({}) c.mongoenginetest.system.users.remove({})
def get_tracer_and_connect(self): tracer = get_dummy_tracer() Pin.get_from(mongoengine.connect).clone( tracer=tracer).onto(mongoengine.connect) mongoengine.connect(port=MONGO_CONFIG['port']) return tracer
def test_patch_unpatch(self): tracer = get_dummy_tracer() # Test patch idempotence patch() patch() client = mongoengine.connect(port=MONGO_CONFIG['port']) Pin.get_from(client).clone(tracer=tracer).onto(client) Artist.drop_collection() spans = tracer.writer.pop() assert spans, spans eq_(len(spans), 1) # Test unpatch mongoengine.connection.disconnect() unpatch() mongoengine.connect(port=MONGO_CONFIG['port']) Artist.drop_collection() spans = tracer.writer.pop() assert not spans, spans # Test patch again patch() client = mongoengine.connect(port=MONGO_CONFIG['port']) Pin.get_from(client).clone(tracer=tracer).onto(client) Artist.drop_collection() spans = tracer.writer.pop() assert spans, spans eq_(len(spans), 1)
def __init__(self, handlers=None, default_host='', transforms=None, wsgi=False, **settings): connect(options.db, host=options.host, replicaSet = options.replset) super(Application, self).__init__(handlers=handlers, default_host=default_host, transforms=transforms, wsgi=wsgi, **settings)
def handle(self, *args, **options): ''' The SuryaWebPortal initialization method. ''' # Check if we have the right number of arguments #if len(args) != 1: # raise CommandError('Error insufficient params: use ./manage.py init -help for info') # Check if mongod, is running isMongod = False processes = os.popen('''ps axo "%c"''') for process in processes: if 'mongod' in process: isMongod = True if not isMongod: raise CommandError('Error please run mongod first') # Import mongoengine and connect to the database try: import mongoengine except: raise CommandError('Error importing from mongoengine. Please ensure that mongoengine is installed') # Drop the database SuryaDB (This Implies That we lose all the stored images as well) mongoengine.connect('SuryaDB') SuryaUploadData.drop_collection() SuryaGroundTruth.drop_collection() SuryaDeploymentData.drop_collection() SuryaCalibrationData.drop_collection() SuryaProcessingList.drop_collection() SuryaIANAFailedResult.drop_collection() SuryaIANAResult.drop_collection() SuryaResult.drop_collection()
def management_project_manage(): connect('user', port=27777) projects = MongoProject.objects() if request.method == 'POST': # # check for selection # if 'selectedprojects' in request.form: data = dict(request.form) project_ids = data['selectedprojects'] action = str(data['button'][0]) for projectid in project_ids: project = MongoProject.objects(projectid=projectid)[0] project.status = action project.save() connect('user', port=27777) projects = MongoProject.objects() return render_template('management/project_manage.html', projects=projects, with_edit="True", title="Project Management", states=ProjectSTATUS)
def management_user_manage(): connect('user', port=27777) users = MongoUser.objects() if request.method == 'POST': # # check for selection # if 'selectedusers' in request.form: data = dict(request.form) usernames = data['selectedusers'] action = str(data['button'][0]) if action == 'delete': for username in usernames: user = MongoUser.objects(username=username)[0] user.delete() else: for username in usernames: user = MongoUser.objects(username=username)[0] user.status = action user.save() users = MongoUser.objects() return render_template('management/user_manage.html', users=users, with_edit="True", states=['approved', 'pending', 'denied', 'blocked', 'delete'], title="User Management")
def test_connect_disconnect_works_on_same_document(self): """Ensure that the connect/disconnect works properly with a single Document""" db1 = 'db1' db2 = 'db2' # Ensure freshness of the 2 databases through pymongo client = MongoClient('localhost', 27017) client.drop_database(db1) client.drop_database(db2) # Save in db1 connect(db1) class User(Document): name = StringField(required=True) user1 = User(name='John is in db1').save() disconnect() # Make sure save doesnt work at this stage with self.assertRaises(MongoEngineConnectionError): User(name='Wont work').save() # Save in db2 connect(db2) user2 = User(name='Bob is in db2').save() disconnect() db1_users = list(client[db1].user.find()) self.assertEqual(db1_users, [{'_id': user1.id, 'name': 'John is in db1'}]) db2_users = list(client[db2].user.find()) self.assertEqual(db2_users, [{'_id': user2.id, 'name': 'Bob is in db2'}])
def test_connect_uri(self): """Ensure that the connect() method works properly with URIs.""" c = connect(db='mongoenginetest', alias='admin') c.admin.system.users.delete_many({}) c.mongoenginetest.system.users.delete_many({}) c.admin.command("createUser", "admin", pwd="password", roles=["root"]) c.admin.authenticate("admin", "password") c.admin.command("createUser", "username", pwd="password", roles=["dbOwner"]) if not IS_PYMONGO_3: self.assertRaises( MongoEngineConnectionError, connect, 'testdb_uri_bad', host='mongodb://*****:*****@localhost' ) connect("testdb_uri", host='mongodb://*****:*****@localhost/mongoenginetest') conn = get_connection() self.assertIsInstance(conn, pymongo.mongo_client.MongoClient) db = get_db() self.assertIsInstance(db, pymongo.database.Database) self.assertEqual(db.name, 'mongoenginetest') c.admin.system.users.delete_many({}) c.mongoenginetest.system.users.delete_many({})
def pytest_configure(): from django.conf import settings settings.configure( DEBUG_PROPAGATE_EXCEPTIONS=True, DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}}, SITE_ID=1, SECRET_KEY='not very secret in tests', USE_I18N=True, USE_L10N=True, STATIC_URL='/static/', ROOT_URLCONF='tests.urls', TEMPLATE_LOADERS=(), MIDDLEWARE_CLASSES=(), INSTALLED_APPS=( 'django.contrib.auth', 'django.contrib.contenttypes', 'rest_framework', 'rest_framework_mongoengine', 'tests', ), AUTHENTICATION_BACKENDS=(), PASSWORD_HASHERS=(), ) from mongoengine import connect connect('test') try: import django django.setup() except AttributeError: pass
def test_connect_fails_if_connect_2_times_with_custom_alias(self): connect('mongoenginetest', alias='alias1') with self.assertRaises(MongoEngineConnectionError) as ctx_err: connect('mongoenginetest2', alias='alias1') self.assertEqual("A different connection with alias `alias1` was already registered. Use disconnect() first", str(ctx_err.exception))
def get_question(tag): mongoengine.connect('Words', host='mongodb://localhost/Words') questionList = Question.objects(tags__name=tag.encode())[:10] number = randint(0, len(questionList)-1) question = questionList[number] option = Question.objects(id__ne=question.id)[:3] wrong = [] tag = [] for index in option: wrong.append(index['word'].encode('utf8')) for index in question.tags: tag.append(index['name'].encode('utf8')) js = { 'word': question.word, 'answer': question.answer, 'tags': json.dumps(tag), 'option': json.dumps(wrong) } result = json.dumps(js) resp = Response(result, status=200, mimetype='application/json') return resp
def add_question(): mongoengine.connect('Words', host='mongodb://localhost/Words') if (not request.data) or (not 'tags' in request.data) or (not 'word' in request.data) or ( not 'answer' in request.data): abort(400) tagList = [] data = json.loads(request.get_data()) content = data['word'].encode('utf8') answer = data['answer'].encode('utf8') for index in data['tags']: #todo:gets_or_create getTag = Tags.objects(id=index['id']) if 0 == len(getTag): addedTag = Tags(name=index['name'].encode('utf8'), date=datetime.datetime.now).save() tagList.append(Tag(id=addedTag.id, name=addedTag.name, date=addedTag.date)) else: tagList.append(Tag(id=getTag[0].id, name=getTag[0].name, date=getTag[0].date)) questionItem = Question() questionItem.word = content questionItem.answer = answer questionItem.tags = tagList questionItem.save() js = Question.objects().to_json() resp = Response(js, status=200, mimetype='application/json', charset='utf-8') return resp
def get_question(tag): mongoengine.connect('Words', host='mongodb://localhost/Words') count = len(Question.objects(tags__name__istartswith=tag.encode())) number = randint(1, count) question = Question.objects(tags__name__istartswith=tag.encode())[number:number + 1][0] option = Question.objects(id__ne=question.id)[:3] wrong = [] tag = [] for index in option: wrong.append(dict(word=index['answer'], answer=False)) wrong.append(dict(word=question.answer, answer=True)) for index in question.tags: tag.append(dict(id=index['id'], name=index['name'])) js = { 'word': question.word, 'tags': json.loads(JSONEncoder().encode(tag)), 'option': json.loads(JSONEncoder().encode(wrong)) } result = json.dumps(js) resp = Response(result, status=200, mimetype='application/json') return resp
def initialize(self): self.gl = gitlab.Gitlab( self.config.GITLAB_BASE_URL, self.config.GITLAB_TOKEN) mongoengine.connect(host=self.config.DBAAS_MONGODB_ENDPOINT) self.gl.auth() self.runs = 0 self.teams_seen = set()
def do_action(self): print "CLEANED", self.cleaned_data try: connect ('user', port=27777) users = Users() except: print "ERROR: INternal Server error, please contact the admin" pass try: project = Project ( title = self.cleaned_data["title"], abstract = self.cleaned_data["abstract"], broader_impact = self.cleaned_data["broader_impact"], intellectual_merit = self.cleaned_data["intellectual_merit"], scale_of_use = self.cleaned_data["scale_of_use"], use_of_fg = self.cleaned_data["use_of_fg"], categories = self.cleaned_data["categories"], keywords = self.cleaned_data["keywords"], ) projects.add(project) pass except Exception, e: print e pass
def _connect_to_test_db(cls): me.connection.disconnect() me.connect( fixtures.DB_NAME, host=c.MONGO_HOST, port=c.MONGO_PORT )
def form_sources(self): model_modules = [c for c in listdir(self.model_location) if isfile(join(self.model_location, c)) if c != '__init__.py'] model_modules = [m for m in model_modules if PY_FILE_REGEX.match(m)] for model_module in model_modules: # get the name of the class model_module = model_module.split('.')[0] try: module_path = self.load_path + '.' + model_module model_class = model_module module = importlib.import_module(module_path) self.models.append(ModelIdentifier(db_name=module.db_name, db_alias=module.db_alias, collection_name=module.collection_name, fields=module.relation_fields, payload_fields = module.payload_fields, function_fields = module.function_fields, model_class=module.model_class)) except (ImportError, Exception) as e: raise RuntimeError("Error importing the module ", e) for model in self.models: if self.connect_str: conn = connect(model.db_name, model.db_alias, host=self.connect_str) else: conn = connect(model.db_name, model.db_alias, host=MONGO_HOST, port=MONGO_PORT) model_name = model.db_name + "." + model.db_alias + "." + model.collection_name data_source = MongoDataSource(model_name, conn, model) self.data_sources[model_name] = data_source
def resetDB(name='tsp',host='localhost',port=27017,username=None,password=None): ''' DANGER: THIS WILL RESET DATABASE ''' import pymongo # FIXME: Authenticate may break conn=pymongo.Connection(host=host,port=port) if name in conn.database_names(): # Backup conn.copy_database(name,name+'_'+"_".join(map(str,localtime()[:5])),username=username,password=password) # Drop Database conn.drop_database(name) connect(name,reconnect=True) # (Re)initialize Database Admin( username='******', password=passwordHash('admin','admin'), realname='administrator', ).save() Settings( phase=0, ttl=86400, ).save()
def __init__(self, release, logger=None): self.release = release mongoengine.connect('configdb') config_obj = CMSSWConfig config_obj._meta['collection'] = release self.index = mongosearch.SearchIndex(config_obj, use_term_index=False) self.logger = logger
def setUp(self): connect("test") self.user = mongoengine_auth.User(username="******") self.user.set_password("password") self.user.save()
def do_action(self): print "CLEANED", self.cleaned_data try: connect ('user', port=27777) users = Users() except: print "ERROR: Internal Server error, please contact the admin" pass try: user = User ( title = self.cleaned_data["title"], firstname = self.cleaned_data["firstname"], lastname = self.cleaned_data["lastname"], email = self.cleaned_data["email"], username = self.cleaned_data["username"], password = self.cleaned_data["password"], phone = self.cleaned_data["phone"], department = self.cleaned_data["department"], institution = self.cleaned_data["institution"], address = self.cleaned_data["address"], country = self.cleaned_data["country"], citizenship = self.cleaned_data["citizenship"], bio = self.cleaned_data["bio"], ) users.add(user) pass except Exception, e: print e pass
def _init(): global _initialized global redis_client global mongodb_client global mongodb_client_db global document_ids if _initialized: return _initialized = True _redis_pool = redis.ConnectionPool( host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0 ) redis_client = redis.Redis(connection_pool=_redis_pool) mongodb_client = pymongo.MongoClient( host=settings.MONGODB_HOST, port=settings.MONGODB_PORT ) mongodb_client_db = mongodb_client[settings.MONGODB_DB] connect(settings.MONGODB_DB, host=settings.MONGODB_HOST, port=settings.MONGODB_PORT ) document_ids = _DocumentIds(mongodb_client_db)
def process(event, host, port, db, collection): connect(db, host=host, port=int(port)) auth = OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_secret) meta_info = MetaInfo.objects(key='news_tweets_meta').first() last_tweet_id = None if not meta_info else meta_info.value['toi'] for news_handle in news_handles: tweets = tweepy.API(auth).user_timeline(screen_name=news_handle, since_id=last_tweet_id, count=50) last_tweet_id = None for tweet in tweets: tweet = tweet._json tweet = process_tweet(tweet) if not tweet: continue if not last_tweet_id: last_tweet_id = tweet.get('id') status = save_tweet(tweet, host, port, db, collection) if status: print 'Tweet with id %d saved' % tweet.get('id') else: print 'Error while saving tweet %d ' % tweet.get('id') if last_tweet_id: obj = MetaInfo.objects(key='news_tweets_meta') obj.update_one(set__value__toi=last_tweet_id, upsert=True)
from flask import Flask from flask_graphql import GraphQLView from schema import schema from mongoengine import connect app = Flask(__name__) app.debug = True app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) if __name__ == '__main__': connect('graphene-mapping-example', alias='default') # from schema import create_person # create_person("AAA") # create_person("BBB") # create_person("CCC") app.run()
from environs import Env from mongoengine import connect, Document, UUIDField, StringField, ListField, StringField, EmailField, DateTimeField import datetime, uuid env = Env() env.read_env() connect(db=env("MONGODB_DATABASE"), username=env("MONGODB_ROOT_USERNAME"), password=env("MONGODB_ROOT_PASSWORD"), authentication_source="admin", host=env("MONGODB_DATABASE"), port=27017) class UserModel(Document): id = UUIDField(default=uuid.uuid4(), primary_key=True, editable=False) name = StringField(editable=True, max_length=100, required=True) password = StringField(editable=True, max_length=256, required=True) email = EmailField(required=True) enterprises = ListField(UUIDField(editable=False)) records = ListField(UUIDField(editable=False)) created_at = DateTimeField(default=datetime.datetime.now()) def save(self, *args, **kwargs): return super(UserModel, self).save(*args, **kwargs)
}, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] _MONGODB_USER = '******' _MONGODB_PASSWD = 'abbnaseri' mongoengine.connect('WalletDB', username=_MONGODB_USER, password=_MONGODB_PASSWD, authentication_source='admin') # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True
def add_repo(repo, rdir_in, branch=None): """ This will add a git repo into the mongo modulestore. If branch is left as None, it will fetch the most recent version of the current branch. """ # pylint: disable=too-many-statements git_repo_dir = getattr(settings, 'GIT_REPO_DIR', DEFAULT_GIT_REPO_DIR) git_import_static = getattr(settings, 'GIT_IMPORT_STATIC', True) git_import_python_lib = getattr(settings, 'GIT_IMPORT_PYTHON_LIB', True) python_lib_filename = getattr(settings, 'PYTHON_LIB_FILENAME', DEFAULT_PYTHON_LIB_FILENAME) # Set defaults even if it isn't defined in settings mongo_db = { 'host': 'localhost', 'port': 27017, 'user': '', 'password': '', 'db': 'xlog', } # Allow overrides if hasattr(settings, 'MONGODB_LOG'): for config_item in ['host', 'user', 'password', 'db', 'port']: mongo_db[config_item] = settings.MONGODB_LOG.get( config_item, mongo_db[config_item]) if not os.path.isdir(git_repo_dir): raise GitImportErrorNoDir(git_repo_dir) # pull from git if not (repo.endswith('.git') or repo.startswith(('http:', 'https:', 'git:', 'file:'))): raise GitImportErrorUrlBad() if rdir_in: rdir = os.path.basename(rdir_in) else: rdir = repo.rsplit('/', 1)[-1].rsplit('.git', 1)[0] log.debug('rdir = %s', rdir) rdirp = '{0}/{1}'.format(git_repo_dir, rdir) if os.path.exists(rdirp): log.info('directory already exists, doing a git pull instead ' 'of git clone') cmd = ['git', 'pull', ] cwd = rdirp else: cmd = ['git', 'clone', repo, ] cwd = git_repo_dir cwd = os.path.abspath(cwd) try: ret_git = cmd_log(cmd, cwd=cwd) except subprocess.CalledProcessError as ex: log.exception('Error running git pull: %r', ex.output) raise GitImportErrorCannotPull() if branch: switch_branch(branch, rdirp) # get commit id cmd = ['git', 'log', '-1', '--format=%H', ] try: commit_id = cmd_log(cmd, cwd=rdirp) except subprocess.CalledProcessError as ex: log.exception('Unable to get git log: %r', ex.output) raise GitImportErrorBadRepo() ret_git += '\nCommit ID: {0}'.format(commit_id) # get branch cmd = ['git', 'symbolic-ref', '--short', 'HEAD', ] try: branch = cmd_log(cmd, cwd=rdirp) except subprocess.CalledProcessError as ex: # I can't discover a way to excercise this, but git is complex # so still logging and raising here in case. log.exception('Unable to determine branch: %r', ex.output) raise GitImportErrorBadRepo() ret_git += '{0}Branch: {1}'.format(' \n', branch) # Get XML logging logger and capture debug to parse results output = StringIO.StringIO() import_log_handler = logging.StreamHandler(output) import_log_handler.setLevel(logging.DEBUG) logger_names = ['xmodule.modulestore.xml_importer', 'git_add_course', 'xmodule.modulestore.xml', 'xmodule.seq_module', ] loggers = [] for logger_name in logger_names: logger = logging.getLogger(logger_name) logger.setLevel(logging.DEBUG) logger.addHandler(import_log_handler) loggers.append(logger) try: management.call_command( 'import', git_repo_dir, rdir, nostatic=not git_import_static, nopythonlib=not git_import_python_lib, python_lib_filename=python_lib_filename ) except CommandError: raise GitImportErrorXmlImportFailed() except NotImplementedError: raise GitImportErrorUnsupportedStore() ret_import = output.getvalue() # Remove handler hijacks for logger in loggers: logger.setLevel(logging.NOTSET) logger.removeHandler(import_log_handler) course_key = None location = 'unknown' # extract course ID from output of import-command-run and make symlink # this is needed in order for custom course scripts to work match = re.search(r'(?ms)===> IMPORTING courselike (\S+)', ret_import) if match: course_id = match.group(1) course_key = CourseKey.from_string(course_id) cdir = '{0}/{1}'.format(git_repo_dir, course_key.course) log.debug('Studio course dir = %s', cdir) if os.path.exists(cdir) and not os.path.islink(cdir): log.debug(' -> exists, but is not symlink') log.debug(subprocess.check_output(['ls', '-l', ], cwd=os.path.abspath(cdir))) try: os.rmdir(os.path.abspath(cdir)) except OSError: log.exception('Failed to remove course directory') if not os.path.exists(cdir): log.debug(' -> creating symlink between %s and %s', rdirp, cdir) try: os.symlink(os.path.abspath(rdirp), os.path.abspath(cdir)) except OSError: log.exception('Unable to create course symlink') log.debug(subprocess.check_output(['ls', '-l', ], cwd=os.path.abspath(cdir))) # store import-command-run output in mongo mongouri = 'mongodb://{user}:{password}@{host}:{port}/{db}'.format(**mongo_db) try: if mongo_db['user'] and mongo_db['password']: mdb = mongoengine.connect(mongo_db['db'], host=mongouri) else: mdb = mongoengine.connect(mongo_db['db'], host=mongo_db['host'], port=mongo_db['port']) except mongoengine.connection.ConnectionError: log.exception('Unable to connect to mongodb to save log, please ' 'check MONGODB_LOG settings') cil = CourseImportLog( course_id=course_key, location=location, repo_dir=rdir, created=timezone.now(), import_log=ret_import, git_log=ret_git, ) cil.save() log.debug(u'saved CourseImportLog for %s', cil.course_id) mdb.close()
# create the flask object app = Flask(__name__) # add mongo url to flask config, so that flask_pymongo can use it to make connection app.config[ "MONGO_URI"] = "mongodb+srv://casaDeTesoros:[email protected]/cazadetesoros?retryWrites=true&w=majority" mongo = PyMongo(app) basedir = os.path.abspath(os.path.dirname(__file__)) app.config[ 'MONGOALCHEMY_DATABASE'] = 'mongodb+srv://casaDeTesoros:[email protected]/test?retryWrites=true&w=majority' me.connect( 'sample_mflix', host= 'mongodb+srv://casaDeTesoros:[email protected]/cazadetesoros?retryWrites=true&w=majority' ) db = SQLAlchemy(app) app.secret_key = "secret key" class JSONEncoder(json.JSONEncoder): ''' extend json-encoder class''' def default(self, o): if isinstance(o, ObjectId): return str(o) if isinstance(o, datetime.datetime): return str(o) return json.JSONEncoder.default(self, o)
class Movie(me.Document): title = me.StringField() year = me.IntField() has_sequel = me.BooleanField() imdb_url = me.URLField() cast = me.EmbeddedDocumentListField(Star) score = me.DecimalField() def list_movies(): return Movie.objects.as_pymongo() if __name__ == '__main__': #create connection to mongodb me.connect(db='movies') #create stars marlon_brando = Star(name='Marlon Brando', gender='Male') al_pacino = Star(name='Al Pacino', gender='Male') talia_shire = Star(name='Talia Shire', gender='Female') #create movie the_godfather = Movie(title='The Godfather', year=1972, has_sequel=True, imdb_url='https://www.imdb.com/title/tt0068646', cast=[marlon_brando, al_pacino, talia_shire], score=9.2) #save movie to database
from mongoengine import connect client = connect('hew', host='localhost', port=27017)
import unittest from mongoengine import connect, disconnect import tests if __name__ == '__main__': suite = unittest.TestSuite() suite.addTest(tests.TestDreamcraftBotE2E('test_user_setup')) suite.addTest(tests.TestDreamcraftBotE2E('test_npc_character_creation')) suite.addTest(tests.TestDreamcraftBotE2E('test_character_creation')) suite.addTest(tests.TestDreamcraftBotE2E('test_character_permissions')) suite.addTest(tests.TestDreamcraftBotE2E('test_copy_character')) suite.addTest(tests.TestDreamcraftBotE2E('test_command_logging')) suite.addTest(tests.TestDreamcraftBotE2E('test_session_creation')) suite.addTest(tests.TestDreamcraftBotE2E('test_scenario_creation')) suite.addTest(tests.TestDreamcraftBotE2E('test_scene_creation')) suite.addTest(tests.TestDreamcraftBotE2E('test_zone_creation')) suite.addTest(tests.TestDreamcraftBotE2E('test_scene_features')) suite.addTest(tests.TestDreamcraftBotE2E('test_actions')) suite.addTest(tests.TestDreamcraftBotE2E('test_end_delete_components')) suite.addTest(tests.TestDreamcraftBotE2E('test_character_sharing')) suite.addTest(tests.TestDreamcraftBotE2E('test_delete_restore_characters')) results = unittest.TestResult() connect('mongoenginetest', host='mongomock://localhost') suite.run(results) disconnect() print(results) tests.print_results()
import falcon from pymongo import MongoClient import json import pandas as pd from datetime import datetime import re from wsgiref import simple_server import mongoengine as mongo from mongo_data import User, Experience, Education, CareerTimeline from falcon import testing from alt_app import ThingsResource, get_work_experience import pytest mongo.connect('user_data',port=27017) # first_name_true = ['Jarrah','Hassan','Emer'] class TestThings(testing.TestBase): def before(self): things = ThingsResource() self.api.add_route('/users', things) def test_true(self): body = self.simulate_request('/users?firstname=Jarrah','GET') self.assertEqual(self.srmock.status, falcon.HTTP_200) self.assertEqual(body.json, get_work_experience('Jarrah'))
For more information on this file, see https://docs.djangoproject.com/en/3.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ from pathlib import Path import mongoengine # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent mongoengine.connect(db="tools", host="localhost") # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-_=g7+_oti*r)cx-#_9(_v$*j6#d7!jk^oxx_lqel9l0ukt=0(d' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [
def setUpClass(cls): config.init_conf(package='spaceone.monitoring') connect('test', host='mongomock://localhost') super().setUpClass()
plt.grid(which='both', axis='y', linestyle=':') plt.yticks(np.arange(1, len(data) + 1), labels, rotation='horizontal', fontsize=8) #plt.gcf().subplots_adjust(bottom=.5) # plt.ylim(0, 1) plt.show() fig.savefig(f'figs/{name}_boxplot.png', dpi=300) if __name__ == '__main__': me.connect('performancedb', host=os.environ['MONGOHOST'], username=os.environ['USERNAME'], password=os.environ['PASSWORD']) # New setups with more tuning-samples and changed rebuild frequency homoID = '5f44050def458403b65f97fa' imhomoID = '5f44050def458403b65f97f9' sha = '20382287f7f3d1ff2aa8414891ea657245670c80' h**o = Setup.objects().get(id=homoID) inhomo = Setup.objects().get(id=imhomoID) for s_name, setup in zip(['h**o', 'inhomo'], [h**o, inhomo]): configs = Config.objects(setup=setup, commitSHA=sha) # TODO: Remove limit here for conf in configs:
from djangoreactredux.settings.base import * # NOQA (ignore all errors on this line) from djangoreactredux.settings.local import * DEBUG = True PAGE_CACHE_SECONDS = 1 DATABASES = { 'default': { 'ENGINE': '', }, 'unified': UNIFIED_DB, } mongoengine.connect(db=MONGODB_DATABASES['default']['NAME'], ) REST_FRAMEWORK[ 'EXCEPTION_HANDLER'] = 'django_rest_logger.handlers.rest_exception_handler' # NOQA (ignore all errors on this line) LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'root': { 'level': 'DEBUG', 'handlers': ['django_rest_logger_handler'], }, 'formatters': { 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s '
import flask from flask_restful import Api from mongoengine import connect from mongoengine.connection import disconnect from api import PersonScoreResource from db.db import db from scripts.initialize_db import initialize mongo_url = os.getenv('MONGO_URL') app = flask.Flask(__name__) app.config['MONGODB_DB'] = 'basec' app.config['MONGODB_HOST'] = mongo_url connect('basec', host=mongo_url, port=27017) resource_api = Api(app) resource_api.add_resource(PersonScoreResource, '/evento/<string:cpf>') def init(): disconnect() db.init_app(app) with app.app_context(): initialize() app.run(host='0.0.0.0', port=5002, debug=True) init()
def handle(self, *args, **options): sourceclassfile = os.path.join(options['tmpdir'], os.path.basename(options['sourcecorpus']).replace('.txt','') + '.colibri.cls') sourcecorpusfile = os.path.join(options['tmpdir'], os.path.basename(options['sourcecorpus']).replace('.txt','') + '.colibri.dat') sourcemodelfile = os.path.join(options['tmpdir'], os.path.basename(options['sourcecorpus']).replace('.txt','') + '.colibri.patternmodel') if not os.path.exists(sourceclassfile) or not os.path.exists(sourcecorpusfile) or options['force']: self.stdout.write("Encoding source corpus ...") sourceclassencoder = colibricore.ClassEncoder() sourceclassencoder.build(options['sourcecorpus']) sourceclassencoder.save(sourceclassfile) sourceclassencoder.encodefile(options['sourcecorpus'], sourcecorpusfile) self.stdout.write(self.style.SUCCESS('DONE')) else: self.stdout.write("Reusing previously encoded source corpus ...") targetclassfile = os.path.join(options['tmpdir'], os.path.basename(options['targetcorpus']).replace('.txt','') + '.colibri.cls') targetcorpusfile = os.path.join(options['tmpdir'], os.path.basename(options['targetcorpus']).replace('.txt','') + '.colibri.dat') targetmodelfile = os.path.join(options['tmpdir'], os.path.basename(options['targetcorpus']).replace('.txt','') + '.colibri.patternmodel') if not os.path.exists(targetclassfile) or not os.path.exists(targetcorpusfile) or options['force']: self.stdout.write("Encoding target corpus ...") targetclassencoder = colibricore.ClassEncoder() targetclassencoder.build(options['targetcorpus']) targetclassencoder.save(targetclassfile) targetclassencoder.encodefile(options['targetcorpus'], targetcorpusfile) self.stdout.write(self.style.SUCCESS('DONE')) else: self.stdout.write("Reusing previously encoded target corpus ...") modeloptions = colibricore.PatternModelOptions(mintokens=options['freqthreshold'],maxlength=options['maxlength']) if not os.path.exists(sourcemodelfile) or options['force']: self.stdout.write('Computing pattern model of source corpus ...') sourcemodel = colibricore.UnindexedPatternModel() sourcemodel.train(sourcecorpusfile, modeloptions) sourcemodel.write(sourcemodelfile) self.stdout.write(self.style.SUCCESS('DONE')) else: sourcemodel = None self.stdout.write("Reusing previously computed source model ...") if not os.path.exists(targetmodelfile) or options['force']: self.stdout.write('Computing pattern model of target corpus ...') targetmodel = colibricore.UnindexedPatternModel() targetmodel.train(targetcorpusfile, modeloptions) targetmodel.write(targetmodelfile) self.stdout.write(self.style.SUCCESS('DONE')) else: targetmodel = None self.stdout.write("Reusing previously computed target model ...") alignmodelfile = os.path.join(options['tmpdir'], "alignmodel.colibri") #delete models to conserve memory during next step if sourcemodel is not None: del sourcemodel self.stdout.write(self.style.SUCCESS('Unloaded source patternmodel')) if targetmodel is not None: del targetmodel self.stdout.write(self.style.SUCCESS('Unloaded target patternmodel')) if not os.path.exists(alignmodelfile) or options['force']: cmd = "colibri-mosesphrasetable2alignmodel -i " + options['phrasetable'] + " -o " + alignmodelfile + " -S " + sourceclassfile + " -T " + targetclassfile + " -m " + sourcemodelfile + " -M " + targetmodelfile + " -t " + str(options['freqthreshold']) + " -l " + str(options['maxlength']) + " -p " + str(options['pts']) + " -P " + str(options['pst']) + " -j " + str(options['joinedthreshold']) + " -d " + str(options['divergencethreshold']) self.stdout.write("Computing alignment model: " + cmd) os.system(cmd) self.stdout.write(self.style.SUCCESS('DONE')) else: self.stdout.write(self.style.SUCCESS('Reusing previously computed alignment model')) self.stdout.write("Loading models") sourceclassdecoder = colibricore.ClassDecoder(sourceclassfile) targetclassdecoder = colibricore.ClassDecoder(targetclassfile) sourcemodel = colibricore.UnindexedPatternModel(sourcemodelfile, modeloptions) targetmodel = colibricore.UnindexedPatternModel(targetmodelfile, modeloptions) alignmodel = colibricore.PatternAlignmentModel_float(alignmodelfile, modeloptions) self.stdout.write(self.style.SUCCESS('DONE')) #collection,_ = Collection.objects.get_or_create(name=options['title'], sourcelanguage=options['sourcelang'], targetlanguage=options['targetlang']) #collection_id = 1 l = len(alignmodel) self.stdout.write("Connecting to MongoDB server at " + settings.MONGODB_HOST + ":" + str(settings.MONGODB_PORT) ) mongoengine.connect("colloquery", host=settings.MONGODB_HOST, port=settings.MONGODB_PORT) self.stdout.write("Generating translation pairs (this may take a while)..." ) targetcollocations = {} prevsourcepattern = None collection = Collection(name=options['title'], sourcelanguage=options['sourcelang'], targetlanguage=options['targetlang']) collection.save() sourcecount = 0 for i, (sourcepattern, targetpattern, scores) in enumerate(alignmodel.triples()): if i % 100 == 0: self.stdout.write(str(round(((sourcecount + 1) / l) * 100,1)) + "% -- @" + str(sourcecount + 1) + " of " + str(l) + ": inserted " + str(i+1) + " pairs") #(source=" + str(n_source) + ", target=" + str(n_target) + ", source-keywords=" + str(n_source_keywords) + ", target-keywords=" + str(n_target_keywords) + ")") if prevsourcepattern is None or sourcepattern != prevsourcepattern: prevsourcepattern = sourcepattern sourcecount += 1 sourcefreq = sourcemodel[sourcepattern] text = sourcepattern.tostring(sourceclassdecoder) if ignorable(text): continue sourcecollocation = Collocation(collection=collection, language=options['sourcelang'], text=text, freq=sourcefreq) sourcecollocation.save() targetfreq = targetmodel[targetpattern] text = targetpattern.tostring(targetclassdecoder) if ignorable(text): continue if targetpattern in targetcollocations: #quicker in-memory lookup # targetcollocation = Collocation.objects(text=text, language=options['targetlang'], collection=collection)[0] #get from db targetcollocation = targetcollocations[targetpattern] else: targetcollocation = Collocation(collection=collection, language=options['targetlang'], text=text, freq=targetfreq) targetcollocation.save() #self.stdout.write(repr(targetcollocation.id)) targetcollocations[targetpattern] = targetcollocation.id Translation(source=sourcecollocation, target=targetcollocation, prob=scores[0], revprob=scores[2]).save() Translation(source=targetcollocation, target=sourcecollocation, prob=scores[2], revprob=scores[0]).save()
] WSGI_APPLICATION = 'dianaapi.wsgi.application' # Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases # DATABASES = { # 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), # } # } mongoengine.connect('test') # Password validation # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, {
def tearDown(self): connect( db = MONGODB['db'], host = MONGODB['host'], port = MONGODB['port'] ).drop_database(MONGODB['db'])
'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'wonderland_backend.wsgi.application' DATABASES = {'default': {'ENGINE': ''}} connect(config['MONGODB_NAME'], host=config['MONGODB_CONNECT_STRING']) AUTH_PASSWORD_VALIDATORS = [] LANGUAGE_CODE = 'zh-hant' TIME_ZONE = 'Asia/Taipei' USE_I18N = True USE_L10N = True USE_TZ = True STATIC_URL = '/static/'
] WSGI_APPLICATION = 'ComplaintDjango.wsgi.application' # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': None, } } from mongoengine import connect connect('Complaint') # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, {
def connect(): mongoengine.connect(db_name, host=host, port=port, username=user_name, password=password)
def __init__(self): connect('feedrebot', host=MONGO_HOST, port=MONGO_PORT)
product_name = product['name'] price = str(product['price']) #price currency = product['currency'] #currency quantity = str(product['quantity']) #quantity # Retrieve the product type from Knowledge Graph try: url_encoded_product_name = os.getenv("KG_SERVICE_URI")+"productcategory/?product_name="+urllib.parse.quote(product_name) product_type = urllib.request.urlopen(url_encoded_product_name).read() except: product_type="" # If the product type is not empty, insert it to neo4j if(len(product_type)>0): insert_transactions(userName, email, product_name, product_type, location, purchaseDate, quantity, price, currency, merchant) counter = counter + 1 if __name__ == "__main__": load_dotenv() connect(host=os.getenv('MONGODB_URI')) neo4j_uri = os.getenv('NEO4J_URI') neo4j_user = os.getenv('NEO4J_USER') neo4j_password = os.getenv('NEO4J_PASSWORD') driver = GraphDatabase.driver(neo4j_uri, auth=(neo4j_user, neo4j_password)) update_property_graph_transaction() build_recommendation()
from flask import Flask from mongoengine import connect from flask.ext.script import Manager from flask.ext.httpauth import HTTPBasicAuth import os import config #create flask object and other flask objects flaskApp = Flask("pycomm") flaskApp.config.from_object('config') connect("pycommappdb") auth = HTTPBasicAuth() flaskManager = Manager(flaskApp) from app import models, views
def init(): mongoengine.connect('premote') connection_handler()
import mongoengine mongoengine.connect('mumblr-example') import os PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) #MEDIA_ROOT = os.path.join(PROJECT_PATH, '..', 'mumblr', 'static') SECRET_KEY = '$geoon8_ymg-k)!9wl3wloq4&30w$rhc1*zv%h6m_&nza(4)nk' RECAPTCHA_PUBLIC_KEY = "6LfFgQoAAAAAABQTj4YjuPbccgKtZStoiWtr7E5k" RECAPTCHA_PRIVATE_KEY = "6LfFgQoAAAAAAM-0SAUTe7WxZ-thnWFfSpoc7sfJ"
def setup_method(self, method): """ setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. """ connect('authserver-db-test', host='mongomock://localhost', alias='test')
}, } } CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'my_cache_table', #python manage.py createcachetable my_cache_table } } DB_HOST = 'localhost' client = MongoClient(DB_HOST, 27017) DB = client.stocktrace mongoengine.connect(host=DB_HOST, db='stocktrace') YAHOO = "yahoo" SINA = 'sina' CSV_ENGINE = "csv" STOCK_LIST_ALL = 'stock_list_all' STOCK_LIST_HOLD = 'stock_list_hold' STOCK_LIST_TOP100 = 'stock_list_top100' STOCK_LIST_SELF_SELECTION = 'stock_list_self_selection' ALL_LIST = [ STOCK_LIST_ALL, STOCK_LIST_HOLD, STOCK_LIST_SELF_SELECTION, STOCK_LIST_TOP100 ] DOWNLOAD_KEY_STAT = False DOWNLOAD_LATEST_PRICE = True HIGHER = 1
WSGI_APPLICATION = 'JDweb.wsgi.application' # Database # https://docs.djangoproject.com/en/1.10/ref/settings/#databases # DATABASES = { # 'default': { # 'ENGINE': None, # #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), # } # } #使用mongiengine from mongoengine import connect connect('jd', host='127.0.0.1', port=27017) #使用已运行的数据库 # Password validation # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME':
parser = argparse.ArgumentParser(prog=PROJECT_NAME, usage='%(prog)s [options]') parser.add_argument('--mongo_uri', help='MongoDB credentials', default='mongodb://localhost:27017/iptv') parser.add_argument('--mysql_host', help='MySQL host', default='localhost') parser.add_argument('--mysql_user', help='MySQL username', default='root') parser.add_argument('--mysql_password', help='MySQL password', default='') parser.add_argument('--mysql_port', help='MySQL port', default=3306) parser.add_argument('--server_id', help='Server ID', default='') argv = parser.parse_args() mysql_host = argv.mysql_host mysql_user = argv.mysql_user mysql_password = argv.mysql_password mysql_port = argv.mysql_port server_id = argv.server_id mongo = connect(host=argv.mongo_uri) if not mongo: sys.exit(1) ser = ServiceSettings.objects(id=server_id).first() if not ser: sys.exit(1) d = mysql.connector.connect( host=mysql_host, port=mysql_port, user=mysql_user, passwd=mysql_password, database='xtream_iptvpro' )
from mongoengine import connect from monkey_island.cc.environment.environment import env # This section sets up the DB connection according to the environment. # If testing, use mongomock which only emulates mongo. for more information, see # http://docs.mongoengine.org/guide/mongomock.html . # Otherwise, use an actual mongod instance with connection parameters supplied by env. if env.testing: # See monkey_island.cc.environment.testing connect('mongoenginetest', host='mongomock://localhost') else: connect(db=env.mongo_db_name, host=env.mongo_db_host, port=env.mongo_db_port) # Order of importing matters here, for registering the embedded and referenced documents before using them. from .config import Config # noqa: F401 from .creds import Creds # noqa: F401 from .monkey_ttl import MonkeyTtl # noqa: F401 from .pba_results import PbaResults # noqa: F401 from .command_control_channel import CommandControlChannel # noqa: F401 from .monkey import Monkey # noqa: F401