From 04ba22be09600333993ceb9d66d96a4128cefaa0 Mon Sep 17 00:00:00 2001 From: Pavel Dik Date: Fri, 18 Nov 2016 12:44:02 +0500 Subject: [PATCH 1/8] Add .gitignore --- .gitignore | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/.gitignore b/.gitignore index b7a3ffa..5a49f96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,105 @@ settings_local.py *.pyc +Thumbs.db +ehthumbs.db +Desktop.ini +$RECYCLE.BIN/ +*.cab +*.msi +*.msm +*.msp +*.lnk +*~ +.fuse_hidden* +.directory +.Trash-* +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +*.manifest +*.spec +pip-log.txt +pip-delete-this-directory.txt +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ +*.mo +*.pot +*.log +local_settings.py +instance/ +.webassets-cache +.scrapy +docs/_build/ +target/ +.ipynb_checkpoints +.python-version +celerybeat-schedule +.env +venv/ +ENV/ +.spyderproject +.ropeproject +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml +.idea/gradle.xml +.idea/libraries +.idea/mongoSettings.xml +*.iws +/out/ +.idea_modules/ +atlassian-ide-plugin.xml +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +*.DS_Store +.AppleDouble +.LSOverride +Icon +._* +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +.idea/ From 1602f04f8d8e2b5d213cccab7a28d3db02914224 Mon Sep 17 00:00:00 2001 From: Pavel Dik Date: Tue, 22 Nov 2016 17:35:45 +0500 Subject: [PATCH 2/8] Add routing by filename --- app.py | 17 +++++++++++++---- tests/test.py | 7 ++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 9aa7df7..36daa2a 100644 --- a/app.py +++ b/app.py @@ -37,11 +37,19 @@ def serve_partial_file_request(request, headers, file, start, end, callbacks=[]) headers=headers, status=206) -def serve_request(request, connection, _id=None): +def serve_request(request, connection, _id=None, filename=None): fs = GridFS(connection[settings.MONGO_DB_NAME]) - try: - file = fs.get(_id) - except: + if _id: + try: + file = fs.get(_id) + except: + abort(404) + elif filename: + try: + file = fs.get_last_version(filename) + except: + abort(404) + else: abort(404) if getattr(file, 'pending', False): @@ -91,6 +99,7 @@ def serve_request(request, connection, _id=None): url_map = Map([ Rule('/'), + Rule('/'), ], converters={ 'ObjectId': ObjectIdConverter, }) diff --git a/tests/test.py b/tests/test.py index a2358c9..c9203d1 100644 --- a/tests/test.py +++ b/tests/test.py @@ -22,7 +22,8 @@ def setUpClass(cls): def put_file(self, path): f = open(path, 'rb') - filename = os.path.basename(path) + + filename = os.path.relpath(path) return self.fs.put(f.read(), filename=filename) def get_file(self, _id, headers={}): @@ -38,6 +39,10 @@ def test(self): content = StringIO(r._app_iter[0]) self.assertEquals(open(file_path).read(), content.read()) + r = self.app.get('/%s' % os.path.relpath(file_path)) + content = StringIO(r._app_iter[0]) + self.assertEquals(open(file_path).read(), content.read()) + self.app.get('/%s/' % file_id, status=404) def test_range(self): From 94f7f9c9950bab6325fd2ac36b6264bc4c7af95e Mon Sep 17 00:00:00 2001 From: Pavel Dik Date: Tue, 22 Nov 2016 17:36:20 +0500 Subject: [PATCH 3/8] Update libs --- requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 84ab8a9..403ae2a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Werkzeug==0.8.2 -pymongo==2.4.2 +Werkzeug==0.11.11 +pymongo==3.3.1 WebTest==2.0.9 -Unidecode==0.04.9 +Unidecode==0.04.9bre From 164897ecdabb5a8d4841b8d344420adf58533f13 Mon Sep 17 00:00:00 2001 From: Pavel Dik Date: Tue, 22 Nov 2016 17:44:03 +0500 Subject: [PATCH 4/8] Add Dockerfile --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..79e0ce0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:2.7 + +WORKDIR app +ADD requirements.txt requirements.txt +RUN pip install uwsgi +RUN pip install -r requirements.txt +COPY . . +CMD uwsgi --socket=:8001 --module=wsgi:app From 5b0f25b8702f416127f870c62d641fc3f78bc483 Mon Sep 17 00:00:00 2001 From: Pavel Dik Date: Tue, 22 Nov 2016 18:08:29 +0500 Subject: [PATCH 5/8] Update libs --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 403ae2a..1e97518 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ Werkzeug==0.11.11 pymongo==3.3.1 WebTest==2.0.9 -Unidecode==0.04.9bre +Unidecode==0.04.19 From fce31f3c5d3520eff626b0408020dcbd387f8499 Mon Sep 17 00:00:00 2001 From: MerliX Date: Mon, 27 Feb 2017 13:38:59 +0500 Subject: [PATCH 6/8] pymongo upgrade to 3.4.0; settings based on mongo_url --- requirements.txt | 2 +- settings.py | 18 +++--------------- settings_test.py | 3 +-- utils.py | 9 +-------- 4 files changed, 6 insertions(+), 26 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1e97518..8f93c81 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ Werkzeug==0.11.11 -pymongo==3.3.1 +pymongo==3.4.0 WebTest==2.0.9 Unidecode==0.04.19 diff --git a/settings.py b/settings.py index 75422b0..dbba903 100644 --- a/settings.py +++ b/settings.py @@ -1,30 +1,18 @@ import sys -from pymongo.read_preferences import ReadPreference - - -# Mongo section -MONGO_HOST = 'localhost' -MONGO_PORT = 27017 -MONGO_DB_NAME = 'grid_fs' -MONGO_REPLICATION_ON = True -MONGO_REPLICA_SET_URI = 'localhost:27017,localhost:27018' -MONGO_REPLICA_SET_NAME = 'test_set' -MONGO_READ_PREFERENCE = ReadPreference.PRIMARY_PREFERRED - +MONGO_DB_URL = 'mongodb://localhost:27017,localhost:27018/grid_fs?' \ + 'replicaSet=test_set&readPreference=primaryPreferred' # App section for builtin server APP_HOST = '0.0.0.0' APP_PORT = 5000 DEBUG = True - try: from settings_local import * except ImportError: pass - -if 'test' in sys.argv[0]: # Is there another way? +if 'test' in sys.argv[0]: # Is there another way? try: from settings_test import * except ImportError: diff --git a/settings_test.py b/settings_test.py index 49e10b4..68ec7b2 100644 --- a/settings_test.py +++ b/settings_test.py @@ -1,4 +1,3 @@ DEBUG = True -MONGO_DB_NAME = 'grid_fs_test' -MONGO_REPLICATION_ON = False +MONGO_DB_URL = 'mongodb://username:password@localhost:27017/grid_fs_test' diff --git a/utils.py b/utils.py index c4f8783..3a1e949 100644 --- a/utils.py +++ b/utils.py @@ -34,14 +34,7 @@ def next(self): def get_mongodb_connection(): - if settings.MONGO_REPLICATION_ON: - return MongoReplicaSetClient( - settings.MONGO_REPLICA_SET_URI, - read_preference=settings.MONGO_READ_PREFERENCE, - replicaset=settings.MONGO_REPLICA_SET_NAME, w=1) - else: - return MongoClient(settings.MONGO_HOST, settings.MONGO_PORT) - + return MongoClient(settings.MONGO_DB_URL) class MongoDBConnection(object): From 99e351b3b85c6343d20e9c52a0146eb1df0e2285 Mon Sep 17 00:00:00 2001 From: Max Pomazuev Date: Thu, 2 Mar 2017 19:04:51 +0500 Subject: [PATCH 7/8] auth --- settings.py | 3 +++ utils.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/settings.py b/settings.py index 75422b0..8b1757e 100644 --- a/settings.py +++ b/settings.py @@ -11,6 +11,9 @@ MONGO_REPLICA_SET_URI = 'localhost:27017,localhost:27018' MONGO_REPLICA_SET_NAME = 'test_set' MONGO_READ_PREFERENCE = ReadPreference.PRIMARY_PREFERRED +MONGO_PASSWORD = None +MONGO_USER = None + # App section for builtin server APP_HOST = '0.0.0.0' diff --git a/utils.py b/utils.py index c4f8783..7e4cb0e 100644 --- a/utils.py +++ b/utils.py @@ -40,7 +40,9 @@ def get_mongodb_connection(): read_preference=settings.MONGO_READ_PREFERENCE, replicaset=settings.MONGO_REPLICA_SET_NAME, w=1) else: - return MongoClient(settings.MONGO_HOST, settings.MONGO_PORT) + return MongoClient( + settings.MONGO_HOST, settings.MONGO_PORT, + password=settings.MONGO_PASSWORD, user=settings.MONGO_USER) From 53e9b76e97238f45cebb61e4e5ba71f205210f86 Mon Sep 17 00:00:00 2001 From: Max Pomazuev Date: Fri, 3 Mar 2017 13:03:43 +0500 Subject: [PATCH 8/8] smth --- settings.py | 20 +++++++++++--------- settings_test.py | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/settings.py b/settings.py index 0ca253d..9674c1e 100644 --- a/settings.py +++ b/settings.py @@ -4,15 +4,17 @@ # Mongo section -MONGO_HOST = 'localhost' -MONGO_PORT = 27017 -MONGO_DB_NAME = 'grid_fs' -MONGO_REPLICATION_ON = True -MONGO_REPLICA_SET_URI = 'localhost:27017,localhost:27018' -MONGO_REPLICA_SET_NAME = 'test_set' -MONGO_READ_PREFERENCE = ReadPreference.PRIMARY_PREFERRED -MONGO_PASSWORD = None -MONGO_USER = None +# MONGO_HOST = 'localhost' +# MONGO_PORT = 27017 +# MONGO_DB_NAME = 'grid_fs' + +# MONGO_REPLICATION_ON = True +# MONGO_REPLICA_SET_URI = 'localhost:27017,localhost:27018' +# MONGO_REPLICA_SET_NAME = 'test_set' +# MONGO_READ_PREFERENCE = ReadPreference.PRIMARY_PREFERRED + +# MONGO_PASSWORD = None +# MONGO_USER = None MONGO_DB_URL = 'mongodb://localhost:27017,localhost:27018/grid_fs?' \ diff --git a/settings_test.py b/settings_test.py index 68ec7b2..5dbf07a 100644 --- a/settings_test.py +++ b/settings_test.py @@ -1,3 +1,3 @@ DEBUG = True -MONGO_DB_URL = 'mongodb://username:password@localhost:27017/grid_fs_test' +MONGO_DB_URL = 'mongodb://localhost:27017/grid_fs_test'