%global _empty_manifest_terminate_build 0 Name: python-disk Version: 2021.6.29 Release: 1 Summary: Python library for interacting with the file system License: MIT URL: https://github.com/idin/disk Source0: https://mirrors.nju.edu.cn/pypi/web/packages/01/2d/c5d406e56bc10643b5963d0cfa9be4da3fd0709f0a241b2931f240668a31/disk-2021.6.29.tar.gz BuildArch: noarch Requires: python3-dill Requires: python3-send2trash Requires: python3-chronometry Requires: python3-slytherin %description # *Disk* Disk is a Python library for interacting with the file system in an object oriented manner. I know you can use os and os.path to do all of these but I find their usage hard to remember and true to object oriented principles. # Installation You can use pip to install Disk: ```bash pip install disk ``` # Usage All files and directories (folders) are considered *Path* objects. Any path except the root, has a parent: the directory it is in. Directories have children, some of them are files and some are subdirectories. ## Path The *Path* object points to an existing or non-existing file or directory. ```python from disk import Path path = Path('C:\\') ``` ### *get_current_directory* Usually we want to start in the current working directory: ```python path = Path.get_current_directory() ``` ### *list*, *dir*, *ls* All of the above methods do the same thing; *ls* is for linux people, *dir* is for windows people, and *list* is for literal people. ```python print(path.list()) ``` ### *directories* To get the sub-directories of a directory use the *directories* attribute which returns a list of *Paths*: ```python subdirectories = path.directories ``` ### *files* To get the files inside a directory use the *files* attribute which returns a list of *Paths*: ```python files = path.files ``` ### *parent_directory* The parent directory is the directory a *Path* (either file or directory) is inside of. ```python parent_directory = path.parent_directory ``` ### *make_directory* To create a new directory **inside** a *Path* that is also a directory, use *make_directory* with the name of the new directory as the *name* argument: ```python path.make_directory(name='new_directory') ``` You can also create a directory at the location of the *Path* object by letting the *name* argument take its default value of *None*: ```python path.make_directory() ``` ### *make_parent_directory* Sometimes you need to create a new file at a *Path* that doesn't already exist, *i.e.* the directory of the file location doesn't exist. This is when *make_parent_directory* becomes handy: ```python path.make_parent_directory(ignore_if_exists=True) ``` The default value of *ignore_if_exists* is *True*. ### *delete* The *delete* function moves a file or directory to the trash. If the *name* argument is provided the file or directory inside the *Path* with that name will be deleted: ```python path.delete(name='new_directory') ``` If the *name* argument is not provided the file or directory the *Path* points to will be deleted: ```python path.delete() ``` ### *save* To save a Python object as a **Pickle** file using the *pickle* or *dill* library you can just use the *save* function of the *Path* which saves the object right at the location of *Path*. ```python my_list = [1, 2, 3] Path('my_list.pickle').save(my_list, method='pickle') Path('my_list.dill').save(my_list, method='dill') ``` ### *load* To load an object from a **Pickle** file located at a *Path* you can run the *load* function of the *Path*. ```python list_from_pickle = Path('my_list.pickle').load(method='pickle') list_from_dill = Path('my_list.dill').load(method='dill') ``` %package -n python3-disk Summary: Python library for interacting with the file system Provides: python-disk BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-disk # *Disk* Disk is a Python library for interacting with the file system in an object oriented manner. I know you can use os and os.path to do all of these but I find their usage hard to remember and true to object oriented principles. # Installation You can use pip to install Disk: ```bash pip install disk ``` # Usage All files and directories (folders) are considered *Path* objects. Any path except the root, has a parent: the directory it is in. Directories have children, some of them are files and some are subdirectories. ## Path The *Path* object points to an existing or non-existing file or directory. ```python from disk import Path path = Path('C:\\') ``` ### *get_current_directory* Usually we want to start in the current working directory: ```python path = Path.get_current_directory() ``` ### *list*, *dir*, *ls* All of the above methods do the same thing; *ls* is for linux people, *dir* is for windows people, and *list* is for literal people. ```python print(path.list()) ``` ### *directories* To get the sub-directories of a directory use the *directories* attribute which returns a list of *Paths*: ```python subdirectories = path.directories ``` ### *files* To get the files inside a directory use the *files* attribute which returns a list of *Paths*: ```python files = path.files ``` ### *parent_directory* The parent directory is the directory a *Path* (either file or directory) is inside of. ```python parent_directory = path.parent_directory ``` ### *make_directory* To create a new directory **inside** a *Path* that is also a directory, use *make_directory* with the name of the new directory as the *name* argument: ```python path.make_directory(name='new_directory') ``` You can also create a directory at the location of the *Path* object by letting the *name* argument take its default value of *None*: ```python path.make_directory() ``` ### *make_parent_directory* Sometimes you need to create a new file at a *Path* that doesn't already exist, *i.e.* the directory of the file location doesn't exist. This is when *make_parent_directory* becomes handy: ```python path.make_parent_directory(ignore_if_exists=True) ``` The default value of *ignore_if_exists* is *True*. ### *delete* The *delete* function moves a file or directory to the trash. If the *name* argument is provided the file or directory inside the *Path* with that name will be deleted: ```python path.delete(name='new_directory') ``` If the *name* argument is not provided the file or directory the *Path* points to will be deleted: ```python path.delete() ``` ### *save* To save a Python object as a **Pickle** file using the *pickle* or *dill* library you can just use the *save* function of the *Path* which saves the object right at the location of *Path*. ```python my_list = [1, 2, 3] Path('my_list.pickle').save(my_list, method='pickle') Path('my_list.dill').save(my_list, method='dill') ``` ### *load* To load an object from a **Pickle** file located at a *Path* you can run the *load* function of the *Path*. ```python list_from_pickle = Path('my_list.pickle').load(method='pickle') list_from_dill = Path('my_list.dill').load(method='dill') ``` %package help Summary: Development documents and examples for disk Provides: python3-disk-doc %description help # *Disk* Disk is a Python library for interacting with the file system in an object oriented manner. I know you can use os and os.path to do all of these but I find their usage hard to remember and true to object oriented principles. # Installation You can use pip to install Disk: ```bash pip install disk ``` # Usage All files and directories (folders) are considered *Path* objects. Any path except the root, has a parent: the directory it is in. Directories have children, some of them are files and some are subdirectories. ## Path The *Path* object points to an existing or non-existing file or directory. ```python from disk import Path path = Path('C:\\') ``` ### *get_current_directory* Usually we want to start in the current working directory: ```python path = Path.get_current_directory() ``` ### *list*, *dir*, *ls* All of the above methods do the same thing; *ls* is for linux people, *dir* is for windows people, and *list* is for literal people. ```python print(path.list()) ``` ### *directories* To get the sub-directories of a directory use the *directories* attribute which returns a list of *Paths*: ```python subdirectories = path.directories ``` ### *files* To get the files inside a directory use the *files* attribute which returns a list of *Paths*: ```python files = path.files ``` ### *parent_directory* The parent directory is the directory a *Path* (either file or directory) is inside of. ```python parent_directory = path.parent_directory ``` ### *make_directory* To create a new directory **inside** a *Path* that is also a directory, use *make_directory* with the name of the new directory as the *name* argument: ```python path.make_directory(name='new_directory') ``` You can also create a directory at the location of the *Path* object by letting the *name* argument take its default value of *None*: ```python path.make_directory() ``` ### *make_parent_directory* Sometimes you need to create a new file at a *Path* that doesn't already exist, *i.e.* the directory of the file location doesn't exist. This is when *make_parent_directory* becomes handy: ```python path.make_parent_directory(ignore_if_exists=True) ``` The default value of *ignore_if_exists* is *True*. ### *delete* The *delete* function moves a file or directory to the trash. If the *name* argument is provided the file or directory inside the *Path* with that name will be deleted: ```python path.delete(name='new_directory') ``` If the *name* argument is not provided the file or directory the *Path* points to will be deleted: ```python path.delete() ``` ### *save* To save a Python object as a **Pickle** file using the *pickle* or *dill* library you can just use the *save* function of the *Path* which saves the object right at the location of *Path*. ```python my_list = [1, 2, 3] Path('my_list.pickle').save(my_list, method='pickle') Path('my_list.dill').save(my_list, method='dill') ``` ### *load* To load an object from a **Pickle** file located at a *Path* you can run the *load* function of the *Path*. ```python list_from_pickle = Path('my_list.pickle').load(method='pickle') list_from_dill = Path('my_list.dill').load(method='dill') ``` %prep %autosetup -n disk-2021.6.29 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-disk -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Fri May 05 2023 Python_Bot - 2021.6.29-1 - Package Spec generated