Skip to content

Commit

Permalink
fixed upload path issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibhas committed Jun 21, 2017
1 parent f2b4b26 commit 154b23c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions imgee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
lastuser.init_usermanager(UserManager(db, models.User))
registry.init_app()

# PYTHONPATH is `pwd` when testing and empty otherwise
# using it to determine the project root
# either get it from environment variable, or it's one level up from this init file
app.project_root = os.environ.get('PYTHONPATH', '') or os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print app.project_root


@app.errorhandler(403)
def error403(error):
Expand Down
3 changes: 2 additions & 1 deletion imgee/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timedelta
from glob import glob
import os.path
import os
import re
from subprocess import check_call, CalledProcessError
import time
Expand Down Expand Up @@ -292,7 +293,7 @@ def delete(stored_file, commit=True):
registry.remove_keys_starting_with(stored_file.name)

# remove locally
cache_path = app.config.get('UPLOADED_FILES_DEST')
cache_path = os.path.join(app.project_root, app.config.get('UPLOADED_FILES_DEST'))
os.remove(os.path.join(cache_path, '%s' % stored_file.filename))
cached_img_path = os.path.join(cache_path, '%s_*' % stored_file.name)
for f in glob(cached_img_path):
Expand Down
4 changes: 2 additions & 2 deletions imgee/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import re
import os.path
import os
from subprocess import check_output, CalledProcessError
from urlparse import urljoin

Expand Down Expand Up @@ -97,7 +97,7 @@ def get_file_url(scheme=None):


def path_for(img_name):
return os.path.join(app.config['UPLOADED_FILES_DEST'], img_name)
return os.path.join(app.project_root, app.config['UPLOADED_FILES_DEST'], img_name)


# -- mimetypes and content types
Expand Down
2 changes: 1 addition & 1 deletion instance/testing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os import environ
UPLOADED_FILES_DEST = 'tests/imgee/static/test_uploads'
UPLOADED_FILES_DEST = 'imgee/static/test_uploads'
AWS_FOLDER = 'test/'

UNKNOWN_FILE_THUMBNAIL = 'unknown.jpeg'
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def mkdir_p(dirname):

@manager.command
def init():
mkdir_p(app.config['UPLOADED_FILES_DEST'])
mkdir_p(os.path.join(app.project_root, app.config['UPLOADED_FILES_DEST']))

manager.run()
1 change: 1 addition & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh
set -e
export FLASK_ENV="TESTING"
export PYTHONPATH=$(pwd) # setting project root as PYTHONPATH
./manage.py init # creates the test upload directory
coverage run `which nosetests` "$@"
coverage report -m

0 comments on commit 154b23c

Please sign in to comment.