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

[WIP] Moving to Py3 #100

Closed
wants to merge 574 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
574 commits
Select commit Hold shift + click to select a range
7499cc7
make it more readable
asldevi Sep 26, 2013
20422fc
more clean up
asldevi Sep 26, 2013
12d8e9c
shorter path if size isn't there
asldevi Oct 2, 2013
650a678
add newlines
asldevi Oct 4, 2013
f298954
move from RQ to celery
asldevi Oct 4, 2013
f2e1f39
show loading gif if the bgtask isn't yet done
asldevi Oct 4, 2013
2467b6f
clean up setting up redis connection
asldevi Oct 4, 2013
7569c7b
script to run celery
asldevi Oct 7, 2013
2029f27
make response with loading img instead of redirection to it
asldevi Oct 7, 2013
c72058b
fix fitting into box
asldevi Oct 7, 2013
4f0030b
file endpoints instead of thumbnails everywhere
asldevi Oct 7, 2013
3dfda68
remove redundant and unused view
asldevi Oct 8, 2013
9afad82
make gallery public
asldevi Oct 8, 2013
997c74d
fix syntax in template
asldevi Oct 8, 2013
76bf16e
expire redis keys of running job registry in an hour
asldevi Oct 8, 2013
b7d369e
endpoint to remove old files from local cache
asldevi Oct 8, 2013
98af3f6
add loader image
asldevi Oct 9, 2013
69a34e1
put in celery in requirements
asldevi Oct 9, 2013
894bea6
fix back the broken pop_up_gallery
asldevi Oct 9, 2013
a523b8e
fix docs for usage of runcelery
asldevi Oct 10, 2013
3a9dc11
use Imgee field from baseframe
asldevi Oct 10, 2013
6b20553
simplify task registry
asldevi Oct 11, 2013
75a0ace
add function name also to task registry
asldevi Oct 11, 2013
0b95413
profile, img-size are now data attrs in ImgeeField
asldevi Oct 15, 2013
8077857
fixes to make tests pass; thx unittests
asldevi Oct 15, 2013
3ab146c
fix the fitting size again
asldevi Oct 17, 2013
e1afb32
imgee/storage.py
asldevi Oct 17, 2013
71e9dd5
put in funcname in taskid itself
asldevi Oct 17, 2013
770db71
move registry init to __init__.py
asldevi Oct 17, 2013
a11ff3a
add doctest to get resized size
asldevi Oct 17, 2013
1aeab97
make delete async
asldevi Oct 17, 2013
74a6735
script to run celery in production
asldevi Oct 17, 2013
1e7ed8a
no shortcuts for delete async
asldevi Oct 18, 2013
8b70222
have width and height cols instead of size in thumbnail
asldevi Oct 18, 2013
63fff62
no async if CELERY_ALWAYS_EAGER is set
asldevi Oct 21, 2013
2bc5f0a
add on_failure hook to BaseTask
asldevi Oct 21, 2013
3c0a115
remove thumbnails explicitly in delete
asldevi Oct 21, 2013
594a4e8
fix bug
asldevi Oct 21, 2013
03768d0
check for width or height - no need of both
asldevi Oct 21, 2013
6f590a5
actual sizes of thumbnails in db and in the names on s3, not requeste…
asldevi Oct 21, 2013
861c83e
fix use of secure_filename
asldevi Oct 21, 2013
2fb3060
save a db query
asldevi Oct 22, 2013
25265f7
public api for /file endpoint
asldevi Oct 22, 2013
276e024
add upload endpoint to api
asldevi Oct 23, 2013
2578684
make api a blueprint
asldevi Oct 23, 2013
568878f
fix logout bug
asldevi Oct 23, 2013
a6d77dd
include imgee url of the file in the api responses
asldevi Oct 23, 2013
0a43346
fix label bug
asldevi Oct 24, 2013
c36bd7e
put size in the imgee url, if available
asldevi Oct 24, 2013
998ebba
add label option in pop-up-gallery
asldevi Oct 24, 2013
f3fa016
let imgee.js make the url for popup
asldevi Oct 24, 2013
4719a1c
no dom creation in callee of .imgee
asldevi Oct 24, 2013
fb376df
move all logic into imgee.js
asldevi Oct 24, 2013
ab3781a
fix tests
asldevi Oct 24, 2013
380c6c5
put in version for api
asldevi Oct 28, 2013
af1a136
put in 404 check in api
asldevi Oct 28, 2013
4ddc45b
use filesizeformat
asldevi Oct 29, 2013
c842935
fix for breaking tests
asldevi Oct 29, 2013
9e35abb
make an errorhandler for api
asldevi Oct 29, 2013
4c6e17c
put in lastuser resource handler for auth
asldevi Oct 29, 2013
3016304
use filesizeformat again
asldevi Oct 29, 2013
f1694e3
Updated mail sender settings.
jace Oct 29, 2013
4f1ef4b
shorter path if size isn't there
asldevi Oct 2, 2013
c1bba67
add newlines
asldevi Oct 4, 2013
2195017
move from RQ to celery
asldevi Oct 4, 2013
8bad7d6
show loading gif if the bgtask isn't yet done
asldevi Oct 4, 2013
1b4cb08
clean up setting up redis connection
asldevi Oct 4, 2013
69520ae
script to run celery
asldevi Oct 7, 2013
231a608
make response with loading img instead of redirection to it
asldevi Oct 7, 2013
a6f5d0a
fix fitting into box
asldevi Oct 7, 2013
2812031
file endpoints instead of thumbnails everywhere
asldevi Oct 7, 2013
11cd43e
remove redundant and unused view
asldevi Oct 8, 2013
8b20245
make gallery public
asldevi Oct 8, 2013
9f55c90
fix syntax in template
asldevi Oct 8, 2013
5fffd4c
expire redis keys of running job registry in an hour
asldevi Oct 8, 2013
4841e83
endpoint to remove old files from local cache
asldevi Oct 8, 2013
33aa4e9
add loader image
asldevi Oct 9, 2013
cecac77
put in celery in requirements
asldevi Oct 9, 2013
7f7d1ed
fix back the broken pop_up_gallery
asldevi Oct 9, 2013
6b22026
fix docs for usage of runcelery
asldevi Oct 10, 2013
04b66f4
use Imgee field from baseframe
asldevi Oct 10, 2013
1081bbc
simplify task registry
asldevi Oct 11, 2013
4fec410
add function name also to task registry
asldevi Oct 11, 2013
191034d
profile, img-size are now data attrs in ImgeeField
asldevi Oct 15, 2013
a867078
fixes to make tests pass; thx unittests
asldevi Oct 15, 2013
22d5fef
fix the fitting size again
asldevi Oct 17, 2013
9b110d5
imgee/storage.py
asldevi Oct 17, 2013
3bbe6cb
put in funcname in taskid itself
asldevi Oct 17, 2013
6d877a7
move registry init to __init__.py
asldevi Oct 17, 2013
763dc8e
add doctest to get resized size
asldevi Oct 17, 2013
3b01543
make delete async
asldevi Oct 17, 2013
b97a915
script to run celery in production
asldevi Oct 17, 2013
656a674
no shortcuts for delete async
asldevi Oct 18, 2013
eb49e25
have width and height cols instead of size in thumbnail
asldevi Oct 18, 2013
15a3857
no async if CELERY_ALWAYS_EAGER is set
asldevi Oct 21, 2013
8d02208
add on_failure hook to BaseTask
asldevi Oct 21, 2013
aa20dc3
remove thumbnails explicitly in delete
asldevi Oct 21, 2013
9bf8e5a
fix bug
asldevi Oct 21, 2013
aa9afa2
check for width or height - no need of both
asldevi Oct 21, 2013
f431c6f
actual sizes of thumbnails in db and in the names on s3, not requeste…
asldevi Oct 21, 2013
37af078
fix use of secure_filename
asldevi Oct 21, 2013
5ab1474
save a db query
asldevi Oct 22, 2013
7dabe9a
public api for /file endpoint
asldevi Oct 22, 2013
bedc276
add upload endpoint to api
asldevi Oct 23, 2013
61bd9a8
make api a blueprint
asldevi Oct 23, 2013
3e8f267
fix logout bug
asldevi Oct 23, 2013
cca357f
include imgee url of the file in the api responses
asldevi Oct 23, 2013
5bd5464
fix label bug
asldevi Oct 24, 2013
028b177
put size in the imgee url, if available
asldevi Oct 24, 2013
0828978
add label option in pop-up-gallery
asldevi Oct 24, 2013
6f49a7b
let imgee.js make the url for popup
asldevi Oct 24, 2013
8c703b7
no dom creation in callee of .imgee
asldevi Oct 24, 2013
0921f19
move all logic into imgee.js
asldevi Oct 24, 2013
fb37709
fix tests
asldevi Oct 24, 2013
40fe796
put in version for api
asldevi Oct 28, 2013
df2eff2
put in 404 check in api
asldevi Oct 28, 2013
a3f66e8
use filesizeformat
asldevi Oct 29, 2013
9e1a5b0
fix for breaking tests
asldevi Oct 29, 2013
c45b405
make an errorhandler for api
asldevi Oct 29, 2013
55e7394
put in lastuser resource handler for auth
asldevi Oct 29, 2013
3e81ece
use filesizeformat again
asldevi Oct 29, 2013
578b8e0
'size' column is no longer in the table.
jace Oct 29, 2013
2124207
Allow multiple environments for Celery.
jace Oct 29, 2013
536ee82
enable celery error emails
asldevi Oct 30, 2013
691c80a
remove rq*
asldevi Oct 30, 2013
b18d852
fix broken thumbnail generation
asldevi Oct 30, 2013
b94e17c
fix 'browse your gallery' link
asldevi Oct 30, 2013
3738807
add title while uploading via api
asldevi Oct 30, 2013
a5d7b6a
Merge branch 'master' into develop
asldevi Oct 30, 2013
c42054d
manage.py now uses coaster.manage
miteshashar Nov 11, 2013
d6e4ea6
remove taskid even on failure from registry
asldevi Nov 12, 2013
25260fb
fix on_failure
asldevi Nov 12, 2013
6fd3c59
Merge pull request #42 from hasgeek/develop
jace Dec 11, 2013
91ed1f6
Profile page thumbnails alignment
miteshashar Dec 11, 2013
1b936b4
Image View Page - Thumbnail distortion
miteshashar Dec 12, 2013
01c3703
Correction: limit value was hardcoded.
miteshashar Dec 12, 2013
fa75232
Use mimetype instead of filename to validate file type for uploads.
miteshashar Dec 26, 2013
9fb290f
Bug fixed in determination of file type. File handler needs to point …
miteshashar Dec 27, 2013
626ed5e
Moved header-based checking of mimetype into the existing utility fun…
miteshashar Dec 27, 2013
75e91d7
StoredFile.orig_extn column
miteshashar Dec 27, 2013
fc8bea5
Storing the original extension of the image, when it is uploaded.
miteshashar Dec 27, 2013
3c22e11
Added mimetypes for .bmp files.
miteshashar Dec 28, 2013
9ca570e
Added mimetypes for corel draw files.
miteshashar Dec 28, 2013
2c15ad2
Made file mimetype and extension guessing more robust.
miteshashar Dec 28, 2013
f3ce299
Used the ALLOWED_MIMETYPES mapping dictionary to generate EXTNS to us…
miteshashar Dec 28, 2013
e9088ba
Corrected error in previous commit
miteshashar Dec 28, 2013
1610c0f
Corrected error in previous commit
miteshashar Dec 28, 2013
ce20518
Made extensions in the ALLOWED_MIMETYPES mapping dictionary unicode, …
miteshashar Dec 28, 2013
5335a00
StoredFile needs to be provided with unicode values for title and mim…
miteshashar Dec 28, 2013
c8baef5
Store width and height for svg
miteshashar Dec 28, 2013
920f7b8
Merge branch 'profile-page-thumbnails' into vector
miteshashar Dec 29, 2013
2246ea3
Merge branch 'imgviewpg-sidebar-thumbs' into vector
miteshashar Dec 29, 2013
21b4b83
Incorporated the CSS changes made in branches profile-page-thumbnails…
miteshashar Dec 29, 2013
cd6809f
Fixed:
miteshashar Dec 29, 2013
d49a2c7
Use PNG's for SVG embeds.
miteshashar Dec 30, 2013
0f50f21
Using subprocess.call instead of os.system
miteshashar Dec 30, 2013
a169718
If generation of an image preview fails, it should redirect to a gene…
miteshashar Dec 30, 2013
d9af656
Handle floating point dimensions in SVG's
miteshashar Dec 30, 2013
b230c4a
Corrected error message in /<profile>/new.json replaced earlier for d…
miteshashar Dec 30, 2013
ac2295d
/<profile>/new.json should respond with 403 when it cannot accept a f…
miteshashar Dec 30, 2013
2f92d0d
Removed shinedotted.png. It is blocked with a 403 code when used dire…
miteshashar Dec 30, 2013
d0b731e
Upgraded dropzone.js to 3.8.2. Bootstrap alert based notification for…
miteshashar Dec 30, 2013
d2c246c
AJAX-based update of Title, and on-page addition of image to the list…
miteshashar Dec 31, 2013
d44d6d7
Queue up generation of all regular image sizes, as soon as an image i…
miteshashar Dec 31, 2013
4544112
Made /embed/file/<image> blocking with a timeout of 15 seconds, after…
miteshashar Dec 31, 2013
1118809
On Image view page, the thumbnails in the sidebar were being vertical…
miteshashar Dec 31, 2013
3572c26
Moved dropzone on profile page to the sidebar.
miteshashar Dec 31, 2013
de72eb6
Corrected bugs in UI & AJAX for updating title of just uploaded image…
miteshashar Dec 31, 2013
766014c
Handling vertical align of thumbnails on profile page on the client s…
miteshashar Dec 31, 2013
1ce3683
Support for lastuser notifications.
jace Dec 31, 2013
5f5439a
Lastuser init should be in __init__; rename other imports.
jace Dec 31, 2013
6da8884
Mapping information for application/postscript corrected.
miteshashar Jan 1, 2014
4976a4a
gzipped .svgz files will be accepted by imgee
miteshashar Jan 1, 2014
cb7b43b
Use ImageMagick's convert command to resize images & identify command…
miteshashar Jan 2, 2014
e313b51
Removed command for rsvg-convert, as ImageMagick is capable of proces…
miteshashar Jan 2, 2014
664920a
convert should use -thumbnail for smaller output files, and should al…
miteshashar Jan 2, 2014
d394c00
Thumbnail extensions for various files. Corrected tiff to .tiff in ex…
miteshashar Jan 3, 2014
4359a9e
rsvg-convert is better off for SVG's. Switched back to it.
miteshashar Jan 3, 2014
4941bb2
Support for .svgz files.
miteshashar Jan 3, 2014
a4d1714
On profile page, use spinner.gif for dynamically placed thumbnails, t…
miteshashar Jan 3, 2014
94c1480
In-place editing for dynamically inserted image on the profile page.
miteshashar Jan 3, 2014
259643d
After adding images dynamically on profile page, while in list view, …
miteshashar Jan 3, 2014
bee33f0
rsvg-convert has in-built support for svgz. gunzip is not required.
miteshashar Jan 3, 2014
b8d4fc7
For tiff, thumb_extn = .png
miteshashar Jan 3, 2014
81c3f5e
convert and identify commands need to be called with -quiet to suppre…
miteshashar Jan 3, 2014
a15f981
No previews for PSD & CDR files.
miteshashar Jan 3, 2014
cd6ba1a
Added Flask-Alembic, xml4h & python-magic to requirements.txt
miteshashar Jan 5, 2014
96e95f7
Dropzone width should be 100% of it's container and not fixed-width.
miteshashar Jan 5, 2014
be5ddd5
Thumbnails in bottom row on profile page will not get cut-off anymore…
miteshashar Jan 5, 2014
3c9e8c9
Now that thumbnail formats may be different from original files' form…
miteshashar Jan 5, 2014
9b897cc
Shell script to install required libraries.
miteshashar Jan 5, 2014
db3a76b
Pillow is no longer required.
miteshashar Jan 5, 2014
3b80a3f
Flask-Admin seems to be a stale requirement. Removed.
miteshashar Jan 5, 2014
fa9bb18
Add -dUseCIEColor to all calls to ghostscript(as ImageMagick's delega…
miteshashar Jan 5, 2014
0b9d70d
Added librsvg2-dev to be installed for linux
miteshashar Jan 5, 2014
cd178d4
Update _version.py
jace Jan 29, 2014
f4cfe0d
ProfileMixin comes first.
jace Oct 9, 2014
799ac17
Fixes from comments.
jace Dec 19, 2014
b06a545
Fixes for SVG support.
jace Dec 19, 2014
d8b7b92
Travis env.
jace Dec 19, 2014
b9eddd7
Remove unused imports.
jace Dec 19, 2014
4dab8e0
Merge pull request #52 from hasgeek/vector
jace Dec 19, 2014
c78fdd5
Update .travis.yml
jace Aug 31, 2016
6154dd2
using updated flask import syntax
May 3, 2017
f36fa1d
Make init_for call implicit. Fixes #63 (#64)
May 4, 2017
2860cf8
add support for Flask-Migrate. Fixes #66 (#67)
May 5, 2017
3481cc2
assigning error handler the right way
May 31, 2017
f1dce80
removed init_for reference
May 31, 2017
505f008
Merge pull request #68 from hasgeek/fix-error-handler
jace May 31, 2017
fd8efa0
coaster.utils is now distinct
jace Jun 15, 2017
153ea3e
Imgee V2 (#59)
Jul 17, 2017
d7206c5
Update delete.html (#75)
karthikb351 Aug 22, 2017
2a00b9d
Switch to .html.jinja2 templates (Fixes #76) (#77)
Oct 13, 2017
b0dc221
not showing manage labels, delete button and edit title to anon user
Feb 23, 2018
56db726
replaced flask.ext with flask_
Aug 18, 2018
fdf3e97
Fix order_by queries.
jace May 16, 2019
200cebc
Create .pyup.yml
jace Jul 2, 2019
f16307a
Pin coverage to latest version 4.5.3 (#92)
pyup-bot Jul 2, 2019
6b837ca
Pin nose to latest version 1.3.7 (#91)
pyup-bot Jul 2, 2019
7237940
Pin pillow to latest version 6.0.0 (#90)
pyup-bot Jul 2, 2019
7e9e5e8
Pin flask-migrate to latest version 2.5.2 (#89)
pyup-bot Jul 2, 2019
0a667c1
Pin defusedxml to latest version 0.6.0 (#88)
pyup-bot Jul 2, 2019
d3d84e8
Pin python-magic to latest version 0.4.15 (#87)
pyup-bot Jul 2, 2019
31d524a
Pin xml4h to latest version 0.2.0 (#86)
pyup-bot Jul 2, 2019
4d12f1a
Pin redis to latest version 3.2.1 (#85)
pyup-bot Jul 2, 2019
50778ea
Pin boto to latest version 2.49.0 (#84)
pyup-bot Jul 2, 2019
aaa0838
Pin psycopg2 to latest version 2.8.3 (#83)
pyup-bot Jul 2, 2019
3ae2a33
Pin flask-sqlalchemy to latest version 2.4.0 (#82)
pyup-bot Jul 2, 2019
d1ccfbb
Pin sqlalchemy-utils to latest version 0.34.0 (#81)
pyup-bot Jul 2, 2019
5e40f5e
Pin sqlalchemy to latest version 1.3.5 (#80)
pyup-bot Jul 2, 2019
8e3cb29
Pin flask to latest version 1.0.3 (#79)
pyup-bot Jul 2, 2019
2486678
Scheduled monthly dependency update for August (#93)
pyup-bot Aug 5, 2019
c57b3d6
Caching the s3 check (#94)
Aug 7, 2019
8ae1dfc
Blackened all code (#95)
Aug 20, 2019
d11c65f
Scheduled monthly dependency update for October (#97)
pyup-bot Oct 3, 2019
325e893
Bump pillow from 6.1.0 to 6.2.0 (#98)
dependabot[bot] Oct 24, 2019
65e811e
Scheduled monthly dependency update for November (#99)
pyup-bot Nov 4, 2019
f69679f
2to3 changes
Dec 5, 2019
c3f49b7
2to3 changes
Dec 5, 2019
7db47ce
replaced boto with boto3
Jan 6, 2020
7fbfb1a
replaced boto with boto3
Jan 6, 2020
18d7474
fixed the tests
Jan 6, 2020
19ff95c
fixed the tests
Jan 6, 2020
2c4cbf3
removed unnecessary list and str
Jan 6, 2020
c3f4ca8
removed unnecessary list and str
Jan 6, 2020
25e5982
only need python 3 in travis
Jan 6, 2020
b14f97b
only need python 3 in travis
Jan 6, 2020
aa4d40a
removed testing.py
Jan 7, 2020
048c41d
removed testing.py
Jan 7, 2020
094dbca
Merge branch 'py3' of github.com:hasgeek/imgee into py3
Jan 7, 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
24 changes: 24 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[run]
source = imgee

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code
def __repr__
if self\.debug

# Don't complain about importerror handlers
except ImportError

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if False:
if __name__ == .__main__.:
8 changes: 4 additions & 4 deletions imgee/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

db = SQLAlchemy(app)

from imgee.models.user import * # NOQA # isort:skip
from imgee.models.stored_file import * # NOQA # isort:skip
from imgee.models.thumbnail import * # NOQA # isort:skip
from imgee.models.profile import * # NOQA # isort:skip
from .user import * # NOQA # isort:skip
from .stored_file import * # NOQA # isort:skip
from .thumbnail import * # NOQA # isort:skip
from .profile import * # NOQA # isort:skip
31 changes: 17 additions & 14 deletions imgee/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def save_file(fp, profile, title=None):
img_name = "%s%s" % (id_, extn)
local_path = path_for(img_name)

with open(local_path, 'w') as img:
with open(local_path, 'wb') as img:
img.write(fp.read())

stored_file = save_img_in_db(
Expand Down Expand Up @@ -153,23 +153,24 @@ def save_tn_in_db(img, tn_name, size):
return name


def save_on_s3(filename, remotename='', content_type='', bucket='', folder=''):
def save_on_s3(filename, remotename='', content_type=''):
"""
Save contents from file named `filename` to `remotename` on S3.
"""
b = bucket or get_s3_bucket()
folder = get_s3_folder(folder)
bucket = get_s3_bucket()
folder = get_s3_folder()
key = os.path.join(folder, filename)

with open(path_for(filename)) as fp:
with open(path_for(filename), 'rb') as fp:
filename = remotename or filename
k = b.new_key(folder + filename)
headers = {
'Cache-Control': 'max-age=31536000', # 60*60*24*365
'Content-Type': get_file_type(fp, filename),
# once cached, it is set to expire after a year
'Expires': datetime.utcnow() + timedelta(days=365),
}
k.set_contents_from_file(fp, policy='public-read', headers=headers)
bucket.put_object(
ACL='public-read',
Key=key,
Body=fp.read(),
CacheControl='max-age=31536000',
ContentType=content_type or get_file_type(fp, filename),
Expires=datetime.utcnow() + timedelta(days=365),
)
return filename


Expand Down Expand Up @@ -353,7 +354,9 @@ def delete(stored_file, commit=True):
keys = [(get_s3_folder() + thumbnail.name + extn) for thumbnail in thumbnails]
keys.append(get_s3_folder() + stored_file.name + extn)
bucket = get_s3_bucket()
bucket.delete_keys(keys)
bucket.delete_objects(
Delete={'Objects': [{'Key': key} for key in keys], 'Quiet': True}
)

# remove from the db
# remove thumbnails explicitly.
Expand Down
40 changes: 21 additions & 19 deletions imgee/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from flask import request

from boto import connect_s3
from boto.s3.bucket import Bucket
from boto.s3.key import Key
import boto3
import botocore
from PIL import Image
import defusedxml.cElementTree as ElementTree
import magic
Expand All @@ -19,6 +18,7 @@

from . import app


THUMBNAIL_COMMANDS = {
'inkscape': "inkscape -z -f {src} -e {src}.original.png && convert -quiet -thumbnail {width}x{height} {src}.original.png -colorspace sRGB -quality 75% {dest}",
'rsvg-convert': "rsvg-convert --width={width} --height={height} --keep-aspect-ratio=TRUE --format={format} {src} > {dest}",
Expand Down Expand Up @@ -303,9 +303,8 @@ def is_animated_gif(local_path):

def get_file_type(fp, filename=None):
fp.seek(0)
data = fp.read(1024) # https://github.com/ahupp/python-magic#usage
result = magic.from_buffer(fp.read(), mime=True)
fp.seek(0)
result = magic.from_buffer(data, mime=True)
if result in ('text/plain', 'text/xml', 'application/xml'):
if is_svg(fp):
return 'image/svg+xml'
Expand All @@ -322,14 +321,18 @@ def is_file_allowed(fp, provided_mimetype=None, filename=None):


# -- s3 related --
def get_s3_connection():
return connect_s3(app.config['AWS_ACCESS_KEY'], app.config['AWS_SECRET_KEY'])


def get_s3_client():
return boto3.resource(
's3',
aws_access_key_id=app.config['AWS_ACCESS_KEY'],
aws_secret_access_key=app.config['AWS_SECRET_KEY'],
)


def get_s3_bucket():
conn = get_s3_connection()
bucket = Bucket(conn, app.config['AWS_BUCKET'])
return bucket
return get_s3_client().Bucket(app.config['AWS_BUCKET'])


def get_s3_folder(f=''):
Expand All @@ -347,12 +350,10 @@ def exists_in_s3(thumb):
if 'thumb_extn' in ALLOWED_MIMETYPES[thumb.stored_file.mimetype]:
extn = ALLOWED_MIMETYPES[thumb.stored_file.mimetype]['thumb_extn']
key = os.path.join(folder, thumb.name + extn)
# print("checking whether exists in s3: {}".format(key))
resp = bucket.get_key(key)
if not resp:
# print("does not exist")
try:
bucket.Object(key).load()
except botocore.exceptions.ClientError:
return False
# print("exists")
return True


Expand All @@ -361,9 +362,8 @@ def download_from_s3(img_name):
if not os.path.exists(local_path):
bucket = get_s3_bucket()
folder = get_s3_folder()
k = Key(bucket)
k.key = os.path.join(folder, img_name)
k.get_contents_to_filename(local_path)
key = os.path.join(folder, img_name)
bucket.Object(key).download_file(local_path)
return local_path


Expand All @@ -378,6 +378,7 @@ def get_width_height(img_path):
o = check_output(
'identify -quiet -ping -format "%wx%h" {}[0]'.format(img_path),
shell=True,
universal_newlines=True
)
w, h = o.split('x')
elif extn in ['.cdr']:
Expand All @@ -394,7 +395,8 @@ def get_width_height(img_path):
w, h = int(round(float(wo))), int(round(float(ho)))
else:
o = check_output(
'identify -quiet -ping -format "%wx%h" {}'.format(img_path), shell=True
'identify -quiet -ping -format "%wx%h" {}'.format(img_path), shell=True,
universal_newlines=True
)
w, h = o.split('x')
return (w, h)
Expand Down
9 changes: 5 additions & 4 deletions imgee/views/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ def _redirect_url_frm_upload(profile_name):
def upload_file(profile):
upload_form = UploadImageForm()
if upload_form.validate_on_submit():
file_ = request.files['upload_file']
title, stored_file = save_file(file_, profile=profile)
flash('"%s" uploaded successfully.' % title)
return redirect(_redirect_url_frm_upload(profile.name))
imgfile = request.files['upload_file']
if imgfile.filename != '':
title, stored_file = save_file(imgfile, profile=profile)
flash('"%s" uploaded successfully.' % title)
return redirect(_redirect_url_frm_upload(profile.name))
return render_template('form.html.jinja2', form=upload_form, profile=profile)


Expand Down
10 changes: 5 additions & 5 deletions instance/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
UNKNOWN_FILE_THUMBNAIL = 'unknown.jpeg'

#: S3 Configuration; AWS credentials with restricted access
AWS_ACCESS_KEY = environ.get('AWS_ACCESS_KEY')
AWS_SECRET_KEY = environ.get('AWS_SECRET_KEY')
AWS_BUCKET = environ.get('AWS_BUCKET', 'imgee-testing')
#: S3 Configuration
AWS_ACCESS_KEY = 'AKIAIRIRVOH3RE5SKR4A'
AWS_SECRET_KEY = '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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They've been revoked. committed by mistake.

AWS_BUCKET = 'imgee'
AWS_FOLDER = 'test'

MEDIA_DOMAIN = 'https://%s.s3.amazonaws.com' % AWS_BUCKET
MEDIA_DOMAIN = 'http://%s.s3.amazonaws.com/' % AWS_BUCKET

SQLALCHEMY_DATABASE_URI = 'sqlite://'
WTF_CSRF_ENABLED = False
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ Flask-SQLAlchemy==2.4.1
psycopg2==2.8.4
https://github.com/hasgeek/flask-lastuser/zipball/master
https://github.com/jace/flask-alembic/archive/master.zip
boto==2.49.0
boto3==1.10.46
redis==3.3.11
xml4h==0.2.0
python-magic==0.4.15
defusedxml==0.6.0
Flask-Migrate==2.5.2
Expand Down
3 changes: 2 additions & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
set -e
export PYTHONIOENCODING="UTF-8"
export FLASK_ENV="TESTING"
coverage run `which nosetests` "$@"
coverage run -m pytest "$@"
coverage report -m
9 changes: 0 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ sections = FUTURE, STDLIB, SQLALCHEMY, FLASK, THIRDPARTY, FIRSTPARTY, LOCALFOLDE
# Bandit config for flake8-bandit. There's another copy in .pre-commit-config.yaml
[bandit]
exclude = tests, migrations, instance

[nosetests]
match=^test
nocapture=1
cover-package=imgee
with-coverage=1
cover-erase=1
with-doctest=1
where=tests
2 changes: 1 addition & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ImgeeTestCase(unittest.TestCase):
def get_test_user(self, name='testuser', uid=1):
u = User.query.filter_by(username=str(name)).first()
if not u:
userid = ''.join(random.sample(string.letters, 22))
userid = ''.join(random.sample(string.ascii_letters, 22))
u = User(
username=str(name),
userid=str(userid),
iambibhas marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 2 additions & 2 deletions tests/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class LabelTestCase(ImgeeTestCase):
def setUp(self):
super(LabelTestCase, self).setUp()
self.img_id = None
self.test_files = ['../imgee/static/img/imgee.png']
self.test_files = ['imgee/static/img/imgee.png']
self.test_labels = ['logos', 'banners', 'profile-photos']

def upload(self, path=None):
profile = self.get_test_profile()
sf = None
with open(path or self.test_files[0]) as fp:
with open(path or self.test_files[0], 'rb') as fp:
fs = FileStorage(fp)
title, sf = save_file(fs, profile)
return sf
Expand Down
10 changes: 5 additions & 5 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def setUp(self):
super(UploadTestCase, self).setUp()
self.img_id = None
self.test_files = [
'../imgee/static/img/imgee.png',
'../imgee/static/img/imgee.jpeg',
'../imgee/static/img/imgee.svg',
'../imgee/static/img/loading.gif',
'imgee/static/img/imgee.png',
'imgee/static/img/imgee.jpeg',
'imgee/static/img/imgee.svg',
'imgee/static/img/loading.gif',
]
self.test_labels = ['logos', 'banners', 'profile-photos']
self.files = self.upload_all()
Expand All @@ -38,7 +38,7 @@ def upload(self, path=None):
profile = self.get_test_profile()
sf = None
if path:
with open(path) as fp:
with open(path, 'rb') as fp:
fs = FileStorage(fp)
title, sf = save_file(fs, profile)
return sf
Expand Down