pkgstruct
Utility module for formalising the directory structure of software package. The top directory path can be infered from the script path.
pkgstruct supports having a directory structure under the top directory, such as var, share,etc,… under the top directory, and supports the creation of directory structures according to the GNU Coding Standard and the Filesystem Hierarchy Standard.
Requirement
pkgstruct uses only standard modules.
Usage
install
% pip install pkgstruct
Example
Example usage of pkgstruct.py
First, import the module and define an entity of class PkgStruct that uses it. The top directory name is inferred from the script name given in the constructor argument.
import pkgstruct
...
Pkg_info = pkgstruct.PkgStruct(script_path=sys.argv[0])
# pkg_info.dump(relpath=False, with_separator=True)
...
pkg_info.make_subdirs(‘pkg_sysconfdir’, 0o755, True, ‘kivy’)
os.environ[‘KIVY_HOME’] = pkg_info.concat_path(‘pkg_sysconfdir’, ‘kivy’)
....
What subdirectories are defined by it can be displayed with the member function dump().
If the script path (base_script) given as argument is ~/tmp/py_working_tool/lib/python/show_status3.py, Further parent directories of the upper than lib/python/, which is its directory name py_working_tool, is interpreted as the package name:pkg_name, and the location of that directory ~/tmp/py_working_tool is recognized as the top of the directory structure (prefix). Then the following directory structure is deteremied according the rules similar to the GNU Coding Standard or FHS.
bindir: ~/tmp/py_working_tool/bin
datadir: ~/tmp/py_working_tool/share
sysconfdir: ~/tmp/py_working_tool/etc
localstatedir: ~/tmp/py_working_tool/var
runstatedir: ~/tmp/py_working_tool/var/run
tmpdir: ~/tmp/py_working_tool/tmp
and other subdirectories of the package name (pkg_name) directly under these directory names
pkg_datadir: ~/tmp/py_working_tool/share/py_working_tool
pkg_sysconfdir: ~/tmp/py_working_tool/etc/py_working_tool
pkg_cachedir: ~/tmp/py_working_tool/var/cache/py_working_tool
pkg_statedatadir: ~/tmp/py_working_tool/var/lib/py_working_tool
pkg_logdir: ~/tmp/py_working_tool/var/log/py_working_tool
pkg_spooldir: ~/tmp/py_working_tool/var/spool/py_working_tool
The equivalent string is defined and can be accessed as a property of the PkgStruct class. What properties (subdirectory names) are defined can also be checked by directly executing pkgstruct.py on its own. (******** will be the name of the executing user).
Then following is the Example of running pkgstruct.py
‘pkg_name': py_working_tool
‘pkg_path': ~/tmp/py_working_tool
----------------------------------------------------------------------
‘base_script': ~/tmp/py_working_tool/lib/python/pkgstruct.py
----------------------------------------------------------------------
‘script_mnemonic': pkgstruct
‘script_path': ~/tmp/py_working_tool/lib/python/pkgstruct.py
‘script_location': ~/tmp/py_working_tool/lib/python
‘script_basename': pkgstruct.py
----------------------------------------------------------------------
‘prefix': ~/tmp/py_working_tool
----------------------------------------------------------------------
‘exec_user’: ********
----------------------------------------------------------------------
'exec_prefix': '${prefix}'
'bindir': '${prefix}'/bin
'datarootdir': '${prefix}'/share
'datadir': '${prefix}'/share
'sysconfdir': '${prefix}'/etc
'sharedstatedir': '${prefix}'/com
'localstatedir': '${prefix}'/var
'include': '${prefix}'/include
'libdir': '${prefix}'/lib
'srcdir': '${prefix}'/src
'infodir': '${prefix}'/share/info
'runstatedir': '${prefix}'/var/run
'localedir': '${prefix}'/share/locale
'lispdir': '${prefix}'/emacs/lisp
'docdir': '${prefix}'/doc/py_working_tool
'htmldir': '${prefix}'/doc/py_working_tool
'dvidir': '${prefix}'/doc/py_working_tool
'pdfdir': '${prefix}'/doc/py_working_tool
'psdir': '${prefix}'/doc/py_working_tool
'mandir': '${prefix}'/share/man
'man0dir': '${prefix}'/share/man/man0
'man1dir': '${prefix}'/share/man/man1
'man2dir': '${prefix}'/share/man/man2
'man3dir': '${prefix}'/share/man/man3
'man4dir': '${prefix}'/share/man/man4
'man5dir': '${prefix}'/share/man/man5
'man6dir': '${prefix}'/share/man/man6
'man7dir': '${prefix}'/share/man/man7
'man8dir': '${prefix}'/share/man/man8
'man9dir': '${prefix}'/share/man/man9
'manndir': '${prefix}'/share/man/mann
'sbindir': '${prefix}'/sbin
'bootdir': '${prefix}'/boot
'devdir': '${prefix}'/dev
'mediadir': '${prefix}'/media
'mntdir': '${prefix}'/mnt
'optdir': '${prefix}'/opt
'tmpdir': '${prefix}'/tmp
'xmldir': '${prefix}'/etc/xml
'etcoptdir': '${prefix}'/etc/opt
'cachedir': '${prefix}'/var/cache
'statedatadir': '${prefix}'/var/lib
'lockdir': '${prefix}'/var/lock
'logdir': '${prefix}'/var/log
'spooldir': '${prefix}'/var/spool
'statetmpdir': '${prefix}'/var/tmp
'user_home': '${prefix}'/Users/********
'home': '${prefix}'/Users/********
'homedir': '${prefix}'/Users
----------------------------------------------------------------------
'pkg_datadir': '${prefix}'/share/py_working_tool
'pkg_sysconfdir': '${prefix}'/etc/py_working_tool
'pkg_runstatedir': '${prefix}'/var/run/py_working_tool
'pkg_include': '${prefix}'/include/py_working_tool
'pkg_libdir': '${prefix}'/lib/py_working_tool
'pkg_srcdir': '${prefix}'/src/py_working_tool
'pkg_tmpdir': '${prefix}'/tmp/py_working_tool
'pkg_xmldir': '${prefix}'/etc/xml/py_working_tool
'pkg_cachedir': '${prefix}'/var/cache/py_working_tool
'pkg_statedatadir': '${prefix}'/var/lib/py_working_tool
'pkg_lockdir': '${prefix}'/var/lock/py_working_tool
'pkg_logdir': '${prefix}'/var/log/py_working_tool
'pkg_spooldir': '${prefix}'/var/spool/py_working_tool
'pkg_statetmpdir': '${prefix}'/var/tmp/py_working_tool
----------------------------------------------------------------------
In addition, the member function concat_path() was implemented to create another directory/file name string under these. The member function make_subdirs() was also implemented to actually create the directory. Example:
pkg_info.make_subdirs(‘pkg_sysconfdir’, 0o755, True, ‘kivy’) os.environ[‘KIVY_HOME’] = pkg_info.concat_path(‘pkg_sysconfdir’, ‘kivy’)
The above is the code that creates the directory ~/tmp/py_working_tool/etc/py_working_tool/kivy and sets this directory in the environment variable 'KIVY_HOME'.
Another member function complement(..., filename=, ...) was implemented to complement the path name only for the given file name is not absolute path. ( i.e. if given starts from ‘/’ or ‘./’ or ‘../’, the return value is the given filename. Otherwise the return value is the output of concat_path(...))
Metadata
Release files for pkgstruct 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pkgstruct-0.0.4.tar.gz | 14.7 kB | Without provenance | Details for pkgstruct-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pkgstruct-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for pkgstruct-0.0.4-py3-none-any.whl |
Total release size: 24.7 kB
Release files / pkgstruct-0.0.4.tar.gz
| Download URL | pkgstruct-0.0.4.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cbc5415e704a02efc2e1971f70dc189801c6de8c8175921c5a05df06a638eb7
|
|
BLAKE2b-256 checksum How to use checksums |
503c17b04f5e523410397024cfef279d66a059db5c25c407397d9c0c8a1082fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / pkgstruct-0.0.4-py3-none-any.whl
| Download URL | pkgstruct-0.0.4-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
554b8a17f1bfb39386d29b2e6e5c5e1d3a1e2a4f53d6f559eb149ced1385ce10
|
|
BLAKE2b-256 checksum How to use checksums |
2522900f9de9066435871a6466eac24f6a3c39826c0e96d9d70559ca1280be43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for pkgstruct 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.