Skip to main content
  • 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(...))

Author

Nanigashi Uji (53845049+nanigashi-uji@users.noreply.github.com)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pkgstruct-0.0.4.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pkgstruct-0.0.4-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file pkgstruct-0.0.4.tar.gz.

File metadata

  • Download URL: pkgstruct-0.0.4.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pkgstruct-0.0.4.tar.gz
Algorithm Hash digest
SHA256 6cbc5415e704a02efc2e1971f70dc189801c6de8c8175921c5a05df06a638eb7
MD5 e0f5889eac3cce1c569a167b0e2d992c
BLAKE2b-256 503c17b04f5e523410397024cfef279d66a059db5c25c407397d9c0c8a1082fa

See more details on using hashes here.

File details

Details for the file pkgstruct-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pkgstruct-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pkgstruct-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 554b8a17f1bfb39386d29b2e6e5c5e1d3a1e2a4f53d6f559eb149ced1385ce10
MD5 f8b8cf6df117e86d50f3541873acf789
BLAKE2b-256 2522900f9de9066435871a6466eac24f6a3c39826c0e96d9d70559ca1280be43

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page