pax_global_header00006660000000000000000000000064145424332300014512gustar00rootroot0000000000000052 comment=d55f6f1cfd4bea5092ca844d555a0a739ac7dd75 appdata-2.2.1/000077500000000000000000000000001454243323000131265ustar00rootroot00000000000000appdata-2.2.1/.github/000077500000000000000000000000001454243323000144665ustar00rootroot00000000000000appdata-2.2.1/.github/workflows/000077500000000000000000000000001454243323000165235ustar00rootroot00000000000000appdata-2.2.1/.github/workflows/publish-to-pypi.yml000066400000000000000000000022331454243323000223130ustar00rootroot00000000000000name: Build on: push jobs: build-n-publish: name: Build and publish Python 🐍 distributions 📦 to PyPI runs-on: ubuntu-latest steps: - uses: actions/checkout@master - name: Set up Python 3.9 uses: actions/setup-python@v1 with: python-version: 3.9 - name: Install pypa/build run: >- python -m pip install build --user - name: Install requirements run: >- python -m pip install -r requirements.txt - name: Build a binary wheel and a source tarball run: >- python -m build --sdist --wheel --outdir dist/ - name: Coveralls run: >- export pip install coveralls && coverage run --source=appdata -m pytest tests/ && coveralls env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} - name: Publish distribution 📦 to PyPI if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@master with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} appdata-2.2.1/.gitignore000066400000000000000000000003241454243323000151150ustar00rootroot00000000000000# ====== # IDEs # ====== .vscode/ .idea/ .vs/ # ====== # Python # ====== .pytest_cache/ __pycache__/ *.egg-info/ # ====== # output # ====== bin/ build/ target/ dist/ # ====== # Others # ====== *.log venv/ .envappdata-2.2.1/CONTRIBUTING.md000066400000000000000000000101701454243323000153560ustar00rootroot00000000000000# Contributing When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. Please note we have a code of conduct, please follow it in all your interactions with the project. ## Pull Request Process 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. 2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters. 3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. ## Code of Conduct ### Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ### Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ### Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ### Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ### Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ### Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/appdata-2.2.1/LICENSE.md000066400000000000000000000020511454243323000145300ustar00rootroot00000000000000MIT License Copyright (c) 2020 VoIlAlex Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. appdata-2.2.1/README.md000066400000000000000000000046021454243323000144070ustar00rootroot00000000000000# appdata | Application Data Management [![Coverage Status](https://coveralls.io/repos/github/VoIlAlex/appdata/badge.svg?branch=master&)](https://coveralls.io/github/VoIlAlex/appdata?branch=master) [![PyPI release](https://img.shields.io/pypi/v/appdata)](https://pypi.org/project/appdata/) ![Build status](https://github.com/VoIlAlex/appdata/actions/workflows/publish-to-pypi.yml/badge.svg) [![Documentation](https://img.shields.io/readthedocs/appdata)](https://appdata.readthedocs.io/en/latest/) [![Maintainability](https://api.codeclimate.com/v1/badges/b909411d678ef3500d92/maintainability)](https://codeclimate.com/github/VoIlAlex/appdata/maintainability) [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![License](https://img.shields.io/github/license/VoIlAlex/appdata)](https://github.com/VoIlAlex/appdata/blob/master/LICENSE.md) [![Downloads](https://static.pepy.tech/personalized-badge/appdata?period=total&units=international_system&left_color=grey&right_color=green&left_text=Downloads)](https://pepy.tech/project/appdata) [![Linux](https://svgshare.com/i/Zhy.svg)](https://svgshare.com/i/Zhy.svg) [![Windows](https://svgshare.com/i/ZhY.svg)](https://svgshare.com/i/ZhY.svg) [![macOS](https://svgshare.com/i/ZjP.svg)](https://svgshare.com/i/ZjP.svg) ## Installation ```bash pip install appdata ``` ## Documentation The detailed documentation you can find on [appdata.readthedocs.io](https://appdata.readthedocs.io/en/latest/index.html). ## Usage To manage paths of application data folder there is `AppDataPaths` class: ```python from appdata import AppDataPaths app_paths = AppDataPaths('myapp') # Name is optional. By default CWD folder name is used. ``` To create the application folder tree: ```python app_paths.setup() ``` There are few paths specified to manage your application data folder: ```python print(app_paths.name) # myapp print(app_paths.app_data_path) # (for Linux and MacOS) /home//.myapp print(app_paths.logs_path) # (for Linux and MacOS) /home//.myapp/logs print(app_paths.config_path) # (for Linux and MacOS) /home//.myapp/default.ini print(app_paths.log_file_path) # (for Linux and MacOS) /home//.myapp/logs/myapp.log ``` Every path could be customized. See options [here](https://appdata.readthedocs.io/). ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) ## License [MIT](LICENSE.md) appdata-2.2.1/appdata/000077500000000000000000000000001454243323000145405ustar00rootroot00000000000000appdata-2.2.1/appdata/__init__.py000066400000000000000000000150201454243323000166470ustar00rootroot00000000000000import os import shutil import sys from appdata.lock import FileBasedLock from appdata.utils import get_home_folder, prepare_ext class AppDataPaths: DEFAULT_EXT = '.ini' DEFAULT_LOG_FILE_NAME = 'app' DEFAULT_LOCK_FILE_NAME = 'lock' def __init__( self, name=None, default_config_ext=None, logs_folder_name='logs', locks_folder_name='locks', home_folder_path=None, ): """ :param name: name of the project. Uses cwd name as default. """ self.name = name if name else os.path.split(os.getcwd())[1] self.default_config_ext = default_config_ext self.home_folder_path = home_folder_path or get_home_folder() self.logs_folder_name = logs_folder_name self.locks_folder_name = locks_folder_name assert self.name assert self.home_folder_path def get_config_path(self, name=None, ext=None, create=False): """ Allows to get app config path. :param name: name of the application. Uses app name as default. :return: path to the config. """ ext = ext if ext is not None else self.default_config_ext \ if self.default_config_ext is not None else self.DEFAULT_EXT # Not empty extension should start with . (dot) ext = prepare_ext(ext) name = name if name is not None else 'default' # Full name if len(name) == 0: if len(ext) != 0: full_name = ext else: full_name = 'config' else: full_name = name + ext path = os.path.join(self.app_data_path, full_name) return path def get_log_file_path(self, name=None, create=False): if name: name = name elif self.name: name = self.name else: name = self.DEFAULT_LOG_FILE_NAME path = os.path.join(self.logs_path, name + '.log') return path def get_lock_file_path(self, name=None): if name: name = name elif self.name: name = self.name else: name = self.DEFAULT_LOCK_FILE_NAME path = os.path.join(self.locks_path, name + '.lock') return path def check_for_exceptions(self, raise_exceptions=False): try: if not os.path.exists(self.app_data_path): raise RuntimeError('App data folder should exist. Run setup(...) to initialize the required files.') if not os.path.exists(self.config_path): raise RuntimeError('Config file should exist. Run setup(...) to initialize the required files.') if not os.path.exists(self.logs_path): raise RuntimeError('Logs folder should exist. Run setup(...) to initialize the required files.') if not os.path.exists(self.log_file_path): raise RuntimeError('Default log file should exist. Run setup(...) to initialize the required files.') if not os.path.exists(self.locks_path): raise RuntimeError('Locks folder should exist. Run setup(...) to initialize the required files.') except Exception as e: if raise_exceptions: raise return False return True def setup(self, override=False): if override: self.clear() app_data_path = self.app_data_path if not os.path.exists(app_data_path): os.makedirs(app_data_path) config_path = self.config_path if not os.path.exists(config_path): with open(config_path, 'w+'): pass logs_path = self.logs_path if not os.path.exists(logs_path): os.makedirs(logs_path) log_file_path = self.log_file_path if not os.path.exists(log_file_path): with open(log_file_path, 'w+'): pass locks_path = self.locks_path if not os.path.exists(locks_path): os.makedirs(locks_path) def clear(self, everything=False): if everything: app_data_path = self.app_data_path if os.path.exists(app_data_path): shutil.rmtree(app_data_path) else: # Here all the config files should # be deleted by one config_path = self.config_path if os.path.exists(config_path): os.remove(self.config_path) logs_path = self.logs_path if os.path.exists(logs_path): shutil.rmtree(logs_path) locks_path = self.locks_path if os.path.exists(locks_path): if not os.path.isdir(locks_path): os.remove(locks_path) else: for file in os.listdir(locks_path): os.remove( os.path.join(locks_path, file) ) @property def require_setup(self) -> bool: return not os.path.exists(self.app_data_path) \ or not os.path.exists(self.config_path) \ or not os.path.exists(self.logs_path) \ or not os.path.exists(self.log_file_path) \ or not os.path.exists(self.locks_path) @property def app_data_path(self): if self.name is None or self.name == '': name = self.default_name else: name = self.name if sys.platform == 'linux' or sys.platform == 'darwin': app_data_folder_name = f'.{name}' else: app_data_folder_name = name return os.path.join(self.home_folder_path, app_data_folder_name) @property def logs_path(self): if self.logs_folder_name: return os.path.join(self.app_data_path, self.logs_folder_name) else: return self.app_data_path @property def locks_path(self): if self.locks_folder_name: return os.path.join(self.app_data_path, self.locks_folder_name) else: return self.app_data_path @property def lock_file_path(self): return self.get_lock_file_path() @property def config_path(self): """ Allows to get default app config path. :return: path to the default config. """ return self.get_config_path() @property def log_file_path(self): return self.get_log_file_path() @property def default_name(self): return os.path.split(os.getcwd())[1] def lock(self): return FileBasedLock(self) appdata-2.2.1/appdata/lock.py000066400000000000000000000014201454243323000160370ustar00rootroot00000000000000import os import time from contextlib import contextmanager @contextmanager def _file_based_lock_context(lock): try: lock.acquire() yield lock finally: lock.release() class FileBasedLock: def __init__(self, app_paths, name=None): self.app_paths = app_paths self.name = name def acquire(self): lock_path = self.app_paths.get_lock_file_path(name=self.name) while os.path.exists(lock_path): time.sleep(1) with open(lock_path, 'w+') as f: pass def release(self): lock_path = self.app_paths.get_lock_file_path(name=self.name) if os.path.exists(lock_path): os.remove(lock_path) def context(self): return _file_based_lock_context(self) appdata-2.2.1/appdata/utils.py000066400000000000000000000007341454243323000162560ustar00rootroot00000000000000from functools import lru_cache from pathlib import Path from typing import Optional @lru_cache() def get_home_folder(): return Path.home().absolute() @lru_cache() def prepare_ext(ext: Optional[str]): if ext and len(ext) != 0: while ext.startswith('..'): ext = ext[1:] if len(ext) == 1 and ext[0] == '.': ext = '' if len(ext) != 0: if ext[0] != '.': ext = '.' + ext return ext or '' appdata-2.2.1/docs/000077500000000000000000000000001454243323000140565ustar00rootroot00000000000000appdata-2.2.1/docs/getting_started.rst000066400000000000000000000036751454243323000200120ustar00rootroot00000000000000Getting started =================================== **AppData** is a Python library to access app data paths based on the operating system the app is running on. =============== Install AppData =============== To install AppData package from PyPI run the following command in your terminal (Python and Pip should be installed) .. code-block:: none pip install appdata After that you could use the functionality of this library. ============= Using AppData ============= The main class that is used by the package is ``AppDataPaths``: .. code-block:: python3 from appdata import AppDataPaths The default initialization: .. code-block:: python3 app_paths = AppDataPaths() app_paths.setup() By default the current working directory name is used as name for app data folder. The folder destination depends on the operating system your app is ranning on. ``setup()`` function allows to create folders that are not created. To delete all the files generated by the library use: .. code-block:: python3 app_paths.clear(everything=True) To check if ``setup()`` is required use: .. code-block:: python3 app_paths.require_setup The ``AppDataPaths`` class allows to access different paths for the application. Application data path --------------------- To access application data root path: .. code-block:: python3 app_paths.app_data_path Config path ----------- To access application config file path use: .. code-block:: python3 app_paths.config_path Or if you would like to get specific config file path: .. code-block:: python3 app_paths.get_config_path( name='some_name', ext='.conf' ) Logs path --------- To access logs folder path use: .. code-block:: python3 app_paths.logs_path To access default log file use: .. code-block:: python3 app_paths.log_file_path Or if you would like to get specific log file: .. code-block:: python3 app_paths.get_log_file_path(name='some_log') appdata-2.2.1/docs/index.rst000066400000000000000000000003511454243323000157160ustar00rootroot00000000000000Welcome to AppData documentation! =================================== **AppData** is a Python library to access app data paths based on the operating system the app is running on. Contents -------- .. toctree:: getting_startedappdata-2.2.1/pytest.ini000066400000000000000000000000301454243323000151500ustar00rootroot00000000000000[pytest] addopts = -s -vappdata-2.2.1/requirements.txt000066400000000000000000000000761454243323000164150ustar00rootroot00000000000000loguru==0.4.1 pytest==6.2.5 coveralls==3.3.1 pytest-cov==3.0.0appdata-2.2.1/setup.py000066400000000000000000000034401454243323000146410ustar00rootroot00000000000000from setuptools import find_packages from distutils.core import setup import os # User-friendly description from README.md current_directory = os.path.dirname(os.path.abspath(__file__)) try: with open(os.path.join(current_directory, 'README.md'), encoding='utf-8') as f: long_description = f.read() except Exception: long_description = '' setup( # Name of the package name='appdata', # Packages to include into the distribution packages=find_packages('.'), # Start with a small number and increase it with # every change you make https://semver.org version='2.2.1', # Chose a license from here: https: // # help.github.com / articles / licensing - a - # repository. For example: MIT license='MIT', # Short description of your library description='Utils to manage application data folder.', # Long description of your library long_description=long_description, long_description_content_type='text/markdown', # Your name author='voilalex', # Your email author_email='ilya.vouk@gmail.com', # Either the link to your github or to your website url='https://github.com/VoIlAlex/appdata', # Link from which the project can be downloaded download_url='https://github.com/VoIlAlex/appdata/archive/v1.2.0.tar.gz', # List of keywords keywords=[ 'utils', 'filesystem', 'paths', 'resources' ], # List of packages to install with this one install_requires=[ ], # https://pypi.org/classifiers/ classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Console :: Curses', 'Topic :: Utilities', 'Topic :: System :: Filesystems', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8' ], ) appdata-2.2.1/tests/000077500000000000000000000000001454243323000142705ustar00rootroot00000000000000appdata-2.2.1/tests/__init__.py000066400000000000000000000000001454243323000163670ustar00rootroot00000000000000appdata-2.2.1/tests/test_lock.py000066400000000000000000000011331454243323000166270ustar00rootroot00000000000000import os from appdata import AppDataPaths class TestLock: def test_lock_1(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.setup(override=True) lock = app_paths.lock() with lock.context(): pass app_paths.clear(everything=True) def test_lock_2(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.setup(override=True) lock = app_paths.lock() lock.acquire() lock.release() app_paths.clear(everything=True) appdata-2.2.1/tests/test_paths.py000066400000000000000000000220331454243323000170200ustar00rootroot00000000000000import os import shutil from appdata import AppDataPaths from pathlib import Path class TestPaths: def test_paths_initialization_1(self): app = AppDataPaths() assert app.name == 'appdata' def test_paths_initialization_2(self): app = AppDataPaths( name='some_app' ) assert app.name == 'some_app' def test_require_setup_1(self): app_paths = AppDataPaths( name='some_app', default_config_ext='.conf', home_folder_path=os.getcwd() ) require_setup = not os.path.exists(app_paths.home_folder_path) \ or not os.path.exists(app_paths.config_path) return app_paths.require_setup == require_setup class TestConfigPaths: def test_config_path_1(self): app_paths = AppDataPaths() assert app_paths.config_path == os.path.join( Path.home(), '.appdata', 'default' + AppDataPaths.DEFAULT_EXT ) def test_config_path_2(self): app_paths = AppDataPaths(default_config_ext='.conf') assert app_paths.config_path == os.path.join( Path.home(), '.appdata', 'default.conf' ) def test_config_path_3(self): app_paths = AppDataPaths( name='some_app', default_config_ext='.conf' ) assert app_paths.config_path == os.path.join( Path.home(), '.some_app', 'default.conf' ) def test_config_path_4(self): home_folder_path = os.getcwd() app_paths = AppDataPaths( name='some_app', default_config_ext='.conf', home_folder_path=home_folder_path ) assert app_paths.config_path == os.path.join( home_folder_path, '.some_app', 'default.conf' ) def test_config_path_5(self): app_paths = AppDataPaths( name='some_app', default_config_ext='.conf' ) config_path = app_paths.get_config_path( name='some_config', ext='.some_ext' ) assert config_path == os.path.join( Path.home(), '.some_app', 'some_config.some_ext' ) def test_config_path_6(self): app_paths = AppDataPaths( name='some_app', default_config_ext='.conf' ) config_path = app_paths.get_config_path( name='some_config', ext='some_ext' ) assert config_path == os.path.join( Path.home(), '.some_app', 'some_config.some_ext' ) def test_config_path_7(self): app_paths = AppDataPaths( name='some_app', default_config_ext=None ) config_path = app_paths.get_config_path( name='', ext='' ) assert config_path == os.path.join( Path.home(), '.some_app', 'config' ) def test_config_path_8(self): app_paths = AppDataPaths( name='some_app', default_config_ext=None ) config_path = app_paths.get_config_path( name='', ext='.conf' ) assert config_path == os.path.join( Path.home(), '.some_app', '.conf' ) class TestLogPaths: def test_logs_path_1(self): app_paths = AppDataPaths() assert app_paths.logs_path == os.path.join( Path.home(), '.appdata', 'logs', ) def test_logs_path_2(self): app_paths = AppDataPaths(logs_folder_name='some_logs') assert app_paths.logs_path == os.path.join( Path.home(), '.appdata', 'some_logs', ) def test_logs_path_3(self): app_paths = AppDataPaths(logs_folder_name=None) assert app_paths.logs_path == os.path.join( Path.home(), '.appdata', ) def test_log_file_path_4(self): app_paths = AppDataPaths() assert app_paths.log_file_path == os.path.join( Path.home(), '.appdata', 'logs', 'appdata.log' ) def test_log_file_path_5(self): app_paths = AppDataPaths() assert app_paths.get_log_file_path(name='something') == os.path.join( Path.home(), '.appdata', 'logs', 'something.log' ) def test_log_file_path_6(self): app_paths = AppDataPaths() app_paths.name = '' assert app_paths.get_log_file_path() == os.path.join( Path.home(), '.appdata', 'logs', 'app.log' ) class TestPathsUtils: def test_check_for_exceptions_1(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.clear(everything=True) assert app_paths.check_for_exceptions() is False def test_check_for_exceptions_2(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.clear(everything=True) assert app_paths.check_for_exceptions(raise_exceptions=False) is False def test_check_for_exceptions_3(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.clear(everything=True) try: app_paths.check_for_exceptions(raise_exceptions=True) except Exception: return assert False def test_check_for_exceptions_4(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.setup() assert app_paths.check_for_exceptions(raise_exceptions=False) app_paths.clear(everything=True) def test_check_for_exceptions_5(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.setup() os.remove(app_paths.config_path) assert not app_paths.check_for_exceptions(raise_exceptions=False) app_paths.clear(everything=True) def test_check_for_exceptions_6(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.setup() os.remove(app_paths.log_file_path) assert not app_paths.check_for_exceptions(raise_exceptions=False) app_paths.clear(everything=True) def test_check_for_exceptions_7(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.setup() shutil.rmtree(app_paths.logs_path) assert not app_paths.check_for_exceptions(raise_exceptions=False) app_paths.clear(everything=True) def test_check_for_exceptions_8(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.setup() shutil.rmtree(app_paths.locks_path) assert not app_paths.check_for_exceptions(raise_exceptions=False) app_paths.clear(everything=True) def test_setup_1(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.clear(everything=True) assert app_paths.require_setup is True app_paths.setup() assert app_paths.require_setup is False app_paths.clear(everything=True) def test_setup_2(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.setup(override=True) assert os.path.exists(app_paths.locks_path) lock_path = app_paths.get_lock_file_path('some_lock') with open(lock_path, 'w+') as f: pass assert os.path.exists(lock_path) app_paths.setup(override=True) assert not os.path.exists(lock_path) def test_clear_1(self): """ Simple clear clears only default generated files. But app data folder and other content stays in place. """ app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.clear(everything=True) assert not os.path.exists(app_paths.app_data_path) app_paths.setup() assert os.path.exists(app_paths.app_data_path) assert os.path.exists(app_paths.logs_path) assert os.path.exists(app_paths.config_path) assert os.path.exists(app_paths.log_file_path) app_paths.clear() assert os.path.exists(app_paths.app_data_path) assert not os.path.exists(app_paths.logs_path) assert not os.path.exists(app_paths.config_path) assert not os.path.exists(app_paths.log_file_path) app_paths.clear(everything=True) def test_clear_2(self): app_paths = AppDataPaths( home_folder_path=os.getcwd() ) app_paths.clear(everything=True) assert not os.path.exists(app_paths.app_data_path) app_paths.setup() assert os.path.exists(app_paths.app_data_path) app_paths.clear(everything=True) assert not os.path.exists(app_paths.app_data_path) appdata-2.2.1/tests/test_utils.py000066400000000000000000000013271454243323000170440ustar00rootroot00000000000000from pathlib import Path from appdata import get_home_folder, prepare_ext class TestUtils: def test_home_path(self): assert get_home_folder() == Path.home() def test_ext_preparation_1(self): assert prepare_ext('.ext') == '.ext' def test_ext_preparation_2(self): assert prepare_ext('ext') == '.ext' def test_ext_preparation_3(self): assert prepare_ext('') == '' def test_ext_preparation_4(self): assert prepare_ext('.') == '' def test_ext_preparation_5(self): assert prepare_ext('..') == '' def test_ext_preparation_6(self): assert prepare_ext('...') == '' def test_ext_preparation_7(self): assert prepare_ext(None) == ''