Skip to main content

Utility module for formalising the directory structure of software package

Project description

  • 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_seperator=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)

Project details


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.2.tar.gz (14.0 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.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pkgstruct-0.0.2.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for pkgstruct-0.0.2.tar.gz
Algorithm Hash digest
SHA256 9d15f8fffe73c21a6a9afbb7859dfa55c718dd39585d498b280f66b2d337b821
MD5 a4c1a18047a2dbe4488c2347927489b2
BLAKE2b-256 cc64e621394c645b3420ebfcae1eb6de47470c2071bc3538ded8a1c3de39aeb8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pkgstruct-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for pkgstruct-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 890d977e6c2c2a86358fe207bd93a8c6101f6ec4b72b9a1faf9c0499c1477b55
MD5 cda6d31ad083e2326687bdf2d592d89b
BLAKE2b-256 957f4792ef3dd96c742fb2421f68a08e59da23207fd36b495e7b9a90fd3c1b6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page