# HG changeset patch # User Marcin Kuzminski # Date 2019-02-01 12:35:49 # Node ID c25a37254027ba5d3ea129d91f9f48f46a67556d # Parent 415463b0f82ae57e7869e82f72d1305d85265678 file-store: rename module from upload_store to file_store. diff --git a/rhodecode/api/views/server_api.py b/rhodecode/api/views/server_api.py --- a/rhodecode/api/views/server_api.py +++ b/rhodecode/api/views/server_api.py @@ -39,8 +39,8 @@ from rhodecode.lib.utils2 import safe_in from rhodecode.model.db import UserIpMap from rhodecode.model.scm import ScmModel from rhodecode.model.settings import VcsSettingsModel -from rhodecode.apps.upload_store import utils -from rhodecode.apps.upload_store.exceptions import FileNotAllowedException, \ +from rhodecode.apps.file_store import utils +from rhodecode.apps.file_store.exceptions import FileNotAllowedException, \ FileOverSizeException log = logging.getLogger(__name__) @@ -469,7 +469,7 @@ def upload_file(request, apiuser, filena 'user_id': apiuser.user_id, 'ip': apiuser.ip_addr}} try: - store_fid = storage.save_file(file_obj, filename, metadata=metadata) + store_fid, metadata = storage.save_file(file_obj, filename, metadata=metadata) except FileNotAllowedException: raise JSONRPCError('File `{}` is not allowed.'.format(filename)) diff --git a/rhodecode/apps/upload_store/__init__.py b/rhodecode/apps/file_store/__init__.py rename from rhodecode/apps/upload_store/__init__.py rename to rhodecode/apps/file_store/__init__.py --- a/rhodecode/apps/upload_store/__init__.py +++ b/rhodecode/apps/file_store/__init__.py @@ -18,7 +18,7 @@ # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ import os -from rhodecode.apps.upload_store import config_keys +from rhodecode.apps.file_store import config_keys from rhodecode.config.middleware import _bool_setting, _string_setting diff --git a/rhodecode/apps/upload_store/config_keys.py b/rhodecode/apps/file_store/config_keys.py rename from rhodecode/apps/upload_store/config_keys.py rename to rhodecode/apps/file_store/config_keys.py diff --git a/rhodecode/apps/upload_store/exceptions.py b/rhodecode/apps/file_store/exceptions.py rename from rhodecode/apps/upload_store/exceptions.py rename to rhodecode/apps/file_store/exceptions.py diff --git a/rhodecode/apps/upload_store/extensions.py b/rhodecode/apps/file_store/extensions.py rename from rhodecode/apps/upload_store/extensions.py rename to rhodecode/apps/file_store/extensions.py diff --git a/rhodecode/apps/upload_store/local_store.py b/rhodecode/apps/file_store/local_store.py rename from rhodecode/apps/upload_store/local_store.py rename to rhodecode/apps/file_store/local_store.py --- a/rhodecode/apps/upload_store/local_store.py +++ b/rhodecode/apps/file_store/local_store.py @@ -23,9 +23,9 @@ import time import shutil from rhodecode.lib.ext_json import json -from rhodecode.apps.upload_store import utils -from rhodecode.apps.upload_store.extensions import resolve_extensions -from rhodecode.apps.upload_store.exceptions import FileNotAllowedException +from rhodecode.apps.file_store import utils +from rhodecode.apps.file_store.extensions import resolve_extensions +from rhodecode.apps.file_store.exceptions import FileNotAllowedException METADATA_VER = 'v1' @@ -110,7 +110,8 @@ class LocalFileStorage(object): Checks if an extension is permitted. Both e.g. ".jpg" and "jpg" can be passed in. Extension lookup is case-insensitive. - :param extensions: iterable of extensions (or self.extensions) + :param ext: extension to check + :param extensions: iterable of extensions to validate against (or self.extensions) """ extensions = extensions or self.extensions @@ -160,12 +161,15 @@ class LocalFileStorage(object): if metadata: size = os.stat(path).st_size - metadata.update({'size': size, "time": time.time(), - "meta_ver": METADATA_VER}) + metadata.update( + {"size": size, + "time": time.time(), + "meta_ver": METADATA_VER}) + with open(os.path.join(dest_directory, filename_meta), "wb") as dest_meta: dest_meta.write(json.dumps(metadata)) if directory: filename = os.path.join(directory, filename) - return filename + return filename, metadata diff --git a/rhodecode/apps/upload_store/tests/__init__.py b/rhodecode/apps/file_store/tests/__init__.py rename from rhodecode/apps/upload_store/tests/__init__.py rename to rhodecode/apps/file_store/tests/__init__.py diff --git a/rhodecode/apps/upload_store/tests/test_upload_file.py b/rhodecode/apps/file_store/tests/test_upload_file.py rename from rhodecode/apps/upload_store/tests/test_upload_file.py rename to rhodecode/apps/file_store/tests/test_upload_file.py --- a/rhodecode/apps/upload_store/tests/test_upload_file.py +++ b/rhodecode/apps/file_store/tests/test_upload_file.py @@ -22,7 +22,7 @@ import pytest from rhodecode.lib.ext_json import json from rhodecode.tests import TestController -from rhodecode.apps.upload_store import utils, config_keys +from rhodecode.apps.file_store import utils, config_keys def route_path(name, params=None, **kwargs): @@ -58,7 +58,7 @@ class TestFileStoreViews(TestController) f.write(content) with open(filesystem_file, 'rb') as f: - fid = store.save_file(f, fid, metadata={'filename': fid}) + fid, metadata = store.save_file(f, fid, metadata={'filename': fid}) else: status = 404 diff --git a/rhodecode/apps/upload_store/utils.py b/rhodecode/apps/file_store/utils.py rename from rhodecode/apps/upload_store/utils.py rename to rhodecode/apps/file_store/utils.py --- a/rhodecode/apps/upload_store/utils.py +++ b/rhodecode/apps/file_store/utils.py @@ -24,8 +24,8 @@ import uuid def get_file_storage(settings): - from rhodecode.apps.upload_store.local_store import LocalFileStorage - from rhodecode.apps.upload_store import config_keys + from rhodecode.apps.file_store.local_store import LocalFileStorage + from rhodecode.apps.file_store import config_keys store_path = settings.get(config_keys.store_path) return LocalFileStorage(base_path=store_path) diff --git a/rhodecode/apps/upload_store/views.py b/rhodecode/apps/file_store/views.py rename from rhodecode/apps/upload_store/views.py rename to rhodecode/apps/file_store/views.py --- a/rhodecode/apps/upload_store/views.py +++ b/rhodecode/apps/file_store/views.py @@ -24,8 +24,8 @@ from pyramid.response import FileRespons from pyramid.httpexceptions import HTTPFound, HTTPNotFound from rhodecode.apps._base import BaseAppView -from rhodecode.apps.upload_store import utils -from rhodecode.apps.upload_store.exceptions import ( +from rhodecode.apps.file_store import utils +from rhodecode.apps.file_store.exceptions import ( FileNotAllowedException,FileOverSizeException) from rhodecode.lib import helpers as h @@ -69,8 +69,7 @@ class FileStoreView(BaseAppView): 'user_id': self._rhodecode_user.user_id, 'ip': self._rhodecode_user.ip_addr}} try: - store_fid = self.storage.save_file(file_obj.file, filename, - metadata=metadata) + store_fid, metadata = self.storage.save_file(file_obj.file, filename, metadata=metadata) except FileNotAllowedException: return {'store_fid': None, 'access_path': None, diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -281,7 +281,7 @@ def includeme(config): config.include('rhodecode.apps.ops') config.include('rhodecode.apps.admin') config.include('rhodecode.apps.channelstream') - config.include('rhodecode.apps.upload_store') + config.include('rhodecode.apps.file_store') config.include('rhodecode.apps.login') config.include('rhodecode.apps.home') config.include('rhodecode.apps.journal')