Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for io.StringIO #2

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
078c72f
Add support for Python3
ekapratama93 Jan 30, 2018
092d91e
update version
Jul 25, 2018
8ea4c7d
Update __init__.py
ekapratama93 Jul 25, 2018
096ad32
change how check date & delete gridfs
ekapratama93 Apr 5, 2019
fcbe02c
fix logic check on exists
ekapratama93 Apr 5, 2019
050c5a4
add result storage
ekapratama93 Apr 5, 2019
3fe2f84
fix function call
ekapratama93 Apr 5, 2019
c8a9097
fix flake8
ekapratama93 Apr 5, 2019
6be9572
fix flake8
ekapratama93 Apr 5, 2019
040e710
refactor storage
ekapratama93 Apr 5, 2019
4159c01
add logging
ekapratama93 Apr 12, 2019
20e9c88
add requirements.txt
ekapratama93 Apr 12, 2019
e8d1eca
change storage get max age
ekapratama93 Apr 12, 2019
a718ca8
fix test
ekapratama93 Apr 12, 2019
9c332b4
add storage vows
ekapratama93 Apr 12, 2019
ad76f3a
add connection using URI
ekapratama93 Apr 12, 2019
d524916
remove stringIO
ekapratama93 Apr 12, 2019
e4dc1fd
add ensure index
ekapratama93 Apr 15, 2019
698e236
change key
ekapratama93 Apr 15, 2019
3700492
use ResultStorageResult
ekapratama93 Apr 15, 2019
9cc3b44
fix result storage
ekapratama93 Apr 22, 2019
6afeea5
future get
ekapratama93 Apr 22, 2019
9644caf
future last_updated
ekapratama93 Apr 22, 2019
71189a4
update class
ekapratama93 Apr 22, 2019
e92a381
make singleton connection
ekapratama93 Apr 23, 2019
1b28302
add missing package
ekapratama93 Apr 23, 2019
2f7c99b
separate connector
ekapratama93 Apr 23, 2019
e6a4fc7
pin pymongo version
ekapratama93 Jul 6, 2020
d69ca00
exclude thumbor 7
ekapratama93 Jul 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ docs/_build/

# PyBuilder
target/

# Virtual environtment
venv
.env
.venv

# Editor stuff
.vscode

# OS stuff
.DS_Store
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: prepare-test
prepare-test:
pip install pyvows coverage tornado_pyvows

.PHONY: test
test:
@echo "Restart MongoDB"
@docker-compose down
@docker-compose up -d
@echo "Run Vows"
@pyvows -c -l tc_mongodb
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '2.3'
services:
mongo:
image: mvertes/alpine-mongo:4.0.5-0
container_name: thumbor_mongo
ports:
- 27017:27017
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pymongo==3.10.1
thumbor>=5.0.0
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ def read(fname):

setup(
name="tc_mongodb",
version="5.1.0",
version="5.3.0",
author="Thumbor Community",
description=("Thumbor thumbor storage adapters"),
license="MIT",
keywords="thumbor mongodb mongo",
url="https://github.com/thumbor-community/mongodb",
packages=[
packages=find_packages(include=[
'tc_mongodb',
'tc_mongodb.mongodb',
'tc_mongodb.storages',
'tc_mongodb.result_storages'
],
]),
long_description=long_description,
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2.7',
],
install_requires=[
'thumbor>=5.0.0',
'pymongo'
'thumbor>=6.5.1,<7.0.0',
'pymongo==3.10.1'
]
)
5 changes: 0 additions & 5 deletions tc_mongodb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@

Config.define('MONGO_STORAGE_SERVER_HOST', 'localhost', 'MongoDB storage server host', 'MongoDB Storage')
Config.define('MONGO_STORAGE_SERVER_PORT', 27017, 'MongoDB storage server port', 'MongoDB Storage')
Config.define('MONGO_STORAGE_SERVER_DB', 'thumbor', 'MongoDB storage server database name', 'MongoDB Storage')
Config.define('MONGO_STORAGE_SERVER_COLLECTION', 'images', 'MongoDB storage image collection', 'MongoDB Storage')
Empty file added tc_mongodb/mongodb/__init__.py
Empty file.
54 changes: 54 additions & 0 deletions tc_mongodb/mongodb/connector_result_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from pymongo import ASCENDING, DESCENDING, MongoClient


class Singleton(type):
"""
Define an Instance operation that lets clients access its unique
instance.
"""

def __init__(cls, name, bases, attrs, **kwargs):
super(Singleton, cls).__init__(name, bases, attrs)
cls._instance = None

def __call__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instance


class MongoConnector(object):
__metaclass__ = Singleton

def __init__(self,
uri=None,
host=None,
port=None,
db_name=None,
coll_name=None):
self.uri = uri
self.host = host
self.port = port
self.db_name = db_name
self.coll_name = coll_name
self.db_conn, self.coll_conn = self.create_connection()
self.ensure_index()

def create_connection(self):
if self.uri:
connection = MongoClient(self.uri)
else:
connection = MongoClient(self.host, self.port)

db_conn = connection[self.db_name]
coll_conn = db_conn[self.coll_name]

return db_conn, coll_conn

def ensure_index(self):
index_name = 'key_1_created_at_-1'
if index_name not in self.coll_conn.index_information():
self.coll_conn.create_index(
[('key', ASCENDING), ('created_at', DESCENDING)],
name=index_name
)
54 changes: 54 additions & 0 deletions tc_mongodb/mongodb/connector_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from pymongo import ASCENDING, DESCENDING, MongoClient


class Singleton(type):
"""
Define an Instance operation that lets clients access its unique
instance.
"""

def __init__(cls, name, bases, attrs, **kwargs):
super(Singleton, cls).__init__(name, bases, attrs)
cls._instance = None

def __call__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instance


class MongoConnector(object):
__metaclass__ = Singleton

def __init__(self,
uri=None,
host=None,
port=None,
db_name=None,
coll_name=None):
self.uri = uri
self.host = host
self.port = port
self.db_name = db_name
self.coll_name = coll_name
self.db_conn, self.coll_conn = self.create_connection()
self.ensure_index()

def create_connection(self):
if self.uri:
connection = MongoClient(self.uri)
else:
connection = MongoClient(self.host, self.port)

db_conn = connection[self.db_name]
coll_conn = db_conn[self.coll_name]

return db_conn, coll_conn

def ensure_index(self):
index_name = 'path_1_created_at_-1'
if index_name not in self.coll_conn.index_information():
self.coll_conn.create_index(
[('path', ASCENDING), ('created_at', DESCENDING)],
name=index_name
)
Loading