diff --git a/config/default.py b/config/default.py index 1903906c1..1a51d24f8 100644 --- a/config/default.py +++ b/config/default.py @@ -31,13 +31,13 @@ # To override them (in instance/production.py) either use them like here # or use absolute paths like e.g. pathlib.Path('/some/location/somewhere') FILES_PATH = Path(__file__).parent.parent / 'files' -EXPORT_DIR = Path(FILES_PATH) / 'export' -UPLOAD_DIR = Path(FILES_PATH) / 'uploads' -TMP_DIR = Path('/tmp') # used e.g. for processing imports and export files +EXPORT_PATH = Path(FILES_PATH) / 'export' +UPLOAD_PATH = Path(FILES_PATH) / 'uploads' +TMP_PATH = Path('/tmp') # used e.g. for processing imports and export files # Image processing -PROCESSED_IMAGE_DIR = Path(FILES_PATH) / 'processed_images' -RESIZED_IMAGES = Path(PROCESSED_IMAGE_DIR) / 'resized' +PROCESSED_IMAGE_PATH = Path(FILES_PATH) / 'processed_images' +RESIZED_IMAGES = Path(PROCESSED_IMAGE_PATH) / 'resized' IMAGE_SIZE = { 'thumbnail': '200', 'table': '100'} @@ -46,9 +46,9 @@ PROCESSED_EXT = '.jpeg' # For system checks -WRITABLE_DIRS = [ - UPLOAD_DIR, - EXPORT_DIR, +WRITABLE_PATHS = [ + UPLOAD_PATH, + EXPORT_PATH, RESIZED_IMAGES] # Security diff --git a/install/upgrade/database_upgrade.py b/install/upgrade/database_upgrade.py index b69968dac..6d6b2c37b 100644 --- a/install/upgrade/database_upgrade.py +++ b/install/upgrade/database_upgrade.py @@ -25,7 +25,7 @@ from config.database_versions import DATABASE_VERSIONS from config.default import ( DATABASE_PASS, VERSION, DATABASE_VERSION, DATABASE_NAME, DATABASE_USER, - DATABASE_HOST, DATABASE_PORT, EXPORT_DIR) + DATABASE_HOST, DATABASE_PORT, EXPORT_PATH) from instance import production from openatlas.database.connect import open_connection from openatlas.database.settings import Settings @@ -107,7 +107,7 @@ def check_database_version_supported() -> None: def backup_database() -> None: - path = EXPORT_DIR + path = EXPORT_PATH if not os.access(path, os.W_OK): finish( f'Directory for database backup not writeable ({path}). Aborting!') diff --git a/instance/example_testing.py b/instance/example_testing.py index 532fd063c..06b848fa3 100644 --- a/instance/example_testing.py +++ b/instance/example_testing.py @@ -15,4 +15,4 @@ # For Windows user # from pathlib import Path -# TMP_DIR = Path('C:\\Path\\to\\tmp') +# TMP_PATH = Path('C:\\Path\\to\\tmp') diff --git a/openatlas/__init__.py b/openatlas/__init__.py index b5599c352..7499955aa 100644 --- a/openatlas/__init__.py +++ b/openatlas/__init__.py @@ -65,7 +65,7 @@ def before_request() -> None: g.class_view_mapping = OpenatlasClass.get_class_view_mapping() g.table_headers = OpenatlasClass.get_table_headers() g.files = {} - for file_ in app.config['UPLOAD_DIR'].iterdir(): + for file_ in app.config['UPLOAD_PATH'].iterdir(): if file_.stem.isdigit(): g.files[int(file_.stem)] = file_ # Set max file upload in MB diff --git a/openatlas/api/import_scripts/arche.py b/openatlas/api/import_scripts/arche.py index b57d0febc..3149bb763 100644 --- a/openatlas/api/import_scripts/arche.py +++ b/openatlas/api/import_scripts/arche.py @@ -133,7 +133,7 @@ def import_arche_data() -> int: 'https://arche-thumbnails.acdh.oeaw.ac.at/', params={'id': ortho_photo, 'width': 1200}, # type: ignore timeout=60).content - open(str(app.config['UPLOAD_DIR'] / filename), "wb").write(thumb_req) + open(str(app.config['UPLOAD_PATH'] / filename), "wb").write(thumb_req) file.link('P67', artifact) creator = get_or_create_person( diff --git a/openatlas/display/image_processing.py b/openatlas/display/image_processing.py index 25ee3ab3a..6021960b5 100644 --- a/openatlas/display/image_processing.py +++ b/openatlas/display/image_processing.py @@ -33,7 +33,7 @@ def safe_resize_image(name: str, file_format: str, size: str) -> bool: def image_resizing(name: str, format_: str, size: str) -> bool: conf = app.config - filename = Path(conf['UPLOAD_DIR']) / f"{name}{format_}[0]" + filename = Path(conf['UPLOAD_PATH']) / f"{name}{format_}[0]" with Image(filename=filename) as src: ext = conf['PROCESSED_EXT'] \ if format_ in conf['NONE_DISPLAY_EXT'] else format_ diff --git a/openatlas/display/util.py b/openatlas/display/util.py index 7419897d1..97ce708d7 100644 --- a/openatlas/display/util.py +++ b/openatlas/display/util.py @@ -309,7 +309,7 @@ def format_name_and_aliases(entity: Entity, show_links: bool) -> str: def get_backup_file_data() -> dict[str, Any]: - path = app.config['EXPORT_DIR'] + path = app.config['EXPORT_PATH'] latest_file = None latest_file_date = None for file in [ @@ -426,7 +426,7 @@ def system_warnings(_context: str, _unneeded_string: str) -> str: warnings.append( f"Database version {app.config['DATABASE_VERSION']} is needed but " f"current version is {g.settings['database_version']}") - for path in app.config['WRITABLE_DIRS']: + for path in app.config['WRITABLE_PATHS']: if not os.access(path, os.W_OK): warnings.append( '

' + _('directory not writable') + @@ -470,7 +470,7 @@ def get_file_path( ext = app.config['PROCESSED_EXT'] # pragma: no cover path = app.config['RESIZED_IMAGES'] / size / f"{id_}{ext}" return path if os.path.exists(path) else None - return app.config['UPLOAD_DIR'] / f"{id_}{ext}" + return app.config['UPLOAD_PATH'] / f"{id_}{ext}" def format_date(value: Union[datetime, numpy.datetime64]) -> str: diff --git a/openatlas/models/export.py b/openatlas/models/export.py index 366e52418..e95736733 100644 --- a/openatlas/models/export.py +++ b/openatlas/models/export.py @@ -15,7 +15,7 @@ def current_date_for_filename() -> str: def sql_export(format_: str, postfix: Optional[str] = '') -> bool: - file = app.config['EXPORT_DIR'] \ + file = app.config['EXPORT_PATH'] \ / f'{current_date_for_filename()}_export{postfix}.{format_}' pg_dump = "pg_dump" if os.name == 'posix' \ else f'"{shutil.which("pg_dump.exe")}"' diff --git a/openatlas/views/admin.py b/openatlas/views/admin.py index 15d6b785b..dc6d9ac75 100644 --- a/openatlas/views/admin.py +++ b/openatlas/views/admin.py @@ -516,7 +516,7 @@ def admin_orphans() -> str: entity.description]) # Orphaned files with no corresponding entity - for file in app.config['UPLOAD_DIR'].iterdir(): + for file in app.config['UPLOAD_PATH'].iterdir(): if file.name != '.gitignore' \ and os.path.isfile(file) \ and file.stem.isdigit() \ @@ -573,7 +573,7 @@ def admin_orphans() -> str: def admin_file_delete(filename: str) -> Response: if filename != 'all': # Delete one file try: - (app.config['UPLOAD_DIR'] / filename).unlink() + (app.config['UPLOAD_PATH'] / filename).unlink() flash(f"{filename} {_('was deleted')}", 'info') except Exception as e: g.logger.log('error', 'file', f'deletion of {filename} failed', e) @@ -583,10 +583,10 @@ def admin_file_delete(filename: str) -> Response: # Delete all files with no corresponding entity if is_authorized('admin'): # pragma: no cover - don't test, ever entity_file_ids = [entity.id for entity in Entity.get_by_class('file')] - for f in app.config['UPLOAD_DIR'].iterdir(): + for f in app.config['UPLOAD_PATH'].iterdir(): if f.name != '.gitignore' and int(f.stem) not in entity_file_ids: try: - (app.config['UPLOAD_DIR'] / f.name).unlink() + (app.config['UPLOAD_PATH'] / f.name).unlink() except Exception as e: g.logger.log( 'error', 'file', f'deletion of {f.name} failed', e) @@ -764,7 +764,7 @@ def get_disk_space_info() -> Optional[dict[str, Any]]: files_size = int(process.stdout.split()[0]) else: files_size = 40999999999 # pragma: no cover - stats = shutil.disk_usage(app.config['UPLOAD_DIR']) + stats = shutil.disk_usage(app.config['UPLOAD_PATH']) percent_free = 100 - math.ceil(stats.free / (stats.total / 100)) percent_files = math.ceil(files_size / (stats.total / 100)) other_files = stats.total - stats.free - files_size diff --git a/openatlas/views/entity.py b/openatlas/views/entity.py index 26501f16a..518346168 100644 --- a/openatlas/views/entity.py +++ b/openatlas/views/entity.py @@ -88,7 +88,7 @@ def insert( class_name=class_, view_name=g.classes[class_].view, gis_data=manager.place_info['gis_data'], - writable=os.access(app.config['UPLOAD_DIR'], os.W_OK), + writable=os.access(app.config['UPLOAD_PATH'], os.W_OK), overlays=manager.place_info['overlays'], title=_(g.classes[class_].view), crumbs=manager.get_crumbs()) @@ -209,7 +209,7 @@ def insert_files(manager: BaseManager) -> Union[str, Response]: filename = secure_filename(f'a{file.filename}') name = f"{manager.entity.id}.{filename.rsplit('.', 1)[1].lower()}" ext = secure_filename(file.filename).rsplit('.', 1)[1].lower() - path = app.config['UPLOAD_DIR'] / name + path = app.config['UPLOAD_PATH'] / name file.save(str(path)) if f'.{ext}' in app.config['DISPLAY_FILE_EXTENSIONS']: call(f'exiftran -ai {path}', shell=True) # Fix rotation @@ -228,7 +228,7 @@ def insert_files(manager: BaseManager) -> Union[str, Response]: except Exception as e: # pragma: no cover Transaction.rollback() for filename in filenames: - (app.config['UPLOAD_DIR'] / filename).unlink() + (app.config['UPLOAD_PATH'] / filename).unlink() g.logger.log('error', 'database', 'transaction failed', e) flash(_('error transaction'), 'error') url = url_for('index', view=g.classes['file'].view) diff --git a/openatlas/views/export.py b/openatlas/views/export.py index e0bde2cc4..e51f40216 100644 --- a/openatlas/views/export.py +++ b/openatlas/views/export.py @@ -17,7 +17,7 @@ @required_group('manager') def download_sql(filename: str) -> Response: return send_from_directory( - app.config['EXPORT_DIR'], + app.config['EXPORT_PATH'], filename, as_attachment=True) @@ -25,7 +25,7 @@ def download_sql(filename: str) -> Response: @app.route('/export/execute/') @required_group('manager') def export_execute(format_: str) -> Response: - if os.access(app.config['EXPORT_DIR'], os.W_OK): + if os.access(app.config['EXPORT_PATH'], os.W_OK): if sql_export(format_): g.logger.log('info', 'database', 'SQL export') flash(_('data was exported'), 'info') @@ -38,7 +38,7 @@ def export_execute(format_: str) -> Response: @app.route('/export/sql') @required_group('manager') def export_sql() -> str: - path = app.config['EXPORT_DIR'] + path = app.config['EXPORT_PATH'] table = Table(['name', 'size'], order=[[0, 'desc']]) for file in [f for f in path.iterdir() if (path / f).is_file() and f.name != '.gitignore']: @@ -49,7 +49,7 @@ def export_sql() -> str: _('download'), url_for('download_sql', filename=file.name))] if is_authorized('admin') \ - and os.access(app.config['EXPORT_DIR'], os.W_OK): + and os.access(app.config['EXPORT_PATH'], os.W_OK): confirm = _('Delete %(name)s?', name=file.name.replace("'", '')) data.append( link( @@ -80,7 +80,7 @@ def export_sql() -> str: @required_group('admin') def delete_export(filename: str) -> Response: try: - (app.config['EXPORT_DIR'] / filename).unlink() + (app.config['EXPORT_PATH'] / filename).unlink() g.logger.log('info', 'file', 'SQL file deleted') flash(_('file deleted'), 'info') except Exception as e: diff --git a/openatlas/views/file.py b/openatlas/views/file.py index 268004cf9..eae768718 100644 --- a/openatlas/views/file.py +++ b/openatlas/views/file.py @@ -15,7 +15,7 @@ @required_group('readonly') def download_file(filename: str) -> Any: return send_from_directory( - app.config['UPLOAD_DIR'], + app.config['UPLOAD_PATH'], filename, as_attachment=True) @@ -27,12 +27,12 @@ def display_file(filename: str) -> Any: return send_from_directory( app.config['RESIZED_IMAGES'] / request.args.get('size'), filename) - return send_from_directory(app.config['UPLOAD_DIR'], filename) + return send_from_directory(app.config['UPLOAD_PATH'], filename) @app.route('/display_logo/') def display_logo(filename: str) -> Any: - return send_from_directory(app.config['UPLOAD_DIR'], filename) + return send_from_directory(app.config['UPLOAD_PATH'], filename) @app.route('/file/set_profile_image//') diff --git a/openatlas/views/imports.py b/openatlas/views/imports.py index 76b7afb9d..133edccbc 100644 --- a/openatlas/views/imports.py +++ b/openatlas/views/imports.py @@ -171,7 +171,7 @@ def import_data(project_id: int, class_: str) -> str: class_label = g.classes[class_].label if form.validate_on_submit(): file_ = request.files['file'] - file_path = app.config['TMP_DIR'] / secure_filename(file_.filename) + file_path = app.config['TMP_PATH'] / secure_filename(file_.filename) columns: dict[str, list[str]] = { 'allowed': ['name', 'id', 'description'], 'valid': [], diff --git a/tests/test_admin.py b/tests/test_admin.py index a6b177afa..1594ccd76 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -44,7 +44,7 @@ def test_admin(self) -> None: assert b'Invalid linked entity' in rv.data file_ = 'Test77.txt' - with open(Path(app.config['UPLOAD_DIR'] / file_), 'w') as _file: + with open(Path(app.config['UPLOAD_PATH'] / file_), 'w') as _file: pass rv = self.app.get( diff --git a/tests/test_image.py b/tests/test_image.py index 06e74457c..60f3a72f1 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -52,17 +52,17 @@ def test_image(self) -> None: copyfile( Path(app.root_path) / 'static' / 'images' / 'layout' / 'logo.png', - Path(app.config['UPLOAD_DIR'] / file_name)) + Path(app.config['UPLOAD_PATH'] / file_name)) file2 = insert('file', 'Test_File2') file2.link('P2', g.types[get_hierarchy('License').subs[0]]) copyfile( Path(app.root_path) / 'static' / 'images' / 'layout' / 'logo.png', - Path(app.config['UPLOAD_DIR'] / f'{file2.id}.jpeg')) + Path(app.config['UPLOAD_PATH'] / f'{file2.id}.jpeg')) file_json = insert('file', 'Test') copyfile( Path(app.root_path) / 'static' / 'manifest.json', - Path(app.config['UPLOAD_DIR'] / f'{file_json.id}.json')) + Path(app.config['UPLOAD_PATH'] / f'{file_json.id}.json')) safe_resize_image(file2.id, '.png', size="???") profile_image(file_pathless)