Skip to content

Commit

Permalink
Initial release (0.1, alpha)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jun 21, 2017
0 parents commit 9558a4d
Show file tree
Hide file tree
Showing 21 changed files with 1,084 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
source = linux_utils
omit = linux_utils/tests.py
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: python
python:
- "2.6"
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "pypy"
install:
- scripts/install-on-travis.sh
script:
- make check
- make test
after_success:
- coveralls
branches:
except:
- /^[0-9]/
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2017 Peter Odding

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.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.rst
include *.txt
72 changes: 72 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Makefile for the `linux-utils' package.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 21, 2017
# URL: https://linux-utils.readthedocs.io

PACKAGE_NAME = linux-utils
WORKON_HOME ?= $(HOME)/.virtualenvs
VIRTUAL_ENV ?= $(WORKON_HOME)/$(PACKAGE_NAME)
PATH := $(VIRTUAL_ENV)/bin:$(PATH)
MAKE := $(MAKE) --no-print-directory
SHELL = bash

default:
@echo "Makefile for $(PACKAGE_NAME)"
@echo
@echo 'Usage:'
@echo
@echo ' make install install the package in a virtual environment'
@echo ' make reset recreate the virtual environment'
@echo ' make check check coding style (PEP-8, PEP-257)'
@echo ' make test run the test suite, report coverage'
@echo ' make tox run the tests on all Python versions'
@echo ' make docs update documentation using Sphinx'
@echo ' make publish publish changes to GitHub/PyPI'
@echo ' make clean cleanup all temporary files'
@echo

install:
@test -d "$(VIRTUAL_ENV)" || mkdir -p "$(VIRTUAL_ENV)"
@test -x "$(VIRTUAL_ENV)/bin/python" || virtualenv --quiet "$(VIRTUAL_ENV)"
@test -x "$(VIRTUAL_ENV)/bin/pip" || easy_install pip
@test -x "$(VIRTUAL_ENV)/bin/pip-accel" || pip install --quiet pip-accel
@pip-accel install --quiet --requirement=requirements.txt
@pip uninstall --yes $(PACKAGE_NAME) &>/dev/null || true
@pip install --quiet --no-deps --ignore-installed .

reset:
$(MAKE) clean
rm -Rf "$(VIRTUAL_ENV)"
$(MAKE) install

check: install
@scripts/check-code-style.sh

test: install
@pip-accel install --quiet --requirement=requirements-tests.txt
@py.test --cov
@coverage html
@coverage report --fail-under=90 &>/dev/null

tox: install
@pip-accel install --quiet tox && tox

docs:
@pip-accel install --quiet sphinx
@cd docs && sphinx-build -nb html -d build/doctrees . build/html

publish: install
git push origin && git push --tags origin
$(MAKE) clean
pip-accel install --quiet twine wheel
python setup.py sdist bdist_wheel
twine upload dist/*
$(MAKE) clean

clean:
@rm -Rf *.egg .cache .coverage .tox build dist docs/build htmlcov
@find -depth -type d -name __pycache__ -exec rm -Rf {} \;
@find -type f -name '*.pyc' -delete

.PHONY: default install reset check test tox docs publish clean
106 changes: 106 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
linux-utils: Linux system administration tools for Python
=========================================================

.. image:: https://travis-ci.org/xolox/python-linux-utils.svg?branch=master
:target: https://travis-ci.org/xolox/python-linux-utils

.. image:: https://coveralls.io/repos/xolox/python-linux-utils/badge.svg?branch=master
:target: https://coveralls.io/r/xolox/python-linux-utils?branch=master

The Python package `linux-utils` provides utility functions that make it easy
to script system administration tasks on Linux_ systems in Python. At the
moment only parsing of the ``/etc/fstab`` and ``/etc/crypttab`` configuration
files is implemented, but more functionality will soon be released. The package
is currently tested on cPython 2.6, 2.7, 3.4, 3.5, 3.6 and PyPy (2.7).

.. contents::
:local:

Installation
------------

The `linux-utils` package is available on PyPI_ which means installation should
be as simple as:

.. code-block:: sh
$ pip install linux-utils
There's actually a multitude of ways to install Python packages (e.g. the `per
user site-packages directory`_, `virtual environments`_ or just installing
system wide) and I have no intention of getting into that discussion here, so
if this intimidates you then read up on your options before returning to these
instructions ;-).

Usage
-----

Please refer to the API documentation available on `Read the Docs`_.

History
-------

Back in 2015 I wrote some Python code to parse the Linux configuration files
``/etc/fstab`` and ``/etc/crypttab`` for use in crypto-drive-manager_. Fast
forward to 2017 and I found myself wanting to use the same functionality
in rsync-system-backup_. Three options presented themselves to me:

1. **Copy/paste the relevant code.** Having to maintain the same code in
multiple places causes lower quality code because having to duplicate the
effort of writing documentation, developing tests and fixing bugs is a very
demotivating endeavor.

In fact sometime in 2016 I *did* copy/paste parts of this code into a
project at work, because I needed similar functionality there. Of course
since then the two implementations have started diverging :-p.

2. **Make crypto-drive-manager a dependency of rsync-system-backup.** Although
this approach is less ugly than copy/pasting the code, it still isn't
exactly elegant because the two projects have nothing to do with each other
apart from working with LUKS encrypted disks on Linux.

3. **Extract the functionality into a new package.** In my opinion this is
clearly the most elegant approach, unfortunately it also requires the most
work from me :-). On the plus side I'm publishing the new package with a
test suite which means less untested code remains in crypto-drive-manager_
(which doesn't have a test suite at the time of writing).

While extracting the code I shortly considered integrating the functionality
into debuntu-tools_, however the ``/etc/fstab`` and ``/etc/crypttab`` parsing
isn't specific to Debian or Ubuntu at all and debuntu-tools_ has several
dependencies that aren't relevant to Linux configuration file parsing.

Tangentially related: The reason I went with the extremely generic name
`linux-utils` is because I will be adding more *"specific to Linux but not
Debian"* functionality to this package in the very near future :-).

Contact
-------

The latest version of `linux-utils` is available on PyPI_ and GitHub_. The
documentation is hosted on `Read the Docs`_. For bug reports please create an
issue on GitHub_. If you have questions, suggestions, etc. feel free to send me
an e-mail at `peter@peterodding.com`_.

License
-------

This software is licensed under the `MIT license`_.

© 2017 Peter Odding.

.. External references:
.. _crypto-drive-manager: https://pypi.python.org/pypi/crypto-drive-manager
.. _debuntu-tools: https://pypi.python.org/pypi/debuntu-tools
.. _GitHub: https://github.com/xolox/python-linux-utils
.. _Linux: https://en.wikipedia.org/wiki/Linux
.. _MIT license: http://en.wikipedia.org/wiki/MIT_License
.. _per user site-packages directory: https://www.python.org/dev/peps/pep-0370/
.. _peter@peterodding.com: peter@peterodding.com
.. _PyPI: https://pypi.python.org/pypi/linux-utils
.. _Python Package Index: https://pypi.python.org/pypi/linux-utils
.. _Python: https://www.python.org/
.. _Read the Docs: https://linux-utils.readthedocs.org
.. _rsync-system-backup: https://pypi.python.org/pypi/rsync-system-backup
.. _virtual environments: http://docs.python-guide.org/en/latest/dev/virtualenvs/
83 changes: 83 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# linux-utils: Linux system administration tools for Python.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 21, 2017
# URL: https://linux-utils.readthedocs.io

"""Sphinx documentation configuration for the `linux-utils` package."""

import os
import sys

# Add the 'linux-utils' source distribution's root directory to the module path.
sys.path.insert(0, os.path.abspath(os.pardir))

# -- General configuration -----------------------------------------------------

# Sphinx extension module names.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
'humanfriendly.sphinx',
]

# Sort members by the source order instead of alphabetically.
autodoc_member_order = 'bysource'

# Paths that contain templates, relative to this directory.
templates_path = ['templates']

# The suffix of source filenames.
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'linux-utils'
copyright = u'2017, Peter Odding'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.

# Find the package version and make it the release.
from linux_utils import __version__ as linux_utils_version # noqa

# The short X.Y version.
version = '.'.join(linux_utils_version.split('.')[:2])

# The full version, including alpha/beta/rc tags.
release = linux_utils_version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['build']

# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# Refer to the Python standard library.
# From: http://twistedmatrix.com/trac/ticket/4582.
intersphinx_mapping = dict(
python=('https://docs.python.org/2', None),
executor=('https://executor.readthedocs.io/en/latest/', None),
propertymanager=('https://property-manager.readthedocs.io/en/latest/', None),
)

# -- Options for HTML output ---------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'nature'

# Output file base name for HTML help builder.
htmlhelp_basename = 'linuxutilsdoc'
36 changes: 36 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.. include:: ../README.rst

API documentation
=================

The following documentation is based on the source code of version |release| of
the `linux-utils` package.

**Available modules**

.. contents::
:local:

:mod:`linux_utils`
------------------

.. automodule:: linux_utils
:members:

:mod:`linux_utils.crypttab`
---------------------------

.. automodule:: linux_utils.crypttab
:members:

:mod:`linux_utils.fstab`
------------------------

.. automodule:: linux_utils.fstab
:members:

:mod:`linux_utils.tabfile`
--------------------------

.. automodule:: linux_utils.tabfile
:members:

0 comments on commit 9558a4d

Please sign in to comment.